QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#238367#5693. 众数to_the_immaculateCompile Error//C++14962b2023-11-04 16:31:482023-11-04 16:31:49

Judging History

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

  • [2023-11-04 16:31:49]
  • 评测
  • [2023-11-04 16:31:48]
  • 提交

answer

#include<iostream>
#include<vector>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int a[N];
vector<pair<int,int> > ve;
signed main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)    cin >> a[i];
	ans = 0;
	ans += a[n] * n;
	for(int i = n - 1; i >= 1; i --)
	{
		if(a[i] > a[n])
		{
			ans += a[n] * n;
			ve.push_back({i,a[i] - a[n]});
		}
		if(a[i] <= a[n])
		{
			ans += a[i] * n;
		}
	}
	vector<int>dle;
	while(ve.size())
	{
		int now = ve[0].first;
		int c = ve[0].second;
		ans += c * now;
		ve.erase(ve.begin());
		for(int i = 0; i < ve.size(); i ++)
		{
			if(ve[i].second > c)
			{
				ans += c * now;
				ve[i].second = ve[i].second - c;
			}
			else
			{
				ans += ve[i].second * now;
				dle.push_back(i);
			}
		}
		int t = 0;
		for(int i = 0; i < dle.size(); i ++)
		{
			ve.erase(ve.begin() + dle[i] - t);
			t += 1;
		}
		dle.clear();
	}
	cout << ans;
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:13:9: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   13 |         ans = 0;
      |         ^~~
      |         abs