QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570716#9313. Make MaxDBXZHAOWA 1ms5856kbC++141.6kb2024-09-17 17:19:122024-09-17 17:19:14

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-17 17:19:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5856kb
  • [2024-09-17 17:19:12]
  • 提交

answer

// ֻѡÔñΪ2µÄÇø¼ä
// Ñ¡ÔñÏàÁÚ½ÏСµÄÒ»¶¨±ÈÑ¡´óµÄ¸üÓÅ
#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010;

int n, m;
int w[N];
int mount[N], sum[N], cnt;
PII wg[N];
map<int, int> alp;
set<int> nums;

inline void read(int& a)
{
	int s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
			w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	a = s * w;
}


int main()
{
	int T;
	read(T);
	while (T -- )
	{
		read(n);
		
		m = 0;
		for (int i = 1; i <= n; ++ i)
		{
			read(w[i]);
			if (i == 1 || w[i] != w[i - 1]) wg[++ m] = {w[i], 1};
			else wg[m].y ++;
		}
		
		for (int i = 1; i <= m; ++ i)
			sum[i] = sum[i - 1] + wg[i].y;
		
		cnt = 0;
		mount[++ cnt] = 1;
		for (int i = 2; i < m; ++ i)
			if (wg[i].x > wg[i - 1].x && wg[i].x > wg[i + 1].x) 
				mount[++ cnt] = i;
		mount[++ cnt] = m;

		LL res = 0;
		nums.clear();
		for (int i = 1; i < cnt; ++ i)
		{
			int len = 0;
			int j = i + 1;
			for (int k = mount[i] + 1; k <= mount[j]; ++ k)
			{
				nums.insert(wg[k].x);
				if (alp[wg[k].x] == 0) len ++;
				alp[wg[k].x] += wg[k].y;
			}
			
			int tmp;
			int now = 1;
			for (auto it = nums.begin(); it != nums.end(); ++ it)
			{
				tmp = *it;
				res = res + (LL)alp[tmp] * (len - now);
				alp[tmp] = 0;
				++ now;
			}
			
			wg[mount[j]].x = tmp, wg[mount[j]].y = sum[mount[j]];
		}
		
		printf("%lld\n", res);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5856kb

input:

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

output:

0
0
0
1

result:

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