QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473804 | #6427. Just Another Game of Stones | RainingLove | TL | 2989ms | 34632kb | C++23 | 4.6kb | 2024-07-12 14:17:32 | 2024-07-12 14:17:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,q,a[maxn],op,l,r,x;
inline int read() {
int x=0,f=1;
char ch=cin.get();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=cin.get();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+(ch^48);ch=cin.get();}
return x*f;
}
#define maxm 505
#define rg register
int bel[maxn],st[maxm],ed[maxm];
int Max[maxm];
vector<int>qwq[maxm],Xor[maxm],sum[30][maxm];
int qp[30];
int main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
n=read(),q=read();
for(rg int i=1;i<=n;++i) a[i]=read();
qp[0]=1;
for(rg int i=1;i<=29;++i) qp[i]=(qp[i-1]<<1);
rg int block=sqrt(n);
for(rg int i=1;i<=(n-1)/block+1;++i) {
st[i]=(i-1)*block+1;
ed[i]=min(i*block,n);
for(rg int j=st[i];j<=ed[i];++j) {
bel[j]=i;
qwq[i].push_back(a[j]);
Xor[i].push_back(0);
for(rg int k=0;k<=29;++k) sum[k][i].push_back(0);
}
sort(qwq[i].begin(),qwq[i].end());
for(rg int j=0;j<qwq[i].size();++j) {
if(j==0) {
Xor[i][j]=qwq[i][j];
for(rg int k=0;k<=29;++k) sum[k][i][j]=((qwq[i][j]&qp[k])!=0);
}
else {
Xor[i][j]=(Xor[i][j-1]^qwq[i][j]);
for(rg int k=0;k<=29;++k) sum[k][i][j]=((qwq[i][j]&qp[k])!=0)+sum[k][i][j-1];
}
}
}
while(q--) {
op=read(),l=read(),r=read(),x=read();
if(op==1) {
rg int s=bel[l]+1,t=bel[r]-1;
for(rg int i=s;i<=t;++i) Max[i]=max(Max[i],x);
for(rg int i=st[s-1];i<=ed[s-1];++i) {
a[i]=max(a[i],Max[s-1]);
if(l<=i&&i<=r) a[i]=max(a[i],x);
qwq[s-1][i-st[s-1]]=a[i];
}
Max[s-1]=0;
sort(qwq[s-1].begin(),qwq[s-1].end());
for(rg int i=0;i<qwq[s-1].size();++i) {
if(i==0) {
Xor[s-1][i]=qwq[s-1][i];
for(rg int k=0;k<=29;++k) sum[k][s-1][i]=((qwq[s-1][i]&qp[k])!=0);
}
else {
Xor[s-1][i]=(Xor[s-1][i-1]^qwq[s-1][i]);
for(rg int k=0;k<=29;++k) sum[k][s-1][i]=((qwq[s-1][i]&qp[k])!=0)+sum[k][s-1][i-1];
}
}
if(bel[l]!=bel[r]) {
for(rg int i=st[t+1];i<=ed[t+1];++i) {
a[i]=max(a[i],Max[t+1]);
if(l<=i&&i<=r) a[i]=max(a[i],x);
qwq[t+1][i-st[t+1]]=a[i];
}
Max[t+1]=0;
sort(qwq[t+1].begin(),qwq[t+1].end());
for(rg int i=0;i<qwq[t+1].size();++i) {
if(i==0) {
Xor[t+1][i]=qwq[t+1][i];
for(rg int k=0;k<=29;++k) sum[k][t+1][i]=((qwq[t+1][i]&qp[k])!=0);
}
else {
Xor[t+1][i]=(Xor[t+1][i-1]^qwq[t+1][i]);
for(rg int k=0;k<=29;++k) sum[k][t+1][i]=((qwq[t+1][i]&qp[k])!=0)+sum[k][t+1][i-1];
}
}
}
}
else {
rg int s=bel[l]+1,t=bel[r]-1;
rg int tmp=0;
for(rg int i=s;i<=t;++i) {
rg int p=upper_bound(qwq[i].begin(),qwq[i].end(),Max[i])-qwq[i].begin();
rg int len=qwq[i].size();
tmp^=(Xor[i][len-1]^Xor[i][p-1]);
if(p&1) tmp^=Max[i];
}
for(rg int i=l;i<=min(r,ed[s-1]);++i) tmp^=max(a[i],Max[s-1]);
if(bel[l]!=bel[r]) {
for(rg int i=st[t+1];i<=r;++i) tmp^=max(a[i],Max[t+1]);
}
tmp^=x;
if(tmp==0) cout<<"0\n";
else {
rg int js=-1;
rg int ans=0;
if((tmp^x)<x) ans++;
while(tmp) js++,tmp>>=1;
for(rg int i=l;i<=min(r,ed[s-1]);++i) if((max(a[i],Max[s-1])&(1<<js))) ans++;
if(bel[l]!=bel[r]) {
for(rg int i=st[t+1];i<=r;++i) if((max(a[i],Max[t+1])&(1<<js))) ans++;
}
for(rg int i=s;i<=t;++i) {
rg int p=upper_bound(qwq[i].begin(),qwq[i].end(),Max[i])-qwq[i].begin();
rg int len=qwq[i].size();
if((Max[i]&(1<<js))) ans+=p;
ans+=sum[js][i][len-1]-sum[js][i][p-1];
}
cout<<ans<<'\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
5 4 1 2 1 4 1 2 1 3 1 1 2 4 3 2 2 4 4 2 1 4 4
output:
1 0 3
result:
ok 3 number(s): "1 0 3"
Test #2:
score: 0
Accepted
time: 2989ms
memory: 34632kb
input:
200000 200000 962352030 173642520 1008864183 74920228 684681800 500911321 1001441054 257633652 185843534 59168654 317689197 731348417 123888883 708119712 340055368 876566011 980078202 969174443 814012870 715639041 596932238 173757742 314504576 1045746913 740811577 570187156 999816627 12441059 122507...
output:
38889 57353 46659 19709 34617 138247 1211 755 16087 26119 14051 12263 33399 14363 41869 21117 97277 16733 64611 737 32715 25031 148859 17395 76263 56261 19825 93349 48429 22291 31645 9833 35195 95623 184389 39321 153 6067 6495 25369 9041 35785 39783 111237 151543 54289 121169 165785 101803 101821 15...
result:
ok 99837 numbers
Test #3:
score: 0
Accepted
time: 2959ms
memory: 34504kb
input:
200000 200000 962448218 958513200 826817273 288493295 72329606 793844396 161474258 749557053 862074728 135184207 668911451 838765519 576454286 121274388 388348135 263187992 907050448 15832750 818487193 381586607 465699121 602151844 79762183 196026513 582482566 931149307 480935730 159461747 585046007...
output:
18515 12719 24057 31925 17901 115925 146271 104061 8999 158211 146057 111579 31549 925 50509 62041 43485 3087 109093 6501 70803 59687 75457 137021 61153 24695 112325 3009 42565 14461 8419 2077 61229 60333 160819 40045 65745 4959 2349 13803 73683 115339 137585 48641 23943 1473 84973 68993 89153 5491 ...
result:
ok 99962 numbers
Test #4:
score: 0
Accepted
time: 2950ms
memory: 34440kb
input:
200000 200000 962544405 669642056 644770364 502066363 533719237 13035646 395249287 167738631 464564098 211199761 1020133705 946182622 1029019688 608170888 436640902 723551797 834022694 136232881 822961515 47534172 334466005 1030545946 918761614 420047937 424153555 218369633 1035796657 306482436 1047...
output:
3255 81127 56879 67249 46421 116905 6071 4199 79925 17027 86579 891 62153 89905 97233 63251 10311 629 59525 142181 170519 3593 30971 86945 30873 81313 84145 3727 115629 1579 38801 6967 84659 134727 79203 108359 19231 116677 99273 12449 6909 189769 46489 77353 34309 13175 43589 124695 21251 35733 130...
result:
ok 99924 numbers
Test #5:
score: 0
Accepted
time: 2896ms
memory: 34516kb
input:
199999 200000 0 1 0 0 0 0 1 0 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 1 0 0 0 1 1 ...
output:
0 39093 0 0 7465 0 16579 0 14007 0 0 71337 0 0 0 52371 0 87361 0 21725 8205 0 0 0 0 8837 0 0 64937 0 0 0 62465 0 0 0 0 0 67977 107293 57805 83445 0 98381 0 101425 577 0 0 50485 31097 11921 37185 0 35729 11129 141839 121671 0 0 0 0 0 0 44997 0 0 0 132229 0 0 0 0 70937 0 78495 76809 31585 0 55525 1090...
result:
ok 99939 numbers
Test #6:
score: 0
Accepted
time: 2963ms
memory: 34440kb
input:
199999 199998 1514 307 1429 1644 257 1275 1599 1099 231 740 501 1730 30 1561 727 888 1148 152 373 1110 1776 917 304 1115 113 1254 383 1479 23 1954 462 916 1878 1432 1196 189 1274 477 26 1068 800 890 1554 1775 1777 1357 344 1551 1139 1469 168 584 1062 1181 1662 1430 452 1685 1468 565 635 1525 1767 15...
output:
75781 45269 14269 4339 54337 89997 105757 21133 47553 8351 95253 19225 2623 29671 48643 57371 22603 103747 176527 88497 118589 118351 61833 85051 110213 149685 29443 91475 6649 91685 2991 112405 14547 36451 509 107069 28719 8261 45761 9403 421 70013 3859 1619 51015 75363 19885 8387 112275 59989 8261...
result:
ok 100162 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
199997 199998 0 11 4 13 6 30 28 30 18 13 21 24 4 24 1 9 30 27 12 12 6 30 9 31 16 25 5 5 7 13 24 15 9 10 21 12 27 29 28 8 16 20 9 30 5 11 9 25 6 2 14 26 3 14 23 1 10 11 12 31 22 23 23 0 25 10 2 6 3 31 31 14 20 19 15 2 17 4 2 31 27 20 2 23 5 17 30 30 14 9 25 15 8 31 9 30 13 13 2 0 19 3 21 3 10 4 4 29 ...
output:
7875 57807 95059 7017 30085 5059 123909 151147 34203 40629 119345 20891 1495 23551 32049 5233 37025 33671 43355 107345 87053 44329 126053 31685 6605 42943 45281 39709 3877 15207 89705 138957 70835 64647 23691 94099 84845 138199 7169 122397 126567 92163 180731 106401 68389 87627 64683 66505 49689 320...