QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#596595 | #9242. An Easy Geometry Problem | DBsoleil# | WA | 11ms | 11956kb | C++20 | 3.8kb | 2024-09-28 16:05:35 | 2024-09-28 16:05:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
static constexpr int Maxn = 2e5 + 5;
static constexpr uint64_t MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, BA = 4.2e8;
static constexpr uint64_t BASE1 = 100037, BASE2 = 99983;
uint64_t pw1[Maxn], pw2[Maxn];
using hash_t = tuple<int, uint64_t, uint64_t>;
hash_t operator + (const hash_t &lhs, const hash_t &rhs) {
int rl = get<0>(rhs), len = get<0>(lhs) + get<0>(rhs);
uint64_t h1 = (get<1>(lhs) * pw1[rl] + get<1>(rhs)) % MOD1;
uint64_t h2 = (get<2>(lhs) * pw2[rl] + get<2>(rhs)) % MOD2;
return hash_t(len, h1, h2);
} // hash_t operator +
int n, qn, k, B;
int a[Maxn], b[Maxn], d[Maxn], fen[Maxn];
void upd(int x, int v) { for (; x <= n; x += x & -x) fen[x] += v; }
int ask(int x) { int r = 0; for (; x; x -= x & -x) r += fen[x]; return r; }
hash_t hl[Maxn << 2], hr[Maxn << 2];
#define ls (p << 1)
#define rs (p << 1 | 1)
void pushup(int p) {
hl[p] = hl[ls] + hl[rs];
hr[p] = hr[rs] + hr[ls];
} // pushup
pair<hash_t, hash_t> query(int p, int l, int r, int L, int R) {
if (L == l && r == R) return pair(hl[p], hr[p]);
int mid = (l + r) >> 1;
if (R <= mid) return query(ls, l, mid, L, R);
if (L > mid) return query(rs, mid + 1, r, L, R);
auto ll = query(ls, l, mid, L, mid);
auto rr = query(rs, mid + 1, r, mid + 1, R);
return pair(ll.first + rr.first, rr.second + ll.second);
} // query
void update(int p, int l, int r, int x, int v) {
if (l == r) {
hl[p] = hash_t(1, v + BA, v + BA);
hr[p] = hash_t(1, -v + BA, -v + BA);
} else {
int mid = (l + r) >> 1;
if (x <= mid) update(ls, l, mid, x, v);
else update(rs, mid + 1, r, x, v);
pushup(p);
}
} // update
void print(int p, int l, int r) {
if (l == r) {
fprintf(stderr, "%d, ", get<1>(hl[p]) - BA);
} else {
int mid = (l + r) >> 1;
print(ls, l, mid);
print(rs, mid + 1, r);
}
} // print
int main(void) {
ios_base::sync_with_stdio(false);
cin >> n >> qn >> k >> B;
for (int i = 1; i <= n; ++i) cin >> a[i], b[i] = 2 * a[i] - k * i;
for (int i = 1; i <= n; ++i) d[i] = b[i] - b[i - 1];
for (int i = 1; i <= n; ++i) upd(i, a[i] - a[i - 1]);
for (int i = 1; i <= n; ++i) update(1, 1, n, i, d[i]);
// for (int i = 1; i <= n; ++i) fprintf(stderr, "%d, ", b[i]); fprintf(stderr, "\n");
// for (int i = 1; i <= n; ++i) fprintf(stderr, "%d, ", d[i]); fprintf(stderr, "\n");
while (qn--) {
int op, l, r, v;
cin >> op >> l;
// fprintf(stderr, "-------------------------------- (%d, %d\n", op, l);
if (op == 1) {
cin >> r >> v;
upd(l, v), upd(r + 1, -v);
d[l] += 2 * v, d[r + 1] -= 2 * v;
update(1, 1, n, l, d[l]);
if (r + 1 <= n) update(1, 1, n, r + 1, d[r + 1]);
} else {
if (l == 1 || l == n) { cout << "0\n"; continue; }
int al = ask(l - 1), ar = ask(l + 1);
if (ar - al != k + B) { cout << "0\n"; continue; }
int low = 1, high = min(l - 2, n - l - 1), res = 0;
// fprintf(stderr, "(%d, %d)\n", low, high);
auto check = [&](int len)->bool {
int l1 = l - len, r1 = l - 1;
int l2 = l + 2, r2 = l + len + 1;
// fprintf(stderr, "(%d, %d), (%d, %d)\n", l1, r1, l2, r2);
auto a1 = query(1, 1, n, l1, r1);
auto a2 = query(1, 1, n, l2, r2);
// fprintf(stderr, "a1 = (%d, %d, %d)\n", get<0>(a1.first), get<1>(a1.first) - BA, get<2>(a1.first) - BA);
// fprintf(stderr, "a2 = (%d, %d, %d)\n", get<0>(a2.second), get<1>(a2.second) - BA, get<2>(a2.second) - BA);
return a1.first == a2.second;
};
while (low <= high) {
int mid = (low + high) >> 1;
if (check(mid)) low = mid + 1, res = mid;
else high = mid - 1;
}
cout << 1 + res << endl;
}
// print(1, 1, n);
}
return 0;
} // main
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9696kb
input:
6 6 6 2 1 5 9 10 15 18 2 2 1 3 3 -3 2 2 1 3 4 3 2 3 2 4
output:
1 0 2 0
result:
ok 4 number(s): "1 0 2 0"
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 11956kb
input:
5000 5000 2 0 -329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...
output:
1882 2100 796 844 1706 2088 1505 560 173 1979 715 1807 1036 1591 924 814 2240 1825 1044 2102 893 602 1667 587 2077 1472 1779 1 1846 2449 933 1976 699 1736 1605 750 1082 339 1923 369 1 1413 1011 1342 22 408 1783 2267 843 1 2043 1998 1530 1650 918 1564 2154 836 236 1593 466 1648 948 1117 1066 890 32 2...
result:
wrong answer 1st numbers differ - expected: '2', found: '1882'