QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617007 | #9242. An Easy Geometry Problem | ucup-team4153# | WA | 14ms | 39736kb | C++20 | 3.5kb | 2024-10-06 13:27:43 | 2024-10-06 13:27:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int seed = 19260817;
const int seed2 = 233;
typedef long long ll;
const ll mod = (ll) 1e18 + 7;
const ll mod2 = (ll) 1e18 + 9;
int n, q, K, b;
ll seedpow[N], seedpow2[N];
ll a[N];
struct node {
int l, r;
pair<ll, ll> f, g;
} Tree[N << 2];
node operator+(const node &o1, const node &o2) {
node ans;
ans.l = o1.l;
ans.r = o2.r;
int l1 = o1.r - o1.l + 1;
int r1 = o2.r - o2.l + 1;
ans.f = {((__int128_t) o1.f.first * seedpow[r1] + o2.f.first) % mod,
((__int128_t) o1.f.second * seedpow2[r1] + o2.f.second) % mod};
ans.g = {((__int128_t) o2.g.first * seedpow[l1] + o1.g.first) % mod,
((__int128_t) o2.g.second * seedpow2[l1] + o1.g.second) % mod2};
return ans;
}
void build(int k, int l, int r) {
if (l == r) {
Tree[k].l = Tree[k].r = l;
Tree[k].f.first = (a[l] % mod + mod) % mod;
Tree[k].f.second = (a[l] % mod2 + mod2) % mod2;
Tree[k].g.first = (K - Tree[k].f.first + mod) % mod;
Tree[k].g.second = (K - Tree[k].f.second + mod2) % mod2;
return;
}
int mid = (l + r) >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
Tree[k] = Tree[k << 1] + Tree[k << 1 | 1];
}
void update(int k, int pos) {
if (Tree[k].l == Tree[k].r) {
Tree[k].f.first = (a[Tree[k].l] % mod + mod) % mod;
Tree[k].f.second = (a[Tree[k].l] % mod2 + mod2) % mod2;
Tree[k].g.first = (K - Tree[k].f.first + mod) % mod;
Tree[k].g.second = (K - Tree[k].f.second + mod2) % mod2;
return;
}
int mid = (Tree[k].l + Tree[k].r) >> 1;
if (pos <= mid)update(k << 1, pos);
else update(k << 1 | 1, pos);
Tree[k] = Tree[k << 1] + Tree[k << 1 | 1];
}
node query(int k, int l, int r) {
if (Tree[k].l >= l && Tree[k].r <= r) {
return Tree[k];
}
int mid = (Tree[k].l + Tree[k].r) >> 1;
if (r <= mid)return query(k << 1, l, r);
if (l > mid)return query(k << 1 | 1, l, r);
return query(k << 1, l, r) + query(k << 1 | 1, l, r);
}
bool check(int l, int r, int len) {
auto Hash1 = query(1, l - len + 1, l).g;
auto Hash2 = query(1, r, r + len - 1).f;
return Hash1 == Hash2;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
seedpow[0] = 1;
seedpow2[0] = 1;
for (int i = 1; i < N; i++) {
seedpow[i] = (__int128_t) seedpow[i - 1] * seed % mod;
seedpow2[i] = (__int128_t) seedpow2[i - 1] * seed2 % mod2;
}
cin >> n >> q >> K >> b;
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = n; i >= 1; i--)a[i] = a[i] - a[i - 1];
build(1, 1, n);
while (q--) {
int op;
cin >> op;
if (op == 1) {
int l, r, v;
cin >> l >> r >> v;
a[l] += v;
a[r + 1] -= v;
update(1, l);
if (r + 1 <= n)update(1, r + 1);
} else {
int pos;
cin >> pos;
if (pos == 1 || pos == n || a[pos] + a[pos + 1] != K + b) {
cout << "0\n";
continue;
}
int L = 0, R = min(n - pos - 1, pos - 1);
while (L < R) {
int mid = (L + R + 1) >> 1;
if (check(pos - 1, pos + 2, mid))L = mid;
else R = mid - 1;
}
cout << L + 1 << "\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 39488kb
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: 14ms
memory: 39736kb
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 9 9 9 9 9 10 9 9 9 6 5 9 9 3 9 9 9 9 9 9 9 9 10 9 9 9 1 9 7 9 9 7 10 9 9 7 9 9 9 1 9 9 9 9 5 6 10 9 1 9 9 9 9 3 9 9 9 10 9 10 10 2 9 9 10 9 6 5 9 9 9 9 9 2 9 9 9 9 9 3 7 10 9 9 9 9 9 1 9 9 4 9 2 9 9 9 9 9 9 9 9 10 9 9 9 9 10 10 4 9 9 9 9 9 9 9 3 7 2 3 9 9 9 9 9 8 9 9 3 9 9 10 9 5 0 3 9 9 9 9 9 1 9...
result:
wrong answer 2nd numbers differ - expected: '304', found: '9'