QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551453 | #9242. An Easy Geometry Problem | ucup-team3931# | WA | 6ms | 14524kb | C++14 | 3.1kb | 2024-09-07 16:59:55 | 2024-09-07 16:59:55 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 200100;
const ll base = 131, mod1 = 998244853, mod2 = 1004535809;
ll n, m, K, B, a[maxn], b[maxn], c[maxn], pw1[maxn], pw2[maxn];
struct node {
ll h1, h2, len;
};
inline node operator + (const node &a, const node &b) {
node res;
res.h1 = (a.h1 * pw1[b.len] + b.h1) % mod1;
res.h2 = (a.h2 * pw2[b.len] + b.h2) % mod2;
res.len = a.len + b.len;
return res;
}
struct SGT {
node a[maxn << 2];
inline void pushup(int x) {
a[x] = a[x << 1] + a[x << 1 | 1];
}
void build(int rt, int l, int r, ll *c) {
if (l == r) {
a[rt].h1 = a[rt].h2 = c[l];
a[rt].len = 1;
return;
}
int mid = (l + r) >> 1;
build(rt << 1, l, mid, c);
build(rt << 1 | 1, mid + 1, r, c);
pushup(rt);
}
void update(int rt, int l, int r, int x, ll y) {
if (l == r) {
a[rt].h1 = a[rt].h2 = y;
return;
}
int mid = (l + r) >> 1;
(x <= mid) ? update(rt << 1, l, mid, x, y) : update(rt << 1 | 1, mid + 1, r, x, y);
pushup(rt);
}
node query(int rt, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) {
return a[rt];
}
int mid = (l + r) >> 1;
if (qr <= mid) {
return query(rt << 1, l, mid, ql, qr);
} else if (ql > mid) {
return query(rt << 1 | 1, mid + 1, r, ql, qr);
} else {
return query(rt << 1, l, mid, ql, qr) + query(rt << 1 | 1, mid + 1, r, ql, qr);
}
}
} t1, t2;
void solve() {
scanf("%lld%lld%lld%lld", &n, &m, &K, &B);
pw1[0] = pw2[0] = 1;
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
pw1[i] = pw1[i - 1] * base % mod1;
pw2[i] = pw2[i - 1] * base % mod2;
}
for (int i = 1; i < n; ++i) {
b[i] = a[i + 1] - a[i];
c[n - i] = K - b[i];
}
t1.build(1, 1, n, b);
t2.build(1, 1, n, c);
while (m--) {
ll op, x, y, z;
scanf("%lld%lld", &op, &x);
if (op == 1) {
scanf("%lld%lld", &y, &z);
if (x > 1) {
b[x - 1] += z;
t1.update(1, 1, n, x - 1, b[x - 1]);
t2.update(1, 1, n, n - (x - 1), K - b[x - 1]);
}
if (y < n) {
b[y] -= z;
t1.update(1, 1, n, y, b[y]);
t2.update(1, 1, n, n - y, K - b[y]);
}
} else {
if (x == 1 || x == n) {
puts("0");
continue;
}
if (b[x - 1] + b[x] != K + B) {
puts("0");
continue;
}
// for (int i = 1; i < n; ++i) {
// printf("%lld%c", b[i], " \n"[i == n - 1]);
// }
ll l = 1, r = min(x - 2, n - 1 - x), ans = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
node u = t1.query(1, 1, n, x - 1 - mid, x - 2), v = t2.query(1, 1, n, n - (x + mid), n - (x + 1));
if (u.h1 == v.h1 && u.h2 == v.h2) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
printf("%lld\n", ans + 1);
}
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14080kb
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: 14524kb
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 609th numbers differ - expected: '26', found: '25'