QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566479#9313. Make Maxwjh111Compile Error//C++141.7kb2024-09-16 00:14:172024-09-16 00:14:21

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 00:14:21]
  • 评测
  • [2024-09-16 00:14:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans=0,n;
const int N=200004;
int tree[N*4],a[N];
int ls(int x){
	return (x*2);
}
int rs(int x){
	return (x*2+1);
}
void push(int x){
	tree[x]=a[tree[ls(x)]]>=a[tree[rs(x)]]?tree[ls(x)]:tree[rs(x)];
}
int q(int pl,int pr,int p,int l,int r){
	int res;
	if (pl==l&&r==pr)
	return tree[p];
	int m=(l+r)/2;
	if (pl<=m&&pr>m){
		int s1=q(max(pl,m+1),pr,rs(p),m+1,r),s2=q(pl,min(pr,m),ls(p),l,m);
	res=a[s2]>=a[s1]?s2:s1;
	return res;}
	else{
		if (pr>m){
			res=q(max(pl,m+1),pr,rs(p),m+1,r);
		}
		else{
			res=q(pl,min(pr,m),ls(p),l,m);
		}
		return res;
	}
}
/*int q(int pl,int pr,int p,int l,int r){
	int res=0;
	if (pl<=l&&r<=pr)
	return tree[p];
	int m=(l+r)/2;
	if (pl<=m)
	res+=q(pl,pr,ls(p),l,m);
	if (pr>m)
	res+=q(pl,pr,rs(p),m+1,r);
	return res;
}*///等价的 
void build(int x,int l,int r){
	if (l==r){
		tree[x]=r;
		return ;
	}
	int m=(l+r)/2;
	build(ls(x),l,m);
	build(rs(x),m+1,r);
	push(x);
	return ;
}
int dfs(int a1,int b,int k){
	if (b<a1){
		return 0;
	}
	if (b==a1){
		return a[b];
	}
	int i1=q(a1,b,1,1,n),m=a[i1];
	//cout<<a1<<" "<<b<<" "<<i1<<"\n";
	int s1=dfs(a1,i1-1,m),s2=dfs(i1+1,b,m);
	if (s1!=0&&s1<m){
		ans+=i1-a1;
	}
	if (s2!=0&&s2<m){
		ans+=b-i1;
	}
	return m;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while (t--){
		int i;
		ans=0;
		cin>>n;
		for (i=1;i<=n;i++){
			cin>>a[i];
		}
		build(1,1,n);
		int i1=q(1,n,1,1,n),m=a[i1];
		//cout<<i1<<" ";
		int s1=dfs(1,i1-1,m),s2=dfs(i1+1,n,m);
		if (s1>0&&s1<m){
			ans+=i1-1;
		}
		if (s2>0&&s2<m){
			ans+=n-i1;
		}
		cout<<ans<<"\n";
		//cout<<q(1,n,1,1,n)<<"\n";
	}
} 

Details

cc1plus: error: ‘::main’ must return ‘int’