QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571852#9313. Make Maxyuk11119WA 128ms6052kbC++171.3kb2024-09-18 09:27:092024-09-18 09:27:10

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-18 09:27:10]
  • 评测
  • 测评结果:WA
  • 用时:128ms
  • 内存:6052kb
  • [2024-09-18 09:27:09]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;
const int N = 200010;

int T, n, a[N];
vector<PII> b;
bool st[N];


bool cmp(const PII &aa, const PII &bb)
{
	if(aa.first == bb.first) return aa.second < bb.second;
	return aa.first < bb.first;
}


int main()
{
	cin >> T;
	while(T--)
	{
		memset(a, 0, sizeof(a));
		b.clear();
		int ans = 0;
		
		cin >> n;
		for(int i = 0; i < n; i++)
		{	
			cin >> a[i];
			b.push_back({a[i], i});
		}
		sort(b.begin(), b.end(), cmp);
		
		for(auto it : b)
		{
			int x = it.first, ver = it.second;
			if(ver == 0 && a[ver + 1] > x)
				ans++, a[ver] = a[ver + 1];
			else if(ver == (n - 1) && a[ver - 1] > x)
				ans++, a[ver] = a[ver - 1];
			else if(a[ver - 1] > x && a[ver + 1] > x)
			{
				if(a[ver - 1] < a[ver + 1])
					for(int j = ver; a[j] == x && j < n; j++)
						ans++, a[j] = a[ver - 1];
				else
					for(int j = ver; a[j] == x && j >= 0; j--)
						ans++, a[j] = a[ver + 1];
			}
			else if(a[ver - 1] > x)
				for(int j = ver; a[j] == x && j < n; j++)
					ans++, a[j] = a[ver - 1];
			else if(a[ver + 1] > x)
				for(int j = ver; a[j] == x && j >= 0; j--)
					ans++, a[j] = a[ver + 1];
		}
		
		cout << ans << endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 128ms
memory: 6052kb

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:

240090
229904

result:

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