QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578615#9313. Make MaxHorizonblackRE 1ms7704kbC++141.6kb2024-09-20 20:24:502024-09-20 20:24:51

Judging History

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

  • [2024-09-20 20:24:51]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7704kb
  • [2024-09-20 20:24:50]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define maxn 200010
using namespace std;
template <typename T>inline void read(T &x){
	x=0;
	bool res=0;
	char c=getchar();
	while(!isdigit(c)){
		if(c=='-') res=1;
		c=getchar();
	}
	while(isdigit(c)){
		x=(x<<1)+(x<<3)+(c^'0');
		c=getchar();
	}
	if(res) x=(~x)+1;
	return;
}
template <typename T>inline void wr(T x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9) wr(x/10);
	putchar((x%10)+'0');
	return; 
}
int n,t,b[maxn];
struct node{
	int l,r,val,num;
}a[maxn*4];
struct num{
	int k,v;
}c[maxn];
void build(int p,int l,int r){
	a[p].l=l;
	a[p].r=r;
	if(l==r){
		a[p].val=b[l];
		return;
	}
	int mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	a[p].val=max(a[p*2].val,a[p*2+1].val);
}
int ask(int p,int l,int r){
	if(l<=a[p].l&&r>=a[p].r) return a[p].val;
	int ma=0;
	int mid=(a[p].l+a[p].r)/2;
	if(l<=mid) ma=max(ma,ask(p*2,l,r));
	if(r>mid) ma=max(ma,ask(p*2+1,l,r));
	return ma;
} 
int fin(int x,int l,int r){
	if(l==r-1){
		if(b[l]==b[r]) return 0;
		else return 1;
	}
	int y=ask(1,l,r);
	while(c[x].v>y) x--;
	int m=c[x].k;
	int ans=0;
	if(l<m-1){
		ans+=fin(x-1,l,m-1);
		if(ask(1,l,m-1)<y) ans+=m-l;
	}
	if(r>m+1){
		ans+=fin(x-1,m+1,r);
		if(ask(1,m+1,r)<y) ans+=r-m;
	}
	return ans;
}
bool cmp(num x,num y){
	return x.v<y.v;
}
int main(){
	read(t);
	while(t--){
		read(n);
		for(int i=1;i<=n;i++){
			read(b[i]);
			c[i].v=b[i];
			c[i].k=i;
		}
		sort(c+1,c+1+n,cmp);
		build(1,1,n);
		wr(fin(n,1,n));
		putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7704kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Runtime Error

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:


result: