67002023-12-17 16:48:09111Kazamatacpp17Wrong answer 26/4037ms5272 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be2.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	map<int, int> m;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		v[i] = (v[i] + ans) % N;
		if (!m.count(v[i])) {
			auto t = m.insert({v[i], ans}).first;
			if (t != m.begin() && t->first - t->second <= prev(t)->first - prev(t)->second) {
				t = m.erase(t);
			}
		}
		auto t = m.upper_bound(i);
		if (t == m.begin()) {
			ans += max(0ll, N + i - m.rbegin()->first - (ans - m.rbegin()->second));
		}
		else {
			ans += max(0ll, i - prev(t)->first - (ans - prev(t)->second));
		}
	}
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base26/40
1Accepted0/03ms1868 KiB
2Accepted0/014ms2900 KiB
3Accepted2/23ms2376 KiB
4Accepted2/23ms2312 KiB
5Accepted2/23ms2516 KiB
6Accepted2/23ms2488 KiB
7Accepted2/23ms2664 KiB
8Accepted2/23ms2736 KiB
9Accepted2/23ms2736 KiB
10Accepted2/23ms2736 KiB
11Wrong answer0/227ms4404 KiB
12Accepted2/230ms4416 KiB
13Wrong answer0/227ms4268 KiB
14Accepted2/230ms4320 KiB
15Wrong answer0/227ms4576 KiB
16Accepted2/225ms4484 KiB
17Accepted2/223ms4740 KiB
18Wrong answer0/225ms5072 KiB
19Accepted2/234ms5132 KiB
20Wrong answer0/237ms5016 KiB
21Wrong answer0/223ms5272 KiB
22Wrong answer0/237ms5224 KiB