QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737600 | #7020. The Kouga Ninja Scrolls | SGColin# | AC ✓ | 642ms | 55812kb | C++17 | 4.3kb | 2024-11-12 16:23:33 | 2024-11-12 16:23:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
constexpr int N = 100007;
constexpr ll inf = 9000000000000000000ll;
int testcase, bel[N];
struct segtree {
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define mid ((l + r) >> 1)
ll pos[N];
struct node {
pair<ll, int> mx, smx, mn, smn;
node() : mx({-inf ,0}), smx({-inf, 0}), mn({inf, 0}), smn({inf, 0}) {}
node operator + (const node &obj) {
node ret;
if (mx > obj.mx) {
ret.mx = mx;
if (smx > obj.mx) ret.smx = smx;
else {
if (obj.mx.second != ret.mx.second) ret.smx = obj.mx;
else ret.smx = (smx > obj.smx ? smx : obj.smx);
}
} else {
ret.mx = obj.mx;
if (obj.smx > mx) ret.smx = obj.smx;
else {
if (mx.second != ret.mx.second) ret.smx = mx;
else ret.smx = (smx > obj.smx ? smx : obj.smx);
}
}
if (mn < obj.mn) {
ret.mn = mn;
if (smn < obj.mn) ret.smn = smn;
else {
if (obj.mn.second != ret.mn.second) ret.smn = obj.mn;
else ret.smn = (smn < obj.smn ? smn : obj.smn);
}
} else {
ret.mn = obj.mn;
if (obj.smn < mn) ret.smn = obj.smn;
else {
if (mn.second != ret.mn.second) ret.smn = mn;
else ret.smn = (smn < obj.smn ? smn : obj.smn);
}
}
return ret;
}
ll calc() {
if (mx.second == 0) return 0;
if (mx.second != mn.second) return mx.first - mn.first;
ll ans = 0;
if (smx.second != 0) ans = max(ans, smx.first - mn.first);
if (smn.second != 0) ans = max(ans, mx.first - smn.first);
return ans;
}
} c[N << 2];
void build(int rt, int l, int r) {
c[rt] = node();
if (l == r) {
c[rt].mx = {pos[l], bel[l]};
c[rt].mn = {pos[l], bel[l]};
return;
}
build(ls, l, mid);
build(rs, mid + 1, r);
c[rt] = c[ls] + c[rs];
}
void upd(int rt, int l, int r, int p) {
if (l == r) {
c[rt] = node();
c[rt].mx = {pos[l], bel[l]};
c[rt].mn = {pos[l], bel[l]};
return;
}
p <= mid ? upd(ls, l, mid, p) : upd(rs, mid + 1, r, p);
c[rt] = c[ls] + c[rs];
}
node query(int rt, int l, int r, int L, int R) {
if (L <= l && r <= R) return c[rt];
if (L > mid) return query(rs, mid + 1, r, L, R);
if (R <= mid) return query(ls, l, mid, L, R);
return query(ls, l, mid, L, R) + query(rs, mid + 1, r, L, R);
}
} X, Y;
inline void work() {
printf("Case #%d:\n", ++testcase);
int n = rd(), m = rd();
rep(i, 1, n) {
ll xx = rd(), yy = rd();
bel[i] = rd();
X.pos[i] = xx + yy;
Y.pos[i] = xx - yy;
}
X.build(1, 1, n);
Y.build(1, 1, n);
rep(i, 1, m) {
int op = rd();
if (op == 1) {
int k = rd();
ll dx = rd(), dy = rd();
X.pos[k] += dx + dy;
Y.pos[k] += dx - dy;
X.upd(1, 1, n, k);
Y.upd(1, 1, n, k);
} else if (op == 2) {
int k = rd();
bel[k] = rd();
X.upd(1, 1, n, k);
Y.upd(1, 1, n, k);
} else {
int l = rd(), r = rd();
printf("%lld\n", max(X.query(1, 1, n, l, r).calc(), Y.query(1, 1, n, l, r).calc()));
}
}
;}
int main() {
per(t, rd(), 1) work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 54580kb
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: 0
Accepted
time: 642ms
memory: 55812kb
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:
ok 216379 lines