QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325674 | #8226. 堆操作练习题2 | zhouhuanyi | 0 | 5ms | 22240kb | C++14 | 2.6kb | 2024-02-11 19:21:13 | 2024-02-11 19:21:14 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cmath>
#define N 18
#define M 1000000
#define mod 1000000007
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
int h,q,leng,ans,lg[1<<N],dfn[1<<N],sz[1<<N],num[1<<N],a[1<<N],A[1<<N],B[1<<N];
bool used[1<<N],used2[1<<N];
vector<int>p[1<<N];
vector<int>dp[1<<N];
bool cmp(int x,int y)
{
return x>y;
}
bool LENG(int x,int y)
{
return dfn[x]<=dfn[y]&&dfn[y]<=dfn[x]+sz[x]-1;
}
void dfs(int x)
{
dfn[x]=++leng;
if ((x<<1)<=(1<<h)-1)
{
dfs(x<<1),dfs(x<<1|1),sz[x]=sz[x<<1]+sz[x<<1|1]+1;
for (int i=0;i<sz[x<<1];++i) p[x].push_back(p[x<<1][i]);
for (int i=0;i<sz[x<<1|1];++i) p[x].push_back(p[x<<1|1][i]);
p[x].push_back(a[x]);
}
else sz[x]=1,p[x].push_back(a[x]);
dp[x].resize(sz[x]+1),sort(p[x].begin(),p[x].end(),cmp);
return;
}
int get_rk(int x,int d)
{
int ps=0;
for (int i=lg[sz[x]];i>=0;--i)
if (ps+(1<<i)<sz[x]&&p[x][ps+(1<<i)]>=d)
ps+=(1<<i);
return ps;
}
void dfs2(int x)
{
int ps=0,ps2=0,d;
for (int i=0;i<=sz[x];++i) dp[x][i]=0;
if ((x<<1)<=(1<<h)-1)
{
dfs2(x<<1),dfs2(x<<1|1),d=used2[x]+1;
for (int i=0;i<=sz[x<<1]+sz[x<<1|1];++i)
{
if (i)
{
if (ps!=p[x<<1].size()&&(ps2==p[x<<1|1].size()||p[x<<1][ps]<p[x<<1|1][ps2])) ps++;
else ps2++;
}
dp[x][i]=1ll*dp[x<<1][ps]*dp[x<<1|1][ps2]%mod*d%mod;
}
if (!used[x]) Adder(dp[x][sz[x]],1ll*dp[x<<1][sz[x<<1]]*dp[x<<1|1][sz[x<<1|1]]%mod);
}
else
{
if (used[x]) dp[x][0]=1;
else if (used2[x]) dp[x][0]=2,dp[x][1]=1;
else dp[x][0]=dp[x][1]=1;
}
return;
}
int calc(int x,int d)
{
int res=1;
d=get_rk(x,d);
for (int i=1;i<=(1<<h)-1;++i)
if (!LENG(x,i)&&used2[i])
res=2ll*res%mod;
dfs2(x);
return 1ll*MD2(dp[x][d]-(d!=sz[x]?dp[x][d+1]:0))*res%mod;
}
int main()
{
int op,x,y;
for (int i=2;i<=(1<<N)-1;++i) lg[i]=lg[i>>1]+1;
h=read();
for (int i=1;i<=(1<<h)-1;++i) a[i]=read(),num[a[i]]=i;
dfs(1),q=read();
for (int i=1;i<=q;++i)
{
op=read(),x=read(),y=read();
if (op==1)
{
if (y==1) used[x]=1;
else used2[x]=1;
}
else if (op==2)
{
if (y==1) used[x]=0;
else used2[x]=0;
}
else
{
if (!LENG(x,num[y])) puts("0");
else printf("%d\n",calc(x,y));
}
}
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: 0ms
memory: 21816kb
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 0 1 0 1 1 1 1 0 0 0 0 0 0 0
result:
wrong answer 2nd 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: 5ms
memory: 22240kb
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 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 ...
result:
wrong answer 16th 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%