QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351415#8226. 堆操作练习题2grass8cow0 9ms41220kbC++171.9kb2024-03-11 21:50:212024-03-11 21:50:23

Judging History

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

  • [2024-05-22 20:40:58]
  • hack成功,自动添加数据
  • (/hack/631)
  • [2024-03-11 21:50:23]
  • 评测
  • 测评结果:0
  • 用时:9ms
  • 内存:41220kb
  • [2024-03-11 21:50:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[1<<20],p2[1001000];
const int mod=1e9+7;
int si[101000],ans[101000];bool f3[100100];
struct ed{int op,x,z;};
vector<ed>g[1010000];
int be[1010000],B,dfn[1010000],out[1010000];
void dfs(int x){
	be[++B]=x,dfn[x]=B;
	int ls=(x<<1),rs=(x<<1|1);
	if(ls<=n)dfs(ls),dfs(rs);
	out[x]=B;
}
int f[1010000],va[1010000],tr[401000];
priority_queue<int>q1,q2;
void ad(int x,int z){for(;x<=n;x+=(x&-x))tr[x]+=z;}
void cl(int x){for(;x<=n;x+=(x&-x))tr[x]=0;}
int ask(int x){int s=0;for(;x;x-=(x&-x))s+=tr[x];return s;}
int Top(){while(!q1.empty()&&!q2.empty()&&q1.top()==q2.top())q1.pop(),q2.pop();return q1.empty()?0:q1.top();}
void dfs2(int x){
	int ls=(x<<1),rs=(x<<1|1);
	if(ls<=n)dfs2(ls),dfs2(rs);
	else{f[dfn[x]]=a[x];return;}
	int l=dfn[x],r=out[x];
	for(int i=l;i<=r;i++)va[i]=a[be[i]];
	sort(va+l,va+r+1);
	f[l]=va[l];
	for(int i=l+1;i<=r;i++)f[i]=*upper_bound(va+l,va+r+1,f[i]);
	while(!q1.empty())q1.pop();while(!q2.empty())q2.pop();
	int S=0;
	for(ed t:g[x]){
		if(t.op<=2){
			if(t.z==1){
				if(t.op==1)q1.push(f[dfn[t.x]]);
				else q2.push(f[dfn[t.x]]);
			}
			else{
				int Z=((t.op==1)?1:-1);
				S+=Z,ad(f[dfn[t.x]],Z);
			}
		}
		else{
			int p=Top();
			if(p>t.z)ans[t.x]=0;
			else{
				int s1=ask(t.z-1),s2=ask(t.z);s2-=s1;
				if(p==t.z)ans[t.x]=p2[s1+s2];
				else ans[t.x]=1ll*p2[s1]*(p2[s2]-1)%mod;
				ans[t.x]=1ll*ans[t.x]*p2[si[t.x]-S]%mod;
			}
		}
	}
	for(int i=l;i<=r;i++)cl(f[i]);
}
#define pb push_back
int main(){
	scanf("%d",&n);n=(1<<n)-1;
	p2[0]=1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),p2[i]=2*p2[i-1]%mod;
	dfs(1);
	int q;scanf("%d",&q);
	for(int i=1,op,x,z;i<=q;i++){
		scanf("%d%d%d",&op,&x,&z);
		si[i]=si[i-1];
		if(op<=2&&z==2){if(op==1)si[i]++;else si[i]--;}
		if(op<=2){int u=x;while(u)g[u].pb((ed){op,x,z}),u>>=1;}
		else g[x].pb((ed){op,i,z}),f3[i]=1;
	}
	dfs2(1);
	for(int i=1;i<=q;i++)if(f3[i])printf("%d\n",ans[i]);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 40764kb

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:

0
1
0
0
0
2
0
0
2
0
1
0
0
0
0

result:

wrong answer 8th numbers differ - expected: '1', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 41220kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1
0
0
0
0
1
0
0
1
1
1
1
0
1
1
1
1
0
1
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
1
0
1
0
0
1
0
0
0
0
1
1
0
0
1
1
1
1
1
0
0
1
1
1
1
1
0
1
0
0
1
1
0
0
0
0
1
0
0
0
0
1
0
1
0
0
1
0
0
1
0
0
1
1
1
0
0
1
1
1
0
0
0
0
1
1
0
0
0
1
1
0
1
0
0
0
1
0
1
1
1
0
0
1
0
0
0
1
1
...

result:

wrong answer 37th numbers differ - expected: '1', found: '0'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%