QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707719#7765. Xor Masterforest1145140 35ms10072kbC++205.1kb2024-11-03 17:12:552024-11-03 17:12:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-03 17:12:55]
  • 评测
  • 测评结果:0
  • 用时:35ms
  • 内存:10072kb
  • [2024-11-03 17:12:55]
  • 提交

answer

//蒟蒻一枚 rp++
//即得易见平凡,仿照上例显然。留作习题答案略,读者自证不难
//反之亦然同理,推论自然成立,略去过程Q.E.D.,由上可知证毕
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define re register
#define il inline
#define gc() getchar()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define repp(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define tep(i,x) for(int i=head[x];~i;i=ne[i])
#define ls(x) x<<1
#define rs(x) x<<1|1
#define eps (1e-9)
#define inf 0x3f3f3f3f
#define INF 1e16
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define fi first
#define sc second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef double db;
namespace IO{
//	#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<9,stdin),p1==p2)?EOF:*p1++)
//	char buf[1<<9],*p1=buf,*p2=buf;
	template<typename T> inline void read(T &x){
		bool f=1;x=0;char ch=gc();
		while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=gc();}
		while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch&15),ch=gc();
		x=f?x:-x;
	}
	template<typename T> inline void write(T x){
		if(x<0) putchar('-'),x=-x;
	   	if(x>9) write(x/10);
	   	putchar(char('0'+x%10));
	}
	template <typename T,typename ...Args> inline
	void read(T &x,Args &...args){read(x);read(args...);}
	template<typename T> inline void write(T x,char c){write(x),putchar(c);}
}
using namespace IO;
typedef uint64_t u64;
bool _ST;
const int N=5e5+100;
int n,q;
u64 a[N],s[N];
struct LB{
	u64 p[N];
	bool check(u64 x){
		per(i,63,0){
			if(x&(1ull<<i)){
				if(!p[i]) return true;
				x^=p[i];
			}
		}
		return false;
	}
	void insert(u64 x){
		per(i,63,0){
			if(x&(1ull<<i)){
				if(!p[i]){
					x=p[i];
					per(j,63,0) if(p[j]&(1ull<<i)) p[j]^=p[i];
					return;
				}
				x^=p[i];
			}
		}
	} 
	u64 gmax(u64 x){
		per(i,63,0) if((x&(1ull<<i))==0) x^=p[i];
		return x;
	}
	u64 gmin(u64 x){
		per(i,63,0) if(x&(1ull<<i)) x^=p[i];
		return x;
	}
}I;
u64 buk[N<<3],*it0=buk;
struct SGT{
	u64 *sum,tag;
	int len,sz;
}tr[N<<2];
void pushup(int x){
	u64 ad=0;
	rep(i,0,tr[x].sz){
		u64 lv=(i<=tr[ls(x)].sz)?tr[ls(x)].sum[i]:0;
		u64 rv=(i<=tr[rs(x)].sz)?tr[rs(x)].sum[i]:0;
		u64 nxt=lv&rv;tr[x].sum[i]=lv^rv;
		nxt|=tr[x].sum[i]&ad,tr[x].sum[i]^=ad;
		ad=nxt;		
	}
}
void upd(int x,u64 v){
	tr[x].tag^=v;
	int len=tr[x].len;
	rep(i,0,63) if(v&(1ull<<i)){
		int val=0;
		rep(j,0,tr[x].sz) val|=((tr[x].sum[j]>>i)&1ull)<<j,tr[x].sum[j]&=(tr[x].sum[j]^(1ull<<i));
		val=len-val;
		rep(j,0,tr[x].sz) tr[x].sum[j]|=(1ull*((val>>j)&1))<<i;
	}
}
void pushdown(int x){
	if(!tr[x].tag) return;
	upd(ls(x),tr[x].tag);
	upd(rs(x),tr[x].tag);
	tr[x].tag=0;
}
void build(int x,int l,int r){
	tr[x].len=r-l+1,tr[x].sz=__lg(r-l+1),tr[x].tag=0;
	tr[x].sum=it0,it0=it0+tr[x].len+1;
	if(l==r) return tr[x].sum[0]=s[l],void();
	int mid=l+r>>1;
	build(ls(x),l,mid),build(rs(x),mid+1,r);
	pushup(x);
}
void rebuild(int x,int l,int r,u64 tmp){
	if(l==r) return tr[x].sum[0]=max(tr[x].sum[0],tr[x].sum[0]^tmp),void();
	pushdown(x);
	int mid=l+r>>1;
	rebuild(ls(x),l,mid,tmp),rebuild(rs(x),mid+1,r,tmp);
	pushup(x);
}
void update(int x,int l,int r,int L,int R,u64 v){
	if(L<=l&&r<=R) return upd(x,v),void();
	pushdown(x);
	int mid=l+r>>1;
	if(mid>=L) update(ls(x),l,mid,L,R,v);
	if(mid<R) update(rs(x),mid+1,r,L,R,v);
	pushup(x); 
} 
u64 ans[25],SZ;
void query(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R){
		u64 ad=0;
		rep(i,0,SZ){
			u64 v=(i<=tr[x].sz)?tr[x].sum[i]:0;
			u64 nxt=v&ans[i];ans[i]^=v;
			nxt|=ans[i]&ad,ans[i]^=ad;
			ad=nxt;
		}
		return;
	}
	pushdown(x);
	int mid=l+r>>1;
	if(mid>=L) query(ls(x),l,mid,L,R);
	if(mid<R) query(rs(x),mid+1,r,L,R); 
}

