QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152531 | #6427. Just Another Game of Stones | qzez# | WA | 400ms | 82228kb | C++14 | 2.7kb | 2023-08-28 11:07:19 | 2023-08-28 11:07:20 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=N*4+5,K=(1<<15)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=2e9+7;mt19937 rnd(time(0));
int n,m,A[N];
struct Node{
int x,y,w;
Node operator +(const Node &B)const{
Node C;
if(x<B.x) C.x=x,C.w=w;
else if(x>B.x) C.x=B.x,C.x=B.w;
else C.x=x,C.w=w+B.w;
C.y=INF;
if(x^C.x) C.y=min(C.y,x);
if(y^C.x) C.y=min(C.y,y);
if(B.x^C.x) C.y=min(C.y,B.x);
if(B.y^C.x) C.y=min(C.y,B.y);
return C;
}
};
namespace Tree{
#define ls v<<1
#define rs v<<1|1
Node f[M];
int t[M];
int g[M][30];
void Up(int v){
f[v]=f[ls]+f[rs];
for(int i=0;i<30;i++) g[v][i]=g[ls][i]+g[rs][i];
}
void PF(int v,int w1,int w2){
if(w1^f[v].x) return;
for(int i=0;i<30;i++){
if(f[v].x>>i&1) g[v][i]-=f[v].w;
if(w2>>i&1) g[v][i]+=f[v].w;
}
f[v].x=w2;t[v]=w2;
}
void P(int v){
if(~t[v]) PF(ls,t[v],f[v].x),PF(rs,t[v],f[v].x),t[v]=-1;
}
void BD(int l=1,int r=n,int v=1){
t[v]=-1;
if(l==r){
f[v]=(Node){A[l],INF,1};
for(int i=0;i<30;i++) if(f[v].x>>i&1) g[v][i]++;
return;
}
int m=l+r>>1;BD(l,m,ls);BD(m+1,r,rs);Up(v);
}
void Add(int x,int y,int z,int l=1,int r=n,int v=1){
if(f[v].x>=z) return;if(l^r) P(v);
if(x<=l&&r<=y&&z<f[v].y) return PF(v,f[v].x,z);
int m=l+r>>1;x<=m&&(Add(x,y,z,l,m,ls),0);y>m&&(Add(x,y,z,m+1,r,rs),0);Up(v);
}
int qry(int x,int y,int l=1,int r=n,int v=1){
if(x<=l&&r<=y) {
int ans=0;for(int i=0;i<30;i++) if(g[v][i]&1) ans|=1<<i;
return ans;
}
int m=l+r>>1;P(v);
return (x<=m?qry(x,y,l,m,ls):0)+(y>m?qry(x,y,m+1,r,rs):0);
}
int find(int x,int y,int z,int l=1,int r=n,int v=1){
if(x<=l&&r<=y) return g[v][z];int m=l+r>>1;P(v);
return (x<=m?find(x,y,z,l,m,ls):0)+(y>m?find(x,y,z,m+1,r,rs):0);
}
}
void Solve(){
int i,j;scanf("%d%d",&n,&m);
for(i=1;i<=n;i++) scanf("%d",&A[i]);
int k=m;Tree::BD();
while(m--){
int op,l,r,x;scanf("%d%d%d%d",&op,&l,&r,&x);
if(op==1){
Tree::Add(l,r,x);
}else{
int tot=x^Tree::qry(l,r);
if(!tot){puts("0");continue;}
// int ans=0,y=__lg(tot);for(i=l;i<=r;i++) if(A[i]>>y&1) ans++;ans+=(x>>y&1);
int y=__lg(tot);
printf("%d\n",(x>>y&1)+Tree::find(l,r,y));
}
}
}
int main(){
int t;
// scanf("%d",&t);
t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7868kb
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: -100
Wrong Answer
time: 400ms
memory: 82228kb
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:
38900 -365771968 46013 -401789054 29322 -1729542763 1605 572 28648822 -1829033570 196834161 -166655300 1345147573 7231 616915121 -1854170602 482623326 -1780224585 1711425904 -566887403 -1090439135 -1722255588 384081176 1073046195 786720753 457676901 1691781297 2014691170 -539646788 -1842371401 -4439...
result:
wrong answer 1st numbers differ - expected: '38889', found: '38900'