67012023-12-17 16:50:55111Kazamatacpp17Wrong answer 26/40194ms5348 KiB
#define _GLIBCXX_DEBUG

#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;
			while (t != m.begin() && t != m.end() && 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/03ms1956 KiB
2Accepted0/082ms2888 KiB
3Accepted2/23ms2512 KiB
4Accepted2/23ms2608 KiB
5Accepted2/23ms2792 KiB
6Accepted2/23ms2760 KiB
7Accepted2/24ms2876 KiB
8Accepted2/24ms2900 KiB
9Accepted2/24ms3120 KiB
10Accepted2/24ms3328 KiB
11Wrong answer0/2165ms4636 KiB
12Accepted2/2177ms4640 KiB
13Wrong answer0/2166ms4640 KiB
14Accepted2/2177ms4892 KiB
15Wrong answer0/2167ms5208 KiB
16Accepted2/2158ms5080 KiB
17Accepted2/2150ms5128 KiB
18Wrong answer0/2159ms4996 KiB
19Accepted2/2185ms5000 KiB
20Wrong answer0/2193ms5004 KiB
21Wrong answer0/2150ms5268 KiB
22Wrong answer0/2194ms5348 KiB