QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667059 | #9242. An Easy Geometry Problem | yangyl | WA | 33ms | 6268kb | C++20 | 3.2kb | 2024-10-22 20:54:24 | 2024-10-22 20:54:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
constexpr ull P = 1e18 + 9;
constexpr ull B = 29996224275833;
constexpr int N = 2e5 + 5, M = 1e9;
ull base[N];
struct Info {
ull v1, v2;
int len;
}tr[N << 2];
Info merge(Info p, Info q) {
Info res{};
res.v1 = ((i128)p.v1 * base[q.len] % P + q.v1) % P;
res.v2 = ((i128)q.v2 * base[p.len] % P + p.v2) % P;
res.len = p.len + q.len;
return res;
}
void modify(int u, int l, int r, int x, int v) {
if (l == r) {
tr[u].v1 = v;
tr[u].v2 = 2 * M - v;
tr[u].len = 1;
return;
}
int mid = l + r >> 1;
if (mid >= x) {
modify(u << 1, l, mid, x, v);
} else {
modify(u << 1 | 1, mid + 1, r, x, v);
}
tr[u] = merge(tr[u << 1], tr[u << 1 | 1]);
}
Info query(int u, int l, int r, int L, int R) {
if (L <= l && R >= r) {
return tr[u];
}
int mid = l + r >> 1;
Info lf{}, rf{};
if (mid >= L) {
lf = query(u << 1, l, mid, L, R);
}
if (mid < R) {
rf = query(u << 1 | 1, mid + 1, r, L, R);
}
Info res = merge(lf, rf);
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q, k, b;
cin >> n >> q >> k >> b;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
base[0] = 1;
for (int i = 1; i <= n; i++) {
base[i] = (i128) base[i - 1] * B % P;
}
vector<ll> dif(n - 1);
for (int i = 0; i < n - 1; i++) {
dif[i] = a[i + 1] - a[i] + M;
modify(1, 0, n - 1, i, dif[i]);
}
vector<ull> sum(n + 1);
sum[0] = k;
for (int i = 1; i <= n; i++) {
sum[i] = ((i128) sum[i - 1] * B % P + k) % P;
}
while (q--) {
int op;
cin >> op;
if (op == 1) {
int l, r, v;
cin >> l >> r >> v;
l--, r--;
if (l != 0) {
dif[l - 1] += v;
modify(1, 0, n - 1, l - 1, dif[l - 1]);
}
if (r != n - 1) {
dif[r] -= v;
modify(1, 0, n - 1, r, dif[r]);
}
} else {
int x;
cin >> x;
x--;
if (x == 0 || x == n - 1) {
cout << 0 << endl;
} else {
if (dif[x] != 2 * M - dif[x - 1] + k + b) {
cout << 0 << endl;
continue;
}
int l = 1, r = min(x - 1, n - 2 - x);
while (l < r) {
int mid = l + r + 1 >> 1;
if (query(1, 0, n - 1, x - 1 - mid, x - 2).v1 == query(1, 0, n - 1, x + 1, x + 1 + mid).v2 + sum[mid - 1]) l = mid;
else r = mid - 1;
}
if (l != r || (l == 1 && query(1, 0, n - 1, x - 2, x - 2).v1 != query(1, 0, n - 1, x + 1, x + 1).v2 + k)) {
l = 0;
}
cout << l + 1 << endl;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5780kb
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: 33ms
memory: 6268kb
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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 1 2 2 2 2 2 2 2 ...
result:
wrong answer 2nd numbers differ - expected: '304', found: '2'