QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574653#9313. Make MaxAntonioniWA 535ms30224kbC++171.3kb2024-09-18 23:35:092024-09-18 23:35:10

Judging History

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

  • [2024-09-18 23:35:10]
  • 评测
  • 测评结果:WA
  • 用时:535ms
  • 内存:30224kb
  • [2024-09-18 23:35:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N =2e5+5;

typedef struct k{
	int l,r,v;
} kk;
#define inf 0x7ffff 
map<int,vector<kk>>mp;
kk pp[N];
void solve(){
	int n;cin>>n;int arr[n+1];
	int ans=0;
	kk last;
	int maxx=0;
	cin>>arr[1];
	maxx=arr[1];
	last.l=1;
	last.v=arr[1];
	for(int i=2;i<=n;i++){
		cin>>arr[i];
		maxx=max(maxx,arr[i]); 
		if(arr[i]!=last.v){
			mp[last.v].push_back({last.l,i-1,last.v});
			last.l=i;
			last.v=arr[i];
		}
	}
	mp[last.v].push_back({last.l,n,last.v});
	for(auto &it:mp){
		if(it.first==maxx){
			break;
		}
		sort(it.second.begin(),it.second.end(),[&](kk x,kk y){
			return x.l<y.l;
		});
		
		int p=0;int q=1;
		for(auto i:it.second){
			pp[++p]=i;
		}
		for (int i = 2; i <= p; ++i)
				{
					if (pp[q].r + 1 == pp[i].l)
					{
						pp[q].r = pp[i].r;
					}
				else {
					q++;
					pp[q]=pp[i];
				}
		}
		
		it.second.clear();
		for (int i = 1; i <= q; ++i)
				{
					it.second.push_back(pp[i]);
				}
				
		for(auto i:it.second){
			int m1=arr[i.l-1];
			int m2=arr[i.r+1];
			int minn=min(m1,m2);
			ans+=i.r-i.l+1;
			mp[minn].push_back({i.l,i.r,minn});
		}
	}
	cout<<ans;
	cout<<endl;
	mp.clear();
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3656kb

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
Wrong Answer
time: 535ms
memory: 30224kb

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:

3939473
3808534

result:

wrong answer 1st numbers differ - expected: '4084978', found: '3939473'