QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#825724 | #9774. Same Sum | ucup-team191# | WA | 492ms | 21100kb | C++23 | 3.9kb | 2024-12-21 21:54:24 | 2024-12-21 21:54:26 |
Judging History
你现在查看的是最新测评结果
- [2025-01-11 11:59:18]
- hack成功,自动添加数据
- (/hack/1443)
- [2024-12-23 17:02:06]
- hack成功,自动添加数据
- (/hack/1310)
- [2024-12-23 16:48:26]
- hack成功,自动添加数据
- (/hack/1309)
- [2024-12-23 16:33:45]
- hack成功,自动添加数据
- (/hack/1308)
- [2024-12-23 16:23:53]
- hack成功,自动添加数据
- (/hack/1307)
- [2024-12-23 16:13:08]
- hack成功,自动添加数据
- (/hack/1306)
- [2024-12-23 15:54:42]
- hack成功,自动添加数据
- (/hack/1305)
- [2024-12-23 14:58:39]
- hack成功,自动添加数据
- (/hack/1304)
- [2024-12-23 09:58:11]
- hack成功,自动添加数据
- (/hack/1302)
- [2024-12-23 09:47:22]
- hack成功,自动添加数据
- (/hack/1301)
- [2024-12-23 09:41:23]
- hack成功,自动添加数据
- (/hack/1300)
- [2024-12-23 09:26:32]
- hack成功,自动添加数据
- (/hack/1299)
- [2024-12-23 09:19:58]
- hack成功,自动添加数据
- (/hack/1298)
- [2024-12-23 09:13:29]
- hack成功,自动添加数据
- (/hack/1297)
- [2024-12-22 18:52:18]
- hack成功,自动添加数据
- (/hack/1296)
- [2024-12-22 18:13:14]
- hack成功,自动添加数据
- (/hack/1294)
- [2024-12-21 21:54:24]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 500;
const int OFF = (1 << 18);
const int MOD = 998244353;
const int MOD2 = 1e9 + 7;
const int BS = 3;
inline int add(int A, int B) {
if(A + B >= MOD) return A + B - MOD;
return A + B;
}
inline int sub(int A, int B) {
if(A - B < 0) return A - B + MOD;
return A - B;
}
inline int mul(int A, int B) {
return A * 1ll * B % MOD;
}
inline int add2(int A, int B) {
if(A + B >= MOD2) return A + B - MOD2;
return A + B;
}
inline int sub2(int A, int B) {
if(A - B < 0) return A - B + MOD2;
return A - B;
}
inline int mul2(int A, int B) {
return A * 1ll * B % MOD2;
}
const int STEP = 50000;
int pott1[N], pott2[N];
int pott12[N], pott22[N];
inline int fast_pot(ll B) {
if(B < 0) B = (B % (MOD - 1)) + (MOD - 1);
B %= (MOD - 1);
return mul(pott1[B % STEP], pott2[B / STEP]);
}
inline int fast_pot2(ll B) {
if(B < 0) B = (B % (MOD2 - 1)) + (MOD2 - 1);
B %= (MOD2 - 1);
return mul2(pott12[B % STEP], pott22[B / STEP]);
}
int T[2 * OFF], rT[2 * OFF], prop[2 * OFF];
int T2[2 * OFF], rT2[2 * OFF];
ll Tsum[2 * OFF];
void refresh(int x, int len) {
if(!prop[x]) return;
Tsum[x] += (ll)prop[x] * len;
T[x] = mul(T[x], fast_pot(prop[x]));
rT[x] = mul(rT[x], fast_pot(-prop[x]));
T2[x] = mul2(T2[x], fast_pot2(prop[x]));
rT2[x] = mul2(rT2[x], fast_pot2(-prop[x]));
if(x < OFF) {
prop[2 * x] += prop[x];
prop[2 * x + 1] += prop[x];
}
prop[x] = 0;
}
void update(int i, int a, int b, int lo, int hi, int kol) {
if(lo <= a && b <= hi) {
prop[i] += kol; refresh(i, b - a + 1);
return;
}
refresh(i, b - a + 1);
if(a > hi || b < lo) return;
update(2 * i, a, (a + b) / 2, lo, hi, kol);
update(2 * i + 1, (a + b) / 2 + 1, b, lo, hi, kol);
T[i] = add(T[2 * i], T[2 * i + 1]);
rT[i] = add(rT[2 * i], rT[2 * i + 1]);
T2[i] = add2(T2[2 * i], T2[2 * i + 1]);
rT2[i] = add2(rT2[2 * i], rT2[2 * i + 1]);
Tsum[i] = Tsum[2 * i] + Tsum[2 * i + 1];
}
int ob_hsh, rev_hsh, ob_hsh2, rev_hsh2;
ll sum_q;
void query(int i, int a, int b, int lo, int hi) {
refresh(i, b - a + 1);
if(lo <= a && b <= hi) {
sum_q += Tsum[i];
ob_hsh = add(ob_hsh, T[i]);
rev_hsh = add(rev_hsh, rT[i]);
ob_hsh2 = add2(ob_hsh2, T2[i]);
rev_hsh2 = add2(rev_hsh2, rT2[i]);
return;
}
if(a > hi || b < lo) return;
query(2 * i, a, (a + b) / 2, lo, hi);
query(2 * i + 1, (a + b) / 2 + 1, b, lo, hi);
}
void precompute() {
pott1[0] = pott2[0] = 1;
for(int i = 1;i < STEP;i++)
pott1[i] = mul(pott1[i - 1], BS);
int korak = mul(pott1[STEP - 1], BS);
for(int i = 1;i < STEP;i++)
pott2[i] = mul(pott2[i - 1], korak);
pott12[0] = pott22[0] = 1;
for(int i = 1;i < STEP;i++)
pott12[i] = mul2(pott12[i - 1], BS);
int korak2 = mul2(pott12[STEP - 1], BS);
for(int i = 1;i < STEP;i++)
pott22[i] = mul2(pott22[i - 1], korak2);
}
int main() {
precompute();
int n, q; scanf("%d%d", &n, &q);
for(int i = 0;i < n;i++) {
int a; scanf("%d", &a);
Tsum[OFF + i] = a;
T[OFF + i] = fast_pot(a);
rT[OFF + i] = fast_pot(-a);
T2[OFF + i] = fast_pot2(a);
rT2[OFF + i] = fast_pot2(-a);
}
for(int i = OFF - 1; i ;i--) {
T[i] = add(T[2 * i], T[2 * i + 1]);
rT[i] = add(rT[2 * i], rT[2 * i + 1]);
Tsum[i] = Tsum[2 * i] + Tsum[2 * i + 1];
T2[i] = add2(T2[2 * i], T2[2 * i + 1]);
rT2[i] = add2(rT2[2 * i], rT2[2 * i + 1]);
}
for(;q--;) {
int ty, l, r, v;
scanf("%d%d%d", &ty, &l, &r);l--, r--;
if(ty == 1) {
scanf("%d", &v);
update(1, 0, OFF - 1, l, r, v);
} else {
sum_q = 0; ob_hsh = rev_hsh = 0;
ob_hsh2 = 0; rev_hsh2 = 0;
query(1, 0, OFF - 1, l, r);
ll val = sum_q / ((r - l + 1) / 2);
printf(((sum_q % ((r - l + 1) / 2) == 0 ) && (ob_hsh == mul(rev_hsh, fast_pot(val))) &&
(ob_hsh2 == mul2(rev_hsh2, fast_pot2(val)))) ? "YES\n" : "NO\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 19516kb
input:
8 4 1 2 3 4 5 6 7 8 2 1 8 1 1 4 4 2 1 6 2 1 8
output:
YES NO YES
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: 0
Accepted
time: 425ms
memory: 21100kb
input:
200000 200000 0 0 0 1 1 0 2 1 1 2 0 1 0 0 0 2 1 0 1 2 2 1 2 1 2 0 0 2 1 2 1 0 0 2 0 2 1 1 1 2 0 0 0 0 2 0 1 0 0 2 2 1 1 0 0 2 1 0 2 0 2 1 2 1 0 1 2 1 0 1 2 1 2 1 0 1 2 0 1 0 1 1 0 2 1 2 0 2 2 1 1 2 1 2 2 0 0 1 2 0 0 2 2 0 1 2 2 0 0 1 2 1 2 0 2 0 0 2 0 2 1 0 1 1 1 1 2 1 2 0 1 2 1 0 2 1 0 1 1 2 2 0 1 ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 100047 token(s): yes count is 22, no count is 100025
Test #3:
score: 0
Accepted
time: 462ms
memory: 20676kb
input:
200000 200000 5 5 2 0 1 1 4 1 1 0 4 2 2 5 5 4 1 2 2 0 3 3 3 2 5 4 1 5 1 0 0 4 3 4 2 2 3 1 4 2 0 5 4 0 2 5 5 5 2 2 3 4 0 2 2 5 0 2 3 5 4 0 0 2 1 0 5 3 1 4 5 2 2 3 4 5 0 5 5 5 3 3 0 1 4 3 0 0 3 2 2 0 4 5 5 5 2 4 5 2 5 3 1 1 5 2 1 0 1 0 5 0 0 1 5 1 5 3 1 5 3 5 4 0 2 2 4 2 5 2 3 4 5 4 3 5 2 5 2 4 5 3 4 ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 99734 token(s): yes count is 10, no count is 99724
Test #4:
score: 0
Accepted
time: 492ms
memory: 20452kb
input:
200000 200000 185447 70128 80288 38126 188018 126450 46081 189881 15377 21028 12588 100061 7218 74518 162803 34448 90998 44793 167718 16370 136024 153269 186316 137564 3082 169700 175712 19214 82647 72919 170919 142138 57755 168197 81575 126456 183138 106882 167154 184388 198667 190302 188371 183732...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 99837 token(s): yes count is 11, no count is 99826
Test #5:
score: 0
Accepted
time: 442ms
memory: 21028kb
input:
200000 200000 0 2 0 2 0 2 1 1 1 1 0 2 2 0 1 1 1 1 2 0 0 2 1 1 0 2 0 2 0 2 2 0 1 1 0 2 1 1 2 0 2 0 1 1 2 0 1 1 2 0 0 2 0 2 2 0 1 1 2 0 1 1 0 2 0 2 2 0 0 2 2 0 1 1 1 1 1 1 2 0 0 2 0 2 0 2 0 2 2 0 0 2 1 1 0 2 0 2 2 0 2 0 1 1 1 1 0 2 0 2 2 0 1 1 0 2 2 0 0 2 2 0 1 1 2 0 1 1 0 2 1 1 2 0 1 1 0 2 1 1 2 0 1 ...
output:
NO YES YES NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES ...
result:
ok 99868 token(s): yes count is 34, no count is 99834
Test #6:
score: 0
Accepted
time: 447ms
memory: 19720kb
input:
200000 200000 5 0 5 0 2 3 0 5 1 4 1 4 4 1 1 4 1 4 0 5 4 1 2 3 2 3 5 0 5 0 4 1 1 4 2 3 2 3 0 5 3 2 3 2 3 2 2 3 5 0 4 1 1 4 5 0 1 4 0 5 0 5 4 1 3 2 4 1 2 3 2 3 3 2 1 4 4 1 2 3 0 5 5 0 4 1 0 5 2 3 5 0 5 0 5 0 2 3 2 3 3 2 4 1 0 5 2 3 2 3 5 0 0 5 2 3 3 2 5 0 4 1 0 5 0 5 2 3 1 4 0 5 5 0 3 2 1 4 4 1 5 0 2 ...
output:
NO YES YES NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO...
result:
ok 99999 token(s): yes count is 32, no count is 99967
Test #7:
score: 0
Accepted
time: 471ms
memory: 20736kb
input:
200000 200000 185447 14553 70128 129872 80288 119712 38126 161874 188018 11982 126450 73550 46081 153919 189881 10119 15377 184623 21028 178972 12588 187412 100061 99939 7218 192782 74518 125482 162803 37197 34448 165552 90998 109002 44793 155207 167718 32282 16370 183630 136024 63976 153269 46731 1...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 99951 token(s): yes count is 16, no count is 99935
Test #8:
score: 0
Accepted
time: 435ms
memory: 20088kb
input:
200000 200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...
output:
NO YES YES NO NO NO YES YES YES NO YES YES NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO...
result:
ok 99715 token(s): yes count is 40, no count is 99675
Test #9:
score: 0
Accepted
time: 452ms
memory: 19908kb
input:
200000 200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...
output:
YES NO YES NO YES YES NO YES NO NO NO YES NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 100013 token(s): yes count is 34, no count is 99979
Test #10:
score: -100
Wrong Answer
time: 473ms
memory: 20588kb
input:
200000 200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...
output:
YES YES NO YES NO YES NO NO NO NO YES NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer expected YES, found NO [96807th token]