QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#852349 | #9774. Same Sum | Wanye | WA | 945ms | 45824kb | C++14 | 4.5kb | 2025-01-11 11:29:09 | 2025-01-11 11:29:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define N 200005
using namespace std;
inline char nc(){
static char buf[1000000],*p=buf,*q=buf;
return p==q&&(q=(p=buf)+fread(buf,1,1000000,stdin),p==q)?EOF:*p++;
}
inline ll read(){
ll res = 0,w = 1;
char c = nc();
while(c<'0'||c>'9')w=(c=='-'?-1:w),c=nc();
while(c<='9'&&c>='0')res=res*10+c-'0',c=nc();
return res*w;
}
char obuf[1<<21],*p3=obuf;
inline void pc(char c){
p3-obuf<=(1<<20)?(*p3++=c):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=c);
}
inline void write(ll x){
if(x<0) pc('-'),x=-x;
if(x>9) write(x/10);
pc(x%10+'0');
}
struct node{ll s1,s2,s3,s4,s5;}tr[N<<2];
bool operator==(const node&a,const node&b){return a.s1==b.s1&&a.s2==b.s2&&a.s3==b.s3&&a.s4==b.s4&&a.s5==b.s5;}
node operator+(const node&a,const node&b){return (node){(a.s1+b.s1)%mod,(a.s2+b.s2)%mod,(a.s3+b.s3)%mod,(a.s4+b.s4)%mod,(a.s5+b.s5)%mod};}
ll n,q,i,a[N],opt,l,r,c,tag1[N<<2],tag2[N<<2],sum[N<<2];
inline void pushup(ll p){
tr[p] = tr[2*p]+tr[2*p+1];
sum[p] = sum[2*p]+sum[2*p+1];
}
inline void pushtag(ll p,ll s,ll t,ll t1,ll t2){
if(t1!=1) sum[p]*=-1,tag1[p]*=-1,tag2[p]*=-1;
sum[p]+=t2*(t-s+1),tag2[p]+=t2;
t2 = (t2%mod+mod)%mod,t1 = (t1%mod+mod)%mod;
tr[p].s1 *= t1,tr[p].s2 *= t1*t1%mod,tr[p].s3 *= t1*t1%mod*t1%mod,tr[p].s4 *= t1*t1%mod*t1%mod*t1%mod,tr[p].s5 *= t1*t1%mod*t1%mod*t1%mod*t1%mod;
tr[p].s1 %= mod,tr[p].s2 %= mod,tr[p].s3 %= mod,tr[p].s4 %= mod,tr[p].s5 %= mod;
ll p0 = 1,p1 = p0*t2%mod,p2 = p1*t2%mod,p3 = p2*t2%mod,p4 = p3*t2%mod,p5 = p4*t2%mod;
tr[p].s5 = (tr[p].s5+tr[p].s4*5%mod*p1%mod+tr[p].s3*10%mod*p2%mod+tr[p].s2*10%mod*p3%mod+tr[p].s1*5%mod*p4%mod+(t-s+1)*p5%mod)%mod;
tr[p].s4 = (tr[p].s4+tr[p].s3*4%mod*p1%mod+tr[p].s2*6%mod*p2%mod+tr[p].s1*4%mod*p3%mod+(t-s+1)*p4%mod)%mod;
tr[p].s3 = (tr[p].s3+tr[p].s2*3%mod*p1%mod+tr[p].s1*3%mod*p2%mod+(t-s+1)*p3%mod)%mod;
tr[p].s2 = (tr[p].s2+tr[p].s1*2%mod*p1%mod+(t-s+1)*p2%mod)%mod;
tr[p].s1 = (tr[p].s1+(t-s+1)*p1)%mod;
tr[p].s1 = (tr[p].s1%mod+mod)%mod;
tr[p].s2 = (tr[p].s2%mod+mod)%mod;
tr[p].s3 = (tr[p].s3%mod+mod)%mod;
tr[p].s4 = (tr[p].s4%mod+mod)%mod;
tr[p].s5 = (tr[p].s5%mod+mod)%mod;
}
inline void pushdown(ll p,ll s,ll t){
pushtag(2*p,s,(s+t)/2,tag1[p],tag2[p]);
pushtag(2*p+1,(s+t)/2+1,t,tag1[p],tag2[p]);
tag1[p] = 1,tag2[p] = 0;
}
inline void build(ll s,ll t,ll p){
tag1[p] = 1,tag2[p] = 0;
if(s==t){
sum[p] = a[s];
tr[p].s1 = a[s]%mod,tr[p].s2 = a[s]*a[s]%mod,tr[p].s3 = a[s]*a[s]%mod*a[s]%mod;
tr[p].s4 = a[s]*a[s]%mod*a[s]%mod*a[s]%mod;
tr[p].s5 = tr[p].s4*a[s]%mod;
return ;
}
build(s,(s+t)/2,2*p),build((s+t)/2+1,t,2*p+1);
pushup(p);
}
inline void add(ll l,ll r,ll c,ll s,ll t,ll p){
if(l<=s&&t<=r) return pushtag(p,s,t,1,c);
if(tag1[p]!=1||tag2[p]) pushdown(p,s,t);
if(l<=(s+t)/2) add(l,r,c,s,(s+t)/2,2*p);
if(r>(s+t)/2) add(l,r,c,(s+t)/2+1,t,2*p+1);
pushup(p);
}
inline ll get_sum(ll l, ll r, ll s, ll t, ll p) {
if (l <= s && t <= r) return sum[p];
if (tag1[p] != 1 || tag2[p]) pushdown(p, s, t);
ll res = 0;
if (l <= (s + t) / 2) res += get_sum(l, r, s, (s + t) / 2, 2 * p);
if (r > (s + t) / 2) res += get_sum(l, r, (s + t) / 2 + 1, t, 2 * p + 1);
return res;
}
inline void change(ll l,ll r,ll s,ll t,ll p){
if(l<=s&&t<=r) return pushtag(p,s,t,-1,0);
if(tag1[p]!=1||tag2[p]) pushdown(p,s,t);
if(l<=(s+t)/2) change(l,r,s,(s+t)/2,2*p);
if(r>(s+t)/2) change(l,r,(s+t)/2+1,t,2*p+1);
pushup(p);
}
inline node query(ll l,ll r,ll s,ll t,ll p){
if(l<=s&&t<=r) return tr[p];
if(tag1[p]!=1||tag2[p]) pushdown(p,s,t);
if(l<=(s+t)/2&&r>(s+t)/2) return query(l,r,s,(s+t)/2,2*p)+query(l,r,(s+t)/2+1,t,2*p+1);
else if(l<=(s+t)/2) return query(l,r,s,(s+t)/2,2*p);
else return query(l,r,(s+t)/2+1,t,2*p+1);
}
mt19937 rnd(time(0));
int main(){
ll NUM = rnd()%100000+1;
n=read(),q=read();
for(i=1;i<=n;i++) a[i]=read(),a[i]+=NUM;
build(1,n,1);
while(q--){
opt=read();
if(opt==1){
l = read(),r = read(),c = read();
add(l,r,c,1,n,1);
}
if(opt==2){
l = read(),r = read();
ll num = get_sum(l,r,1,n,1);
if(num%((r-l+1)/2)!=0){
pc('N'),pc('O'),pc('\n');
continue;
}
ll Deltaa = num/((r-l+1)/2);
node tmp1 = query(l,r,1,n,1);
change(l,r,1,n,1),add(l,r,Deltaa,1,n,1);
node tmp2 = query(l,r,1,n,1);
add(l,r,-Deltaa,1,n,1),change(l,r,1,n,1);
if(tmp1==tmp2) pc('Y'),pc('E'),pc('S'),pc('\n');
else pc('N'),pc('O'),pc('\n');
}
}
return fwrite(obuf,p3-obuf,1,stdout),0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16012kb
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: 683ms
memory: 43220kb
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: 718ms
memory: 42932kb
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: 707ms
memory: 40764kb
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: 671ms
memory: 43296kb
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: 678ms
memory: 40228kb
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: 706ms
memory: 44152kb
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: 677ms
memory: 42076kb
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: 710ms
memory: 43028kb
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: 0
Accepted
time: 703ms
memory: 39940kb
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:
ok 99963 token(s): yes count is 34, no count is 99929
Test #11:
score: 0
Accepted
time: 9ms
memory: 14912kb
input:
6 122861 0 0 0 0 0 0 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 2 2 6 1 3 3 5 1 4 4 5 1 5 5 5 1 6 6 5 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 2 2 6 1 3 3 5 1 4 4 5 1 5 5 5 1 6 6 5 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6 1 1 1 1 2 1 6...
output:
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 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 YES NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 46656 token(s): yes count is 4986, no count is 41670
Test #12:
score: 0
Accepted
time: 945ms
memory: 39892kb
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 YES YES YES YES YES NO YES YES NO YES NO YES YES NO NO YES YES YES YES NO NO YES YES NO YES NO YES YES YES YES YES YES YES NO NO NO YES YES YES YES YES NO YES YES NO YES NO YES YES YES YES NO YES NO NO YES NO NO YES YES YES NO YES YES YES YES YES NO YES YES YES NO NO NO NO NO Y...
result:
ok 200000 token(s): yes count is 142548, no count is 57452
Test #13:
score: 0
Accepted
time: 372ms
memory: 40148kb
input:
200000 200000 192638 7362 141854 58146 18695 181305 143615 56385 20728 179272 179861 20139 78463 121537 79967 120033 121724 78276 131821 68179 140320 59680 124938 75062 119503 80497 14769 185231 50662 149338 82361 117639 43840 156160 110453 89547 64825 135175 177198 22802 147890 52110 197055 2945 12...
output:
NO NO NO NO YES YES NO NO NO NO YES NO NO NO NO NO YES YES NO NO NO NO YES NO NO YES NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO YES NO NO NO NO NO YES NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO YES YES NO NO NO NO NO NO YES YES NO NO YES YES NO NO NO NO YES NO YES...
result:
ok 200000 token(s): yes count is 48250, no count is 151750
Test #14:
score: 0
Accepted
time: 45ms
memory: 44516kb
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 YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
ok 99626 token(s): yes count is 99626, no count is 0
Test #15:
score: -100
Wrong Answer
time: 158ms
memory: 45824kb
input:
197608 196219 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
YES
result:
wrong answer expected NO, found YES [1st token]