67052023-12-17 17:15:41111Kazamatacpp17Accepted 40/4039ms6124 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);
		int d = 0;
		if (t == m.begin()) {
			d = max(0ll, N + i - m.rbegin()->first - (ans - m.rbegin()->second));
		}
		else {
			d = max(0ll, i - prev(t)->first - (ans - prev(t)->second));
		}
		if (i) d = min(d, 1ll);
		ans += d;
	}
	cout << ans << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/014ms2868 KiB
3Accepted2/23ms2100 KiB
4Accepted2/23ms2236 KiB
5Accepted2/23ms2448 KiB
6Accepted2/23ms2664 KiB
7Accepted2/23ms2896 KiB
8Accepted2/23ms3088 KiB
9Accepted2/23ms3304 KiB
10Accepted2/23ms3408 KiB
11Accepted2/228ms5072 KiB
12Accepted2/232ms5368 KiB
13Accepted2/228ms5324 KiB
14Accepted2/232ms5236 KiB
15Accepted2/228ms5268 KiB
16Accepted2/226ms5232 KiB
17Accepted2/224ms5500 KiB
18Accepted2/226ms5700 KiB
19Accepted2/235ms5656 KiB
20Accepted2/237ms5912 KiB
21Accepted2/224ms6124 KiB
22Accepted2/239ms6080 KiB