QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326164 | #8226. 堆操作练习题2 | xyz123 | 20 | 14ms | 36704kb | C++14 | 2.7kb | 2024-02-12 14:17:10 | 2024-02-12 14:17:11 |
Judging History
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];
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;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
bool ch(long long qq)
{
if(!g[qq]) return 0;
if(g[qq<<1]==0&&g[(qq<<1|1)]==0)
{
if(vv[qq]) return 0;
return 1;
}
if(g[qq<<1]>g[qq<<1|1])
{
return ch(qq<<1);
}
else
{
return ch(qq<<1|1);
}
}
void move(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]);
move(qq<<1);
}
else
{
swap(g[qq],g[qq<<1|1]);
move(qq<<1|1);
}
}
int work()
{
for(int i=1;i<(1<<a);i++)
{
g[i]=d[i];
}
// cout<<q<<" "<<vv[1]<<" "<<vv[2]<<" "<<vv[3]<<" "<<ch(1)<<"\n";
while(ch(q)) move(q);
return (g[q]==d[w]);
}
int main()
{
// freopen("1.in","r",stdin);
srand((unsigned)(time(0)^(*new int)));
fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
T=1;
scanf("%lld",&a);
for(int i=1;i<(1<<a);i++)
{
d[i]=read();
id[d[i]]=i;
}
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,t1^=(1<<(q-1));
}
else
{
v1[q]=1,t2^=(1<<(q-1));
}
}
else if(op==2)
{
if(w==1)
{
v[q]=0,t1^=(1<<(q-1));
}
else
{
v1[q]=0,t2^=(1<<(q-1));
}
}
else
{
an=0;
if(!id[w])
{
printf("0\n");continue;
}w=id[w];
for(int i=t2;;i=((i-1)&t2))
{
cn=0;
for(int j=0;j+1<(1<<a);j++)
{
if(((1<<j)&i)||((1<<j)&t1)) st[++cn]=j+1;
}
for(int j=1;j<=cn;j++) vv[st[j]]=1;
an+=work();
for(int j=1;j<=cn;j++) vv[st[j]]=0;
if(i==0) break;
}
printf("%lld\n",(an%mod+mod)%mod);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 13ms
memory: 32660kb
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 1 2 0 1 0 0 0 0
result:
ok 15 numbers
Test #2:
score: 0
Accepted
time: 12ms
memory: 34636kb
input:
2 3 1 2 50 1 2 2 3 3 2 2 2 2 1 3 1 1 1 1 3 3 2 2 1 1 3 1 3 2 3 1 1 3 1 1 1 1 1 2 2 2 1 1 3 1 3 2 3 1 2 2 2 1 1 2 1 2 1 1 3 1 2 1 2 3 3 2 1 1 1 2 3 1 1 3 2 2 3 2 1 3 1 2 2 1 3 3 2 3 1 1 2 3 1 2 1 1 1 3 1 2 3 1 3 1 3 3 1 3 3 1 3 1 1 1 2 1 1 3 1 2 1 2 1 3 1 1 3 3 2 3 1 3 2 2 1 1 1 1 2 1 1 1 2 1 1 1 2 2...
output:
0 1 1 2 1 1 0 0 0 0 0 0 0 0 0
result:
ok 15 numbers
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #3:
score: 10
Accepted
time: 10ms
memory: 34532kb
input:
4 15 14 13 9 10 11 12 2 7 4 5 1 6 8 3 500 3 1 15 3 1 13 1 9 1 1 6 2 1 15 2 1 14 1 1 10 2 1 5 2 3 12 1 1 1 1 1 4 1 3 6 6 3 10 4 1 3 1 3 13 6 1 11 2 2 4 1 2 14 1 3 6 6 3 1 11 3 1 14 3 2 4 2 6 2 2 15 2 3 1 9 3 7 12 1 13 2 2 9 1 2 5 2 3 14 8 1 15 2 1 12 1 3 11 5 1 5 2 3 1 15 3 5 10 3 1 11 1 14 1 2 13 2 ...
output:
0 0 0 0 8 0 0 8 0 0 0 0 0 8 16 16 0 0 0 32 0 0 32 16 0 0 16 0 0 0 0 4 0 0 0 0 8 0 0 0 0 0 64 64 0 128 0 0 0 128 64 256 0 64 64 0 0 0 8 4 2 0 2 0 0 0 0 8 4 16 0 0 2 0 2 8 0 0 16 0 8 0 0 16 32 0 32 0 4 4 0 4 0 0 0 0 4 0 0 0 2 0 0 0 0 0 4 2 0 0 0 16 8 0 0 0 0 8 2 4 0 4 4 4 16 0 8 8 16 16 0 0 8 0 0 0 0 ...
result:
ok 171 numbers
Test #4:
score: 0
Accepted
time: 7ms
memory: 36704kb
input:
4 15 13 14 7 12 8 11 3 4 9 2 5 6 1 10 500 1 2 1 1 14 2 1 4 1 3 1 12 1 15 2 3 1 15 1 9 2 2 4 1 1 13 1 3 7 1 2 13 1 2 15 2 1 7 2 1 13 1 3 15 10 2 2 1 3 2 2 1 2 2 2 2 2 1 15 2 1 11 1 2 9 2 3 3 11 1 1 1 1 12 2 3 10 9 3 4 3 3 7 1 2 7 2 1 4 1 1 5 1 2 15 2 2 12 2 1 10 2 3 2 7 3 2 13 1 3 1 3 1 15 2 1 1 3 14...
output:
1 2 0 0 0 2 0 0 2 0 2 0 2 0 8 4 0 0 8 4 0 4 4 4 1 0 0 4 0 0 8 0 0 0 32 128 0 0 0 16 0 16 0 0 0 0 8 0 0 0 0 0 16 0 32 0 0 0 8 4 0 0 4 0 0 0 0 0 8 8 0 8 0 0 0 8 0 0 16 0 0 0 0 0 0 2 0 2 0 0 2 0 0 2 1 0 0 0 0 8 16 16 0 0 0 0 0 0 0 0 0 0 0 16 0 0 16 32 0 0 16 0 32 0 0 64 0 4 0 8 0 0 0 4 1 0 0 16 4 0 0 0...
result:
ok 148 numbers
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 14ms
memory: 34648kb
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 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 1 0 1 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 1 0 0 0 1 0 0 0 ...
result:
wrong answer 4th numbers differ - expected: '0', found: '1'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%