struct BIT{
	#define lowbit(x) (x&(-x))
	u64 tr[N];
	void upd(int u,u64 x){for(;u<=n;u+=lowbit(u)) tr[u]^=x;}
	u64 qry(u64 u){u64 res=0;for(;u;u-=lowbit(u)) res^=tr[u];return res;}
}TR;

bool _ED;
signed main(){
	fprintf(stderr,"%.20lf MB\n",(&_ST-&_ED)/1048576.0);
	//ios::sync_with_stdio(false);
	//cin.tie(0);cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,q);
	rep(i,1,n) read(a[i]),s[i]=a[i]^s[i-1],TR.upd(i,a[i]);
	build(1,1,n);
	while(q--){
		int op;read(op);
		if(op==1){
			int x;
			u64 v;read(x,v);
			TR.upd(x,v);
			update(1,1,n,x,n,I.gmin(v));
		}
		if(op==2){
			u64 x;read(x);
			if(!I.check(x)) continue;
			rebuild(1,1,n,I.gmin(x));
			I.insert(x);								
		}
		if(op==3){
			int l,r;read(l,r),SZ=__lg(r-l+1);
			memset(ans,0,sizeof ans);
			u64 tmp=I.gmin(TR.qry(l-1));
			u64 res=0;
			query(1,1,n,l,r);
			rep(i,0,63){
				int val=0;
				rep(j,0,SZ) val|=((ans[j]>>i)&1ull)<<j;
				if(tmp&(1ull<<i)) res+=1ull*(r-l+1-val)*(1ull<<i);
				else res+=1ull*val*(1ull<<i); 
			} 
			write(res,'\n');
		}
	}
	fprintf(stderr,"%.4lf s\n",1.0*clock()/CLOCKS_PER_SEC);
	return 0;
}
//谨记:
//十年OI一场空,不开longlong见祖宗
//数据千万条,清空第一条。多测不清空,爆零两行泪。清空不规范,TLE总相伴。
//快读要加类型名


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 35ms
memory: 10072kb

input:

2000 2000
1860495733 462603674 3739839441 759356520 47330263 550811730 2301200895 989240351 2499503801 2624225494 2123076812 1180966826 238739434 488666688 784742950 2583466952 4111371941 2335988605 2583741355 933716686 1644403538 1970423306 304500250 905101643 1814942168 1136358764 88729799 1577263...

output:

867006634793
3418049036989
1658469159497
794670034691
239792547603
1587489101990
592222190840
1343829229567
971235609706
571701308760
1219913933321
588622962923
2129364200509
1007100395808
3134493164996
3145027621038
2599298085956
1729302186341
837940435945
242569415869
2908005634977
1692554597386
1...

result:

wrong answer 24th lines differ - expected: '1870376108278', found: '1756666248396'

Subtask #2:

score: 0
Runtime Error

Test #5:

score: 0
Runtime Error

input:

500000 100000
12261386944926786495 7846697792998647383 16622924885320463714 170129022271213944 12625257523700625864 7684671687986103560 11532026873918423068 1131776055566669037 8263146651412710501 17872572061246021001 5017109039248728310 11088626167542318645 13810119722795416818 10928315716094262229...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

100000 100000
860905160 3192911636 290327446 2020707113 959258245 454185039 421895589 1070265496 2218913641 1684685660 1206723673 2606734467 4247254571 3341954386 3805299640 1702270353 2472053741 2816060613 1307901348 2702949728 879391505 884661815 330738731 1575749344 1239158446 2099693858 67466644...

output:

208755389215975
125497785366837
162446748431411
63166834945113
33018804920229
89343160639243
36805816758195
40790494641758
13928126471189
267168502433672
174567769038446
251141183855596
11189666657474
133862444125402
92684260245650
179275392898572
46159208957881
232612971657325
184946588056252
11022...

result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%