Skip to content

Commit 7c432f2

Browse files
committed
Codeforces Gym: 105358H
Points Selection
1 parent e1afd58 commit 7c432f2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

Codeforces Gym/105358H.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @file 105358H.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2024-09-22
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 500005
20+
21+
typedef pair<int, int> pii;
22+
23+
vector<pii> rec[maxn];
24+
int f[maxn], g[maxn];
25+
26+
int Mod(int x, int mod) { return x >= mod ? x - mod : x; }
27+
uint64_t getSum(int l, int r) { return uint64_t(l + r) * (r - l + 1) / 2; }
28+
29+
void solve(void) {
30+
int n;
31+
cin >> n;
32+
for (int i = 1, x, y, v; i <= n; i++) cin >> x >> y >> v, rec[x].emplace_back(y, Mod(v, n));
33+
34+
f[0] = 0;
35+
for (int i = 1; i < n; i++) f[i] = n + 1;
36+
37+
uint64_t ans = 0, sum = 0;
38+
int maxv = n + 1;
39+
for (int i = 1; i <= n; i++) {
40+
for (auto [p, v] : rec[i]) {
41+
if (p >= maxv) continue;
42+
43+
for (int x = 0; x < n; x++) g[x] = f[x];
44+
for (int x = 0, y = v; x < n; x++, y = Mod(y + 1, n)) {
45+
if (f[y] <= max(g[x], p)) continue;
46+
sum -= getSum(f[y], n) * y;
47+
f[y] = max(g[x], p);
48+
sum += getSum(f[y], n) * y;
49+
}
50+
maxv = 0;
51+
for (int x = 0; x < n; x++) maxv = max(maxv, f[x]);
52+
}
53+
ans += sum * i;
54+
}
55+
cout << ans << endl;
56+
return;
57+
}
58+
59+
bool mem2;
60+
61+
int main() {
62+
ios::sync_with_stdio(false), cin.tie(nullptr);
63+
#ifdef LOCAL
64+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
65+
#endif
66+
67+
int _ = 1;
68+
while (_--) solve();
69+
70+
#ifdef LOCAL
71+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
72+
#endif
73+
return 0;
74+
}

0 commit comments

Comments
 (0)