QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326171#8226. 堆操作练习题2xyz1230 8ms92444kbC++142.7kb2024-02-12 14:47:212024-02-12 14:47:21

Judging History

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

  • [2024-05-22 20:40:58]
  • hack成功,自动添加数据
  • (/hack/631)
  • [2024-02-12 14:47:21]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:92444kb
  • [2024-02-12 14:47:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001],v1[1000001],id[1000001],op;
long long t1=0,t2=0,g[1000001],vi[1000001],vv[1000001],de[1000001],y[1000001],iv2;
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
int ch(long long qq)
{
	if(!g[qq]) return 0;
	if(g[qq<<1]==0&&g[(qq<<1|1)]==0)
	{
		return qq;
	}
	if(g[qq<<1]>g[qq<<1|1])
	{
		return ch(qq<<1);
	}
	else
	{
		return ch(qq<<1|1);
	}
}
void mov(long long qq)
{
	if(g[qq<<1]==0&&g[(qq<<1|1)]==0)
	{
		g[qq]=0;
		return;
	}
	if(g[qq<<1]>g[qq<<1|1])
	{
		swap(g[qq],g[qq<<1]);
		mov(qq<<1);
	}
	else
	{
		swap(g[qq],g[qq<<1|1]);
		mov(qq<<1|1);
	}
}
vector<int> ve[1000001],qu[1000001],qu1[1000001];
void dfs(long long qq,long long ww)
{
	ve[qq].push_back(qq);de[qq]=ww;
	if((qq<<1)>=(1<<a)) return;
	dfs(qq<<1,ww+1);dfs(qq<<1|1,ww+1);
	for(int i=0;i<ve[qq<<1].size();i++) ve[qq].push_back(ve[qq<<1][i]);
	for(int i=0;i<ve[qq<<1|1].size();i++) ve[qq].push_back(ve[qq<<1|1][i]);
}
long long get(long long qq,long long ww)
{
	return (y[h[qq]-ww+1]&qq)|((1<<(h[qq]-ww+1)));
}
int main()
{
//	freopen("1.in","r",stdin);
	scanf("%lld",&a);
	y[0]=0;
	for(int i=1;i<=a;i++) y[i]=y[i-1]|(1<<(i-1));
	for(int i=1;i<(1<<a);i++)
	{
		d[i]=read();
		id[d[i]]=i;
		for(int j=a-1;j>=0;j--)
		{
			if((1<<j)&i)
			{
				h[i]=j;break;
			}
		}
	}
	dfs(1,1);
	for(int i=1;i<(1<<a);i++)
	{
		for(int j=0;j<ve[i].size();j++) g[ve[i][j]]=d[ve[i][j]];
		int tt=0;
		qu[i].resize(ve[i].size());cn=0;
		while(tt=ch(i))
		{
			qu[i][get(id[g[i]],de[i])-1]=cn,qu1[i].push_back(tt),++cn;
			mov(i);
		}
	}
	iv2=pow_(2,mod-2);
	long long gg=1;
	scanf("%lld",&b);
	for(int ii=1;ii<=b;ii++)
	{
		op=read(),q=read(),w=read();
		if(op==1)
		{
			if(w==1)
			{
				v[q]=1;
			}
			else
			{
				gg=gg*2%mod;
				v1[q]=1;
			}
		}
		else if(op==2)
		{
			if(w==1)
			{
				v[q]=0;
			}
			else
			{
				gg=gg*iv2%mod;
				v1[q]=0;
			}
		}
		else
		{
			an=0;
			if(!id[w])
			{
				printf("0\n");continue;
			}w=id[w];
			long long ff=qu[q][get(w,de[q])-1];an=gg;
			for(int i=0;i<ff;i++)
			{
				if(v1[qu1[q][i]]) an=an*iv2%mod;
			}
			if(!v1[qu1[q][ff]]&&!v[qu1[q][ff]]) an=0;
			else if(v1[qu1[q][ff]]) an=an*iv2%mod;
			printf("%lld\n",(an%mod+mod)%mod);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 90140kb

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
1
1
2
1
1
2
0
1
0
0
0
0

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 8ms
memory: 92444kb

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
1
0
0
0
0
1
0
0
1
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
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
1
0
1
1
0
1
0
0
1
0
0
0
0
1
0
1
1
0
1
0
0
1
0
0
1
1
1
0
0
1
1
1
0
0
0
0
1
1
0
1
1
1
1
0
1
0
0
1
1
0
1
1
1
0
1
1
0
0
0
1
1
...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%