QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419216#8226. 堆操作练习题2cqbzly0 17ms105252kbC++142.8kb2024-05-23 19:00:322024-05-23 19:00:33

Judging History

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

  • [2024-05-23 19:00:33]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:105252kb
  • [2024-05-23 19:00:32]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rz resize
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const int N=(1<<19)+5;
const int mod=1e9+7;
int h,m,a[N],b[N],f[N],sz[N],vs[2][N],all,num[N];
set<int>s[N];
vector<int>ps[N],ps0[N];
vector<int>ord[N],ord0[N],ord1[N];
vector<int>bit[N];
void cl(int x,int rt){
	b[x]=a[x];
	ps[rt].pb(x);
	ps0[rt].pb(a[x]);
	if(x*2<(1<<h))cl(x*2,rt),cl(x*2+1,rt);
}
void work(int x){
	if(x*2>=(1<<h)||!b[x*2]&&!b[x*2+1]){
		b[x]=0;
		return;
	}
	if(b[x*2]>b[x*2+1]){
		b[x]=b[x*2];
		work(x*2);
	}
	else{
		b[x]=b[x*2+1];
		work(x*2+1);
	}
}
int get(int x){
	if(x*2>=(1<<h)||!b[x*2]&&!b[x*2+1])return x;
	if(b[x*2]>b[x*2+1])return get(x*2);
	return get(x*2+1);
}
int id(int i,int x){
	return lower_bound(ps[i].begin(),ps[i].end(),x)-ps[i].begin();
}
int id0(int i,int x){
	return lower_bound(ps0[i].begin(),ps0[i].end(),x)-ps0[i].begin();
}
void add(int x,int y,int z){
	for(;y<=sz[x];y+=y&-y)bit[x][y]+=z;
}
int ask(int x,int y){
	int z=0;
	for(;y;y-=y&-y)z+=bit[x][y];
	return z;
}
int main(){
    freopen("data.in","r",stdin);
    //freopen("swap.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>h;for(int i=1;i<1<<h;i++)cin>>a[i];
    cin>>m;f[0]=1;for(int i=1;i<=1<<h;i++)f[i]=f[i-1]*2%mod;
    for(int i=1;i<1<<h;i++){
    	cl(i,i);
    	sort(ps[i].begin(),ps[i].end());
    	sort(ps0[i].begin(),ps0[i].end());
    	sz[i]=ps[i].size();
    	ord[i].rz(sz[i]);
    	ord0[i].rz(sz[i]);
		ord1[i].rz(sz[i]);
    	bit[i].rz(sz[i]+1);
    	int tmp=0;
		ord1[i][id0(i,b[i])]=0;
    	while(b[i]){
    		int x=get(i);
    		ord0[i][id0(i,b[i])]=tmp;
    		tmp++;
			ord[i][id(i,x)]=tmp;
			work(i);
			if(b[i])ord1[i][id0(i,b[i])]=x;
		}
	}
	for(int i=1;i<=m;i++){
		int op,x,y;
		cin>>op>>x>>y;
		if(op==1){
			vs[y-1][x]^=1;
			if(y==1){
				for(int j=x;j;j/=2){
					s[j].insert(ord[j][id(j,x)]);
				}
			}
			else{
				all++;
				for(int j=x;j;j/=2){
					assert(ord[j][id(j,x)]);
					add(j,ord[j][id(j,x)],1);
					num[j]++;
				}
			}
		}
		else if(op==2){
			vs[y-1][x]^=1;
			if(y==1){
				for(int j=x;j;j/=2){
					s[j].erase(ord[j][id(j,x)]);
				}
			}
			else{
				all--;
				for(int j=x;j;j/=2){
					add(j,ord[j][id(j,x)],-1);
					num[j]--;
				}
			}
		}
		else{
			int p=id0(x,y);
			//cout<<p<<"\n";
			if(p==sz[x]||ps0[x][p]!=y)cout<<0<<"\n";
			else{
				int t=ord0[x][p],z=ord1[x][p];
				if(s[x].size()&&*s[x].begin()<=t||!vs[0][z]&&!vs[1][z]){
					cout<<0<<"\n";
				}
				else{
					//cout<<t<<" "<<ask(x,sz[x])-ask(x,t)<<" "<<z<<"\n";
					int cnt=ask(x,sz[x])-ask(x,t)+all-num[x];
					if(vs[1][z])cnt--;
					cout<<f[cnt]<<"\n";
				}
			}
		}	
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 105252kb

input:

2
3 2 1
50
3 3 1
1 1 2
1 2 1
2 2 1
1 2 2
2 1 2
1 1 1
1 3 2
2 1 1
2 2 2
3 1 2
3 1 3
2 3 2
1 3 2
1 2 2
2 2 2
1 2 1
1 1 2
3 1 1
2 1 2
1 1 1
2 1 1
3 1 2
3 1 3
2 3 2
1 3 2
2 2 1
1 2 1
1 1 1
3 1 2
2 1 1
1 1 1
3 3 1
2 1 1
2 3 2
1 3 1
2 3 1
1 1 2
3 1 3
2 1 2
3 3 1
3 1 3
3 1 1
3 1 1
1 3 2
1 1 1
2 1 1
3 1 1
2...

output:


result:

wrong answer Answer contains longer sequence [length = 15], but output contains 0 elements

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 15ms
memory: 105156kb

input:

9
511 509 510 504 507 505 508 501 503 506 502 494 500 499 493 473 483 495 475 491 497 461 487 490 489 498 496 478 485 480 488 378 469 482 477 462 448 422 470 424 467 421 492 439 454 484 451 376 385 458 464 463 486 411 472 449 474 459 468 479 413 457 455 371 315 432 437 466 453 476 418 433 363 434 38...

output:


result:

wrong answer Answer contains longer sequence [length = 1644], but output contains 0 elements

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%