QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570729#9313. Make MaxDBXZHAOTL 1ms5892kbC++141.6kb2024-09-17 17:24:302024-09-17 17:24:32

Judging History

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

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

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;

		int res = 0;
		nums.clear();
		for (int i = 1; i < cnt; ++ i)
		{
			int len = 0;
			int j = i + 1;
			for (int k = mount[i]; 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("%d\n", res);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: