QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#926359#9727. Barkley IIID06TL 164ms16520kbC++143.2kb2025-03-05 19:59:272025-03-05 19:59:29

Judging History

This is the latest submission verdict.

  • [2025-03-05 19:59:29]
  • Judged
  • Verdict: TL
  • Time: 164ms
  • Memory: 16520kb
  • [2025-03-05 19:59:27]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
struct t1
{
	int l,r;
	long long state,v,bj;
}t[4000005];
void build(int p,int l,int r)
{
	t[p].l=l;
	t[p].r=r;
	t[p].bj=~0ll;
	if(l==r)
	{
		t[p].state=~a[l];
		t[p].v=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	t[p].state=(t[p*2].state&t[p*2+1].v)|(t[p*2].v&t[p*2+1].state);
	t[p].v=t[p*2].v&t[p*2+1].v;
}
void spread(int p)
{
	if(t[p].bj!=(~0ll))
	{
		t[p*2].bj&=t[p].bj;
		t[p*2+1].bj&=t[p].bj;
		t[p*2].l==t[p*2].r?	t[p*2].state=~(t[p*2].v&t[p].bj):t[p*2].state&=t[p].bj;
		t[p*2+1].l==t[p*2+1].r?	t[p*2+1].state=~(t[p*2+1].v&t[p].bj):t[p*2+1].state&=t[p].bj;
		t[p*2].v&=t[p].bj;
		t[p*2+1].v&=t[p].bj;
		t[p].bj=~0ll;
	}
}
long long ask(int p,int x)
{
	if(t[p].l==t[p].r)
	{
		return t[p].v;
	}
	spread(p);
	if((t[p*2].state>>x)&1)
	{
		return ask(p*2,x);
	}
	else if((t[p*2+1].state>>x)&1)
	{
		return ask(p*2+1,x);
	}
	else
	{
		return -1;
	}
}
long long askop(int p,int l,int r,int x)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		if((t[p].state>>x)&1)
		{
			return ask(p,x);
		}
		return -1;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)>>1;
	long long val=0;
	if(l<=mid)
	{
		val=askop(p*2,l,r,x);
		if(val!=-1)
		{
			return val;
		}
	}
	if(r>mid)
	{
		val=askop(p*2+1,l,r,x);
		if(val!=-1)
		{
			return val;
		}
	}
	return -1;
}
long long askva(int p,int l,int r)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		return t[p].v;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)>>1;
	long long val=~0ll;
	if(l<=mid)
	{
		val&=askva(p*2,l,r);
	}
	if(r>mid)
	{
		val&=askva(p*2+1,l,r);
	}
	return val;
}
long long askst(int p,int l,int r)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		return t[p].state;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid&&r>mid)
	{
		return (askst(p*2,l,r)&askva(p*2+1,l,r))|(askva(p*2,l,r)&askst(p*2+1,l,r));
	}
	else if(l<=mid)
	{
		return askst(p*2,l,r);
	}
	else
	{
		return askst(p*2+1,l,r);
	}
}
void change(int p,int l,int r,long long x)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		t[p].bj&=x;
		t[p].l==t[p].r?	t[p].state=~(t[p].v&x):t[p].state&=x;
		t[p].v&=x;
		return;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid)
	{
		change(p*2,l,r,x);
	}
	if(r>mid)
	{
		change(p*2+1,l,r,x);
	}
	t[p].state=(t[p*2].state&t[p*2+1].v)|(t[p*2].v&t[p*2+1].state);
	t[p].v=t[p*2].v&t[p*2+1].v;
}
void change(int p,int l,long long x)
{
	if(t[p].l==t[p].r)
	{
		t[p].state=~x;
		t[p].v=x;
		return;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid)
	{
		change(p*2,l,x);
	}
	else
	{
		change(p*2+1,l,x);
	}
	t[p].state=(t[p*2].state&t[p*2+1].v)|(t[p*2].v&t[p*2+1].state);
	t[p].v=t[p*2].v&t[p*2+1].v;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	build(1,1,n);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,s;
		long long x;
		cin>>opt;
		if(opt==1)
		{
			cin>>l>>r>>x;
			change(1,l,r,x);
		}
		else if(opt==2)
		{
			cin>>s>>x;
			change(1,s,x);
		}
		else
		{
			cin>>l>>r;
			long long va=askva(1,l,r);
			long long st=askst(1,l,r);
			cout<<(va|(st&(~askop(1,l,r,63-__builtin_clzll(st)))))<<"\n";
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5856kb

input:

5 9
7 7 7 6 7
3 1 5
2 1 3
3 1 5
3 1 3
1 1 2 3
3 1 3
2 2 8
3 1 3
3 1 2

output:

7
6
7
3
3
8

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 5856kb

input:

10 10
6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482
1 3 5 7587422031989082829
3 6 10
1 7 8 5197616143400216932
2 4 2518604563805514908
2 2 4533959...

output:

1568091718842717482
35184908959744
176025477579040
8795942500783873690

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 5724kb

input:

100 100
4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...

output:

576531121047601152
1
576460752303423488
4263579105072360993
1306043896232411137
4263579105072360993
576531121047601152
633397148123136
0
1153488865559840256
1152922054496880128
1730020640668059136
3533641810948498945
67108864
1730020640668059136
0
633397148123136
1729382296723653632
0
17300206406680...

result:

ok 78 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 5860kb

input:

1000 1000
3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3639580211161047627 3368486440884437410 3368486440884437410 3368486440...

output:

3368486440884437410
3368486440884437410
3368486440884437410
2251799981457408
0
0
3368486440884437410
0
3326828075601101216
592509842556584322
0
0
0
0
0
0
37154696925806592
0
0
0
3368486440884437410
0
0
3368486440884437410
0
578998425140330496
0
0
134217728
0
3368486440884437410
2306405959167115264
0...

result:

ok 732 lines

Test #5:

score: 0
Accepted
time: 164ms
memory: 16520kb

input:

100000 100000
4364025563773184234 7745126251050571359 5111681002836044963 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7222555899134537718 7745126251050571359 686495...

output:

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
4613942216556019776
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
...

result:

ok 75105 lines

Test #6:

score: -100
Time Limit Exceeded

input:

1000000 1000000
5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485...

output:

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
8796093022208
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
576460754450907136
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...

result: