QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518800#8226. 堆操作练习题2275307894aCompile Error//C++142.5kb2024-08-14 11:25:202024-08-14 11:25:20

Judging History

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

  • [2024-08-14 11:25:20]
  • 评测
  • [2024-08-14 11:25:20]
  • 提交

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
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;using pii=pair<int,int>;
const int N=(1<<18)+5,M=1e6+5,K=1e7+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=5e18+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,k,A[N],d[N],pl[M];
vector<pii> S[N];
int rk[N][20],rs[N][20];
struct bit{
	vector<int> f;int n;
	void resize(int k){n=k;f.resize(k);}
	void add(int x,int y){x++;while(x<=n) f[x-1]+=y,x+=x&-x;}
	int qry(int x){x++;int ans=0;while(x) ans+=f[x-1],x-=x&-x;return ans;}
}f[2][N];
int siz[2],ap[2][N];
ll pw[N];
void Solve(){
	scanf("%d",&k);n=(1<<k)-1;
	for(int i=pw[0]=1;i<=n;i++) pw[i]=pw[i-1]*2%mod;
	for(int i=1;i<=n;i++) scanf("%d",&A[i]),pl[A[i]]=i,d[i]=d[i/2]+1;

	for(int i=n;i;i--){
		S[i].resize((1<<k-d[i]+1)-1);
		S[i][0]=make_pair(A[i],i);
		if(i*2<=n){
			merge(all(S[i<<1]),all(S[i<<1|1]),S[i].begin()+1,[](pii x,pii y){return x>y;});
			for(int j=1;j<S[i].size();j++) S[i][j-1].se=S[i][j].se;S[i].back().se=i;
		}
		for(int j=0;j<S[i].size();j++) rk[pl[S[i][j].fi]][d[i]]=j,rs[S[i][j].se][d[i]]=j;
		for(int o:{0,1}) f[o][i].resize((1<<k-d[i]+1)-1);
	}
	int q;scanf("%d",&q);
	while(q--){
		int op,x,y;scanf("%d%d%d",&op,&x,&y);
		if(op==1||op==2){
			y--;int w=(op==1?1:-1);
			for(int i=d[x];i;i--) f[y][x>>d[x]-i].add(rs[x][i],w);
			siz[y]+=w;ap[y][x]=(op==1);
		}else{
			int len=0;y=pl[y];if(!y){puts("0");continue;}
			for(int i=d[y];i;i--) if((y>>d[y]-i)==x){len=i;break;}
			if(!len){puts("0");continue;}
			int p=rk[y][len];
			int ans=siz[1];
			if((!ap[0][S[x][p].se]&&!ap[1][S[x][p].se])||f[0][x].qry(p-1)){puts("0");continue;}
			ans-=f[1][x].qry(p-1);
			ans-=w2;
			printf("%lld\n",pw[ans]);
		}
	}
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

answer.code: In function ‘void Solve()’:
answer.code:68:30: error: ‘w2’ was not declared in this scope
   68 |                         ans-=w2;
      |                              ^~
answer.code:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d",&k);n=(1<<k)-1;
      |         ~~~~~^~~~~~~~~
answer.code:41:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         for(int i=1;i<=n;i++) scanf("%d",&A[i]),pl[A[i]]=i,d[i]=d[i/2]+1;
      |                               ~~~~~^~~~~~~~~~~~
answer.code:53:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |         int q;scanf("%d",&q);
      |               ~~~~~^~~~~~~~~
answer.code:55:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |                 int op,x,y;scanf("%d%d%d",&op,&x,&y);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~