QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576897#9313. Make Max94knTL 0ms3824kbC++141.7kb2024-09-19 23:15:302024-09-19 23:15:30

Judging History

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

  • [2024-09-19 23:15:30]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3824kb
  • [2024-09-19 23:15:30]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;
struct numbers
{
	int x,nx;	
} a0,a[200010]={0};

int t,n,ai,num,ans;
stack<numbers> s;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	
	cin>>t;
	
	while(t--)
	{
		cin>>n;
		num=ans=0;
		for (int i=1;i<=n;i++)
		{
			cin>>ai;
			if (ai==a[num].x)
			{
				a[num].nx++;
			}
			else
			{
				num++;
				a[num].x=ai,a[num].nx=1;
			}
		}
		
		for (int i=1;i<=num;i++)
		{
			if (s.empty()) s.push(a[i]);
			else
			{
				if (a[i].x>s.top().x)
				{
					while(!s.empty())
					{
						a0.x=s.top().x,a0.nx=s.top().nx;
						s.pop();
						ans+=a0.nx;
						if (s.empty())  //语句可合并 
						{
							a0.x=a[i].x,a0.nx+=a[i].nx;
							s.push(a0);
							break;
						}
						else
						{
							if (a[i].x>s.top().x)
							{
								a0.x=s.top().x,a0.nx+=s.top().nx;
								s.pop();
								s.push(a0);
							}
							else if (a[i].x<s.top().x)
							{
								a0.x=a[i].x,a0.nx+=a[i].nx;
								s.push(a0);
								break;
							}
							else
							{
								a0.x=a[i].x,a0.nx+=(a[i].nx+s.top().nx);
								s.pop();
								s.push(a0);
								break;
							}
							
						}
					}
				}
				else if (a[i].x<s.top().x) s.push(a[i]); 
				else 
				{
					a0.x=a[i].x,a0.nx=a[i].nx+s.top().nx;
					s.pop(),s.push(a0); //合并 
				}
			}
		}
		while(!s.empty())
		{
			a0.x=s.top().x,a0.nx=s.top().nx;
			s.pop();
			if (s.empty()) break;
			else
			{
				ans+=a0.nx;
				a0.x=s.top().x,a0.nx+=s.top().nx;
				s.push(a0);
			}
		}
		cout<<ans<<'\n';
		for (int i=1;i<=num;i++) a[i].nx=a[i].x=0;
	}
	
	return 0;
} 

详细

Test #1:

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

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: