# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
364296 |
2021-02-08T20:35:21 Z |
dolphingarlic |
Fish (IOI08_fish) |
C++14 |
|
1213 ms |
32232 KB |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, segtree[2000001];
array<int, 3> f[500001];
pair<int, int> mx[500001];
int nxt[500001], ord[500001], idx[500001];
void increment(int pos, int node = 1, int l = 1, int r = k) {
if (l == r) segtree[node] = (segtree[node] + 1) % m;
else {
int mid = (l + r) / 2;
if (pos > mid) increment(pos, node * 2 + 1, mid + 1, r);
else increment(pos, node * 2, l, mid);
segtree[node] = (segtree[node * 2] * segtree[node * 2 + 1]) % m;
}
}
int query(int a, int b, int node = 1, int l = 1, int r = k) {
if (l > b || r < a) return 1;
if (l >= a && r <= b) return segtree[node];
int mid = (l + r) / 2;
return (query(a, b, node * 2, l, mid) * query(a, b, node * 2 + 1, mid + 1, r)) % m;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> m;
fill(segtree + 1, segtree + 4 * k + 1, 1);
for (int i = 1; i <= n; i++) {
int l, t;
cin >> l >> t;
mx[t] = max(mx[t], {l, i});
nxt[t] = max(nxt[t], l);
f[i] = {l, t, i};
}
for (int i = 1; i <= n; i++)
if (mx[f[i][1]].first < f[i][0] * 2)
nxt[f[i][1]] = min(nxt[f[i][1]], f[i][0]);
sort(f + 1, f + n + 1);
iota(ord + 1, ord + k + 1, 1);
sort(ord + 1, ord + k + 1, [](int A, int B) { return mx[A] < mx[B]; });
for (int i = 1; i <= k; i++) idx[ord[i]] = i;
int ans = 0;
for (int i = 1, j = 1; i <= n; i++) {
while (f[i][0] >= get<0>(f[j]) * 2) increment(idx[get<1>(f[j++])]);
if (f[i][2] == mx[f[i][1]].second) {
ans = (ans + query(1, idx[f[i][1]])) % m;
int l = idx[f[i][1]], r = k;
while (l != r) {
int mid = (l + r + 1) / 2;
if (mx[ord[mid]].first < nxt[f[i][1]] * 2) l = mid;
else r = mid - 1;
}
ans = (ans + query(1, idx[f[i][1]] - 1) * (query(idx[f[i][1]] + 1, l) + m - 1)) % m;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
184 ms |
6420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
2796 KB |
Output is correct |
2 |
Correct |
104 ms |
6508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
492 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
3948 KB |
Output is correct |
2 |
Correct |
255 ms |
12980 KB |
Output is correct |
3 |
Correct |
252 ms |
13292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
273 ms |
6380 KB |
Output is correct |
2 |
Correct |
236 ms |
6380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
4156 KB |
Output is correct |
2 |
Correct |
237 ms |
6508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
6124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
256 ms |
6892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
6884 KB |
Output is correct |
2 |
Correct |
281 ms |
9836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
441 ms |
11068 KB |
Output is correct |
2 |
Correct |
361 ms |
13804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
11056 KB |
Output is correct |
2 |
Correct |
387 ms |
9812 KB |
Output is correct |
3 |
Correct |
571 ms |
19948 KB |
Output is correct |
4 |
Correct |
413 ms |
17644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
631 ms |
13292 KB |
Output is correct |
2 |
Correct |
1213 ms |
31212 KB |
Output is correct |
3 |
Correct |
764 ms |
32232 KB |
Output is correct |
4 |
Correct |
937 ms |
28592 KB |
Output is correct |