QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#576879#9313. Make MaxacdwzTL 0ms3568kbC++141.8kb2024-09-19 23:12:422024-09-19 23:12:42

Judging History

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

  • [2024-09-19 23:12:42]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3568kb
  • [2024-09-19 23:12:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;long long int mx=0;
		vector <long long int> a(n,0); 
		for(int i=0;i<n;i++) cin>>a[i];
		map <long long int , vector<int> > ma;
		for(int i=0;i<n;i++)
		{
			ma[a[i]].push_back(i);	
			mx=max(mx,a[i]);
		} 
		long long int ans=0;
		auto it=ma.begin();
		while(ma[mx].size()<n)
		{
			auto it=ma.begin();
			for(int i=0;i<it->second.size();i++)
			{
				int zuo=it->second[i]-1,you=it->second[i]+1;
				if(zuo==-1)
				{
					if(a[you]>it->first) {ma[a[you]].push_back(it->second[i]);a[it->second[i]]=a[you];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
				}
				else if(you==n)
				{
					if(a[zuo]>it->first) {ma[a[zuo]].push_back(it->second[i]);a[it->second[i]]=a[zuo];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
				}
				else
				{
					if(a[zuo]>it->first&&a[you]>it->first)
					{
						if(a[zuo]<=a[you]) {ma[a[zuo]].push_back(it->second[i]);a[it->second[i]]=a[zuo];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
						else {ma[a[you]].push_back(it->second[i]);a[it->second[i]]=a[you];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
					}
					else if(a[zuo]>it->first)
					{
						{ma[a[zuo]].push_back(it->second[i]);a[it->second[i]]=a[zuo];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
					}
					else if(a[you]>it->first)
					{
						{ma[a[you]].push_back(it->second[i]);a[it->second[i]]=a[you];it->second.erase(it->second.begin()+i);i--;ans++;continue;}
					}
				}
			}
			if(it->second.size()==0) ma.erase(it);
			/*for(auto i=ma.begin();i!=ma.end();i++) 
			{cout<<"        "<<i->first<<": "; 
				for(int k=0;k<i->second.size();k++) cout<<i->second[k]<<" ";
			}cout<<'\n';*/
		}
		cout<<ans<<'\n';
	}	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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: