QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417784#8226. 堆操作练习题2cqbzlyCompile Error//C++142.5kb2024-05-22 22:10:352024-05-22 22:10:37

Judging History

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

  • [2024-05-22 22:10:37]
  • 评测
  • [2024-05-22 22:10:35]
  • 提交

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],f[N],sz[N],vs[2][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<<j;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]);
    	bit[i].rz(sz[i]+1);
    	int tmp=0;
    	while(a[i]){
    		int x=get(i);
    		ord[i][id0(i,a[i])]=tmp;
    		ord1[i][id0(i,a[i])]=x;
    		tmp++;
			ord[i][id(i,x)]=tmp;
			work(i);
		}
	}
	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{
				for(int j=x;j;j/=2){
					add(j,ord[j][id(j,x)],1);
				}
			}
		}
		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{
				for(int j=x;j;j/=2){
					add(j,ord[j][id(j,x)],-1);
				}
			}
		}
		else{
			int p=get0(x,y);
			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{
					int cnt=ask(x,sz[x])-ask(x,t);
					if(vs[1][z])cnt--;
					cout<<f[cnt]<<"\n";
				}
			}
		}	
	}
}

Details

answer.code: In function ‘void cl(int, int)’:
answer.code:17:9: error: ‘b’ was not declared in this scope
   17 |         b[x]=a[x];
      |         ^
answer.code: In function ‘void work(int)’:
answer.code:23:26: error: ‘b’ was not declared in this scope
   23 |         if(x*2>=(1<<h)||!b[x*2]&&!b[x*2+1]){
      |                          ^
answer.code:27:12: error: ‘b’ was not declared in this scope
   27 |         if(b[x*2]>b[x*2+1]){
      |            ^
answer.code: In function ‘int get(int)’:
answer.code:37:26: error: ‘b’ was not declared in this scope
   37 |         if(x*2>=(1<<h)||!b[x*2]&&!b[x*2+1])return x;
      |                          ^
answer.code:38:12: error: ‘b’ was not declared in this scope
   38 |         if(b[x*2]>b[x*2+1])return get(x*2);
      |            ^
answer.code: In function ‘int main()’:
answer.code:62:22: error: ‘j’ was not declared in this scope
   62 |     for(int i=1;i<1<<j;i++){
      |                      ^
answer.code:110:31: error: ‘get0’ was not declared in this scope; did you mean ‘getw’?
  110 |                         int p=get0(x,y);
      |                               ^~~~
      |                               getw