QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326539#8226. 堆操作练习题2linrui#0 39ms26424kbC++142.2kb2024-02-13 13:12:302024-07-04 03:23:52

Judging History

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

  • [2024-07-04 03:23:52]
  • 评测
  • 测评结果:0
  • 用时:39ms
  • 内存:26424kb
  • [2024-05-22 20:40:58]
  • hack成功,自动添加数据
  • (/hack/631)
  • [2024-02-13 13:12:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using u64=unsigned long long;
using LF=long double;
#define F(i,l,r) for(int i=l;i<=r;++i)
#define G(i,r,l) for(int i=r;i>=l;--i)
#define CT const&
#define IL inline
#define PB push_back
template<class T>
IL void tomn(T &x,T CT y){y<x?x=y,0:0;}
template<class T>
IL void tomx(T &x,T CT y){y>x?x=y,0:0;}
#define DEBUG(x) cerr<<"line:"<<__LINE__<<" "#x"="<<x<<endl
#define CUT cerr<<"**********\n"
const LF EPS=1e-10L;
IL int dcmp(LF x){return fabs(x)<=EPS?0:(x<0?-1:1);}
//const LL INF=4e18L;

const int N=500500,INF=1.02e9,P=1000000007;
struct D{
	int x,i;
};
bool operator<(D x,D y){return x.x<y.x;}
class Seg{
	D mn[4*N];
	int n;
public:
	void build(int n_,int *a_){
		n=1<<__lg(2*n_+3);
		F(i,0,2*n)mn[i]=D{INF};
		F(i,1,n_)mn[i+n]=D{a_[i],i};
		G(i,n-1,1)mn[i]=min(mn[i<<1],mn[(i<<1)|1]);
	}
	void upd(int i,D x){
//		for(i+=n;i;i>>=1)
//			mn[i]=x,tomn(x,mn[i^1]);
		i+=n,mn[i]=x;
		for(i>>=1;i;i>>=1)
			mn[i]=min(mn[i<<1],mn[i<<1|1]);
	}
	D qry(int l,int r){
		D x{INF},y{INF};
		for(l+=n-1,r+=n+1;l^r^1;l>>=1,r>>=1)
			(l&1)?void():tomn(x,mn[l^1]),(r&1)?tomn(y,mn[r^1]):void();
		return min(x,y);
	}
}sol;
int h,a[N],l[N],r[N],n,b[N],c[N];
vector<int> t[N];
bool vis[2][N],ins[N];
LL ans;
void dfs1(int u){
	static int tim;
	l[u]=r[u]=++tim,b[l[u]]=a[u];
	for(int v:t[u])dfs1(v),r[u]=tim;
}
void dfs(int u){
	for(int v:t[u])dfs(v);
	sol.upd(l[u],D{a[u],l[u]});
	c[u]=0;
	if(ins[u]){
		D d=sol.qry(l[u],r[u]);
		c[u]=d.x,sol.upd(d.i,D{INF});
	}
}
void solve(int i,int x,int y){
	if(i>n){
		sol.build(n,b);
		F(j,1,n)c[j]=0;
		dfs(1),(ans+=(c[x]==y))%=P;
		return;
	}
	if(!vis[0][i])ins[i]=0,solve(i+1,x,y);
	if(vis[1][i]||vis[0][i])ins[i]=1,solve(i+1,x,y);
}
int main(){
#ifdef LOCAL
	freopen("C.in","r",stdin);
//	freopen(".out","w",stdout);
#endif
	scanf("%d",&h),n=(1<<h)-1;
	F(i,1,n)scanf("%d",a+i);
	F(i,1,(1<<(h-1)))
		t[i].PB(2*i),t[i].PB(2*i+1);
	int q;scanf("%d",&q),dfs1(1);
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t==1)vis[y-1][x]=1;
		else if(t==2)vis[y-1][x]=0;
		else ans=0,solve(1,x,y),printf("%lld\n",ans);
	}
}

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: 26424kb

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
0
0
0
0
0
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: 39ms
memory: 26396kb

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