QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#772209 | #7020. The Kouga Ninja Scrolls | Alorithm | WA | 3674ms | 86736kb | C++17 | 4.6kb | 2024-11-22 17:30:37 | 2024-11-22 17:30:37 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
const i64 INF = 1ll << 60;
struct ninja {
i64 val, c;
ninja(i64 V = 0, i64 C = 0) : val(V), c(C) { }
bool operator<(const ninja& v) const {
return val < v.val;
}
bool operator>(const ninja& v) const {
return val > v.val;
}
};
struct node {
vector<ninja> nj;
node() {
nj.resize(4);
nj[0] = nj[1] = ninja(-INF);
nj[2] = nj[3] = ninja(INF);
}
};
struct SegTree {
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define mid ((l + r) >> 1)
int n;
vector<node> val;
SegTree(int N = 0) : n(N) {
val.resize(n << 2 | 1);
}
node merge(const node& u, const node& v) {
node ret;
if (u.nj[0] > v.nj[0]) {
ret.nj[0] = u.nj[0];
if (u.nj[1] > v.nj[0]) ret.nj[1] = u.nj[1];
else {
if (v.nj[0].c != ret.nj[0].c) ret.nj[1] = v.nj[0];
else ret.nj[1] = (u.nj[1] > v.nj[1] ? u.nj[1] : v.nj[1]);
}
} else {
ret.nj[0] = v.nj[0];
if (v.nj[1] > u.nj[0]) ret.nj[1] = v.nj[1];
else {
if (u.nj[0].c != ret.nj[0].c) ret.nj[1] = u.nj[0];
else ret.nj[1] = (u.nj[1] > v.nj[1] ? u.nj[1] : v.nj[1]);
}
}
if (u.nj[3] < v.nj[3]) {
ret.nj[3] = u.nj[3];
if (u.nj[3] < v.nj[3]) ret.nj[3] = u.nj[3];
else {
if (v.nj[3].c != ret.nj[3].c) ret.nj[3] = v.nj[3];
else ret.nj[3] = (u.nj[3] < v.nj[3] ? u.nj[3] : v.nj[3]);
}
} else {
ret.nj[3] = v.nj[3];
if (v.nj[3] < u.nj[3]) ret.nj[3] = v.nj[3];
else {
if (u.nj[3].c != ret.nj[3].c) ret.nj[3] = u.nj[3];
else ret.nj[3] = (u.nj[3] < v.nj[3] ? u.nj[3] : v.nj[3]);
}
}
return ret;
}
void modify(int x, i64 v, i64 c, int p, int l, int r) {
if (l == r) {
val[p].nj[0].val = val[p].nj[3].val = v;
val[p].nj[0].c = val[p].nj[3].c = c;
return;
}
if (x <= mid)
modify(x, v, c, ls, l, mid);
else
modify(x, v, c, rs, mid + 1, r);
val[p] = merge(val[ls], val[rs]);
}
node query(int s, int t, int p, int l, int r) {
if (s <= l && r <= t)
return val[p];
node res;
if (s <= mid)
res = merge(res, query(s, t, ls, l, mid));
if (mid + 1 <= t)
res = merge(res, query(s, t, rs, mid + 1, r));
return res;
}
};
i64 get_ans(const node& u) {
if (u.nj[0].c != u.nj[3].c)
return u.nj[0].val - u.nj[3].val;
i64 res = 0;
if (u.nj[1].c)
res = max(res, u.nj[1].val - u.nj[3].val);
if (u.nj[2].c)
res = max(res, u.nj[0].val - u.nj[2].val);
return res;
}
void solve() {
int n, m;
cin >> n >> m;
vector<i64> x(n + 1), y(n + 1), c(n + 1);
SegTree tr_u(n), tr_v(n);
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> c[i];
i64 u = x[i] + y[i], v = x[i] - y[i];
tr_u.modify(i, u, c[i], 1, 1, n);
tr_v.modify(i, v, c[i], 1, 1, n);
}
while (m--) {
int op;
cin >> op;
if (op == 1) {
int i;
i64 dx, dy;
cin >> i >> dx >> dy;
x[i] += dx;
y[i] += dy;
i64 u = x[i] + y[i], v = x[i] - y[i];
tr_u.modify(i, u, c[i], 1, 1, n);
tr_v.modify(i, v, c[i], 1, 1, n);
}
if (op == 2) {
int i;
cin >> i;
cin >> c[i];
i64 u = x[i] + y[i], v = x[i] - y[i];
tr_u.modify(i, u, c[i], 1, 1, n);
tr_v.modify(i, v, c[i], 1, 1, n);
}
if (op == 3) {
// for (int i = 1; i <= n; i++)
// cout << x[i] << ' ' << y[i] << ' ' << c[i] << endl;
int l, r;
cin >> l >> r;
node u = tr_u.query(l, r, 1, 1, n);
node v = tr_v.query(l, r, 1, 1, n);
i64 ans = max(get_ans(u), get_ans(v));
cout << ans << endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Case #" << i << ":\n";
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3872kb
input:
1 2 8 0 0 1 1 1 2 3 1 2 1 1 1 1 3 1 2 1 1 1 1 2 1 2 3 1 2 2 1 1 3 1 2
output:
Case #1: 2 0 0 2
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 3674ms
memory: 86736kb
input:
60 500 500 869676911 -813404481 62 -945322435 46069424 18 -178313683 -431754291 62 365370429 989841420 403 581432447 750507267 482 151389216 29933356 18 -526811063 -170809743 105 862783905 920464530 91 343253321 -871223893 192 403379791 828503986 91 775506325 -370049275 192 533550283 -577541037 482 ...
output:
Case #1: 3685787673 3468859321 3333691523 3468859321 3333691523 3333691523 3961865677 4160346448 3515366597 4160346448 3751993658 4096942446 4554140217 4554140217 2383169926 3685167062 3617781469 4554140217 3173729474 4625859024 3707466685 4554140217 4753589768 3960896897 4554140217 4554140217 45541...
result:
wrong answer 191st lines differ - expected: '2838140813', found: '2691900164'