QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561897 | #9242. An Easy Geometry Problem | Mysterious_Cat | WA | 6ms | 31676kb | C++14 | 2.8kb | 2024-09-13 12:30:53 | 2024-09-13 12:30:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int base = 1e8 + 7;
const int mod[3] = {(int)1e9 + 7, (int)1e9 + 9, (int)1e9 + 23};
int n, q, k, b, pw[N][3], a[N], d[N];
struct V {
int l, v[3];
V (int l_ = 0, int v_ = 0) {
l = l_;
v[0] = (v_ + mod[0]) % mod[0];
v[1] = (v_ + mod[1]) % mod[1];
v[2] = (v_ + mod[2]) % mod[2];
}
V operator + (const V &b) const {
V res;
res.l = l + b.l;
for (int j = 0; j < 3; j++) {
res.v[j] = (1ll * v[j] * pw[b.l][j] + b.v[j]) % mod[j];
}
return res;
}
bool operator == (const V &b) const {
return v[0] == b.v[0] && v[1] == b.v[1] && v[2] == b.v[2];
}
} val[N * 4][2];
void build(int p, int l, int r) {
if (l == r) {
val[p][0] = V(1, d[l]);
val[p][1] = V(1, k - d[l]);
return;
}
int mid = l + r >> 1;
build(p * 2, l, mid);
build(p * 2 + 1, mid + 1, r);
val[p][0] = val[p * 2][0] + val[p * 2 + 1][0];
val[p][1] = val[p * 2][1] + val[p * 2 + 1][1];
}
void modify(int p, int l, int r, int x) {
if (l == r) {
val[p][0] = V(1, d[x]);
val[p][1] = V(1, k - d[x]);
return;
}
int mid = l + r >> 1;
if (x <= mid) {
modify(p * 2, l, mid, x);
} else {
modify(p * 2 + 1, mid + 1, r, x);
}
val[p][0] = val[p * 2][0] + val[p * 2 + 1][0];
val[p][1] = val[p * 2][1] + val[p * 2 + 1][1];
}
V query(int p, int l, int r, int a, int b, int t) {
if (l >= a && r <= b) {
return val[p][t];
}
int mid = l + r >> 1;
if (b <= mid) {
return query(p * 2, l, mid, a, b, t);
} else if (a > mid) {
return query(p * 2 + 1, mid + 1, r, a, b, t);
} else {
return query(p * 2, l, mid, a, b, t) + query(p * 2 + 1, mid + 1, r, a, b, t);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q >> k >> b;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 0; j < 3; j++) {
pw[0][j] = 1;
for (int i = 1; i <= n; i++) {
pw[i][j] = 1ll * pw[i - 1][j] * base % mod[j];
}
}
for (int i = 1; i < n; i++) {
d[i] = a[i + 1] - a[i];
}
build(1, 1, n - 1);
for (int i = 1; i <= q; i++) {
int op;
cin >> op;
if (op == 1) {
int l, r, v;
cin >> l >> r >> v;
if (l - 1 >= 1) {
d[l - 1] += v;
modify(1, 1, n - 1, l - 1);
}
if (r < n) {
d[r] -= v;
modify(1, 1, n - 1, r);
}
} else {
int x;
cin >> x;
if (x == 1 || x == n || d[x - 1] + d[x] != k + b) {
cout << "0\n";
} else if (x == 2 || x == n - 1 || d[x - 2] + d[x + 1] != k) {
cout << "1\n";
} else {
int l = 2, r = min(x - 1, n - x);
while (l < r) {
int mid = l + r + 1 >> 1;
if (query(1, 1, n - 1, x - mid, x - 2, 1) == query(1, 1, n - 1, x + 1, x + mid - 1, 0)) {
l = mid;
} else {
r = mid - 1;
}
}
cout << l << '\n';
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 31216kb
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: 6ms
memory: 31676kb
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:
2 304 73 29 61 292 139 48 17 99 6 5 53 93 3 91 65 29 33 306 21 24 17 21 281 12 16 1 33 7 18 96 7 40 39 13 7 46 43 16 1 72 33 16 22 5 6 189 27 1 35 107 43 34 3 27 20 21 44 56 96 36 2 27 22 30 32 6 5 105 27 37 12 58 2 21 154 17 110 57 3 7 33 15 24 94 68 25 1 14 10 4 10 2 25 39 36 33 164 11 19 181 11 3...
result:
wrong answer 349th numbers differ - expected: '25', found: '2'