QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576160#9313. Make Maxyasdf123Compile Error//C++201.9kb2024-09-19 18:53:552024-09-19 18:53:56

Judging History

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

  • [2024-09-19 18:53:56]
  • 评测
  • [2024-09-19 18:53:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int st[200005][100];

int fd(int l,int r){
	int k=(log2(r-l+1));
	return max(st[l][k],st[r-(1<<k)+1][k]);
}

void run(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>st[i][0];
	}
	for(int k=1;;k++){
		for(int i=1;i<=n-(1<<k)+1;i++){
			st[i][k]=max(st[i][k-1],st[i+(1<<(k-1))][k-1]);
		}
		if((1<<k)>=n){
			break;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int ll=i,rr=i;
		if(i!=1){
			int l=1,r=i-1;
			while(l<=r){
				int m=(l+r)/2;
				if(fd(m,i-1)>=st[i][0]){
					l=m+1;
				}else{
					r=m-1;
				}
//				cout<<m<<" ";
			}
			ll=r+1;
		}
		if(i!=n){
			int l=i+1,r=n;
			while(l<=r){
				int m=(l+r+1)/2;
				if(fd(i+1,m)>=st[i][0]){
					r=m-1;
				}else{
					l=m+1;
				}
			}
			if(st[l][0]!=st[i][0]){
				rr=l-1;
			}
		}
		ans+=(rr-ll);
//		cout<<ll<<rr<<"\n";
	}
	cout<<ans<<"\n";
	
}
int main(){
	int t;
	cin>>t;
	while(t--){
		run();
	}
}

int st[200005][100];

int fd(int l,int r){
	int k=(log2(r-l+1));
	return max(st[l][k],st[r-(1<<k)+1][k]);
}

void run(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>st[i][0];
	}
	for(int k=1;;k++){
		for(int i=1;i<=n-(1<<k)+1;i++){
			st[i][k]=max(st[i][k-1],st[i+(1<<(k-1))][k-1]);
		}
		if((1<<k)>=n){
			break;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int ll=i,rr=i;
		if(i!=1){
			int l=1,r=i-1;
			while(l<=r){
				int m=(l+r)/2;
				if(fd(m,i-1)>=st[i][0]){
					l=m+1;
				}else{
					r=m-1;
				}
//				cout<<m<<" ";
			}
			ll=r+1;
		}
		if(i!=n){
			int l=i+1,r=n;
			while(l<=r){
				int m=(l+r+1)/2;
				if(fd(i+1,m)>=st[i][0]){
					r=m-1;
				}else{
					l=m+1;
				}
			}
			if(st[l][0]!=st[i][0]){
				rr=l-1;
			}
		}
		ans+=(rr-ll);
//		cout<<ll<<rr<<"\n";
	}
	cout<<ans<<"\n";
	
}
int main(){
	int t;
	cin>>t;
	while(t--){
		run();
	}
}

詳細信息

answer.code:69:5: error: redefinition of ‘int st [200005][100]’
   69 | int st[200005][100];
      |     ^~
answer.code:4:5: note: ‘int st [200005][100]’ previously declared here
    4 | int st[200005][100];
      |     ^~
answer.code:71:5: error: redefinition of ‘int fd(int, int)’
   71 | int fd(int l,int r){
      |     ^~
answer.code:6:5: note: ‘int fd(int, int)’ previously defined here
    6 | int fd(int l,int r){
      |     ^~
answer.code:76:6: error: redefinition of ‘void run()’
   76 | void run(){
      |      ^~~
answer.code:11:6: note: ‘void run()’ previously defined here
   11 | void run(){
      |      ^~~
answer.code:126:5: error: redefinition of ‘int main()’
  126 | int main(){
      |     ^~~~
answer.code:61:5: note: ‘int main()’ previously defined here
   61 | int main(){
      |     ^~~~