# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
697089 |
2023-02-08T08:13:01 Z |
mjhmjh1104 |
Fish (IOI08_fish) |
C++17 |
|
623 ms |
10868 KB |
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int M;
int tree[1048576];
int query(int i, int b, int e, int l, int r) {
if (r < l || r < b || e < l) return 1;
if (l <= b && e <= r) return tree[i];
int m = (b + e) / 2;
return 1LL * query(i * 2 + 1, b, m, l, r) * query(i * 2 + 2, m + 1, e, l, r) % M;
}
int update(int i, int b, int e, int p, int v) {
if (p < b || e < p) return tree[i];
if (b == e) return tree[i] = v;
int m = (b + e) / 2;
return tree[i] = 1LL * update(i * 2 + 1, b, m, p, v) * update(i * 2 + 2, m + 1, e, p, v) % M;
}
int n, k, cnt[500006], cnt2[500006], t, rt[500006];
bool visited[500006];
vector<pair<int, int>> v;
int main() {
scanf("%d%d%d", &n, &k, &M);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
y--;
v.push_back({ x, y });
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
while (t < n && v[t].first * 2 <= v[i].first) cnt[v[t++].second]++;
rt[i] = t;
}
int res = 0;
for (int i = 0; i < k; i++) cnt2[i] = cnt[i];
for (int i = 0; i < k; i++) tree[524287 + i] = (cnt[i] + 1) % M;
for (int i = 524286; i >= 0; i--) tree[i] = 1LL * tree[i * 2 + 1] * tree[i * 2 + 2] % M;
for (int i = n - 1; i >= 0; i--) {
while (t > rt[i]) {
--t;
cnt[v[t].second]--;
update(0, 0, 524287, v[t].second, (cnt[v[t].second] + 1) % M);
}
if (!visited[v[i].second] && cnt[v[i].second] == cnt2[v[i].second]) {
visited[v[i].second] = true;
int curr = 1LL * query(0, 0, 524287, 0, v[i].second - 1) * query(0, 0, 524287, v[i].second + 1, k - 1) % M;
res = (res + curr) % M;
}
}
for (int i = 0; i < k; i++) cnt[i] = 0;
t = 0;
for (int i = 0; i < n; i++) {
while (t < n && v[t].first * 2 <= v[i].first) cnt[v[t++].second]++;
rt[i] = t;
}
for (int i = 0; i < k; i++) tree[524287 + i] = (cnt[i] + 1) % M, visited[i] = false;
for (int i = 524286; i >= 0; i--) tree[i] = 1LL * tree[i * 2 + 1] * tree[i * 2 + 2] % M;
for (int i = n - 1; i >= 0; i--) {
while (t > rt[i]) {
--t;
cnt[v[t].second]--;
cnt[v[t].second] = max(cnt[v[t].second], -1);
update(0, 0, 524287, v[t].second, (cnt[v[t].second] + 1) % M);
}
if (!visited[v[i].second]) {
visited[v[i].second] = true;
if (cnt[v[i].second] == cnt2[v[i].second]) {
if (!cnt[v[i].second]) continue;
cnt[v[i].second]--;
cnt[v[i].second] = max(cnt[v[i].second], -1);
}
update(0, 0, 524287, v[i].second, (cnt[v[i].second] + 1) % M);
int curr = query(0, 0, 524287, 0, k - 1);
res = (res + curr) % M;
update(0, 0, 524287, v[i].second, 1);
cnt[v[i].second] = 0;
}
}
printf("%d", res);
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d%d%d", &n, &k, &M);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
7 ms |
2388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
298 ms |
8328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
113 ms |
4812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
12 ms |
2476 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
182 ms |
5988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
320 ms |
8372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
5972 KB |
Output is correct |
2 |
Incorrect |
298 ms |
8380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
277 ms |
7840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
322 ms |
8560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
7792 KB |
Output is correct |
2 |
Correct |
191 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
434 ms |
9576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
470 ms |
9616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
623 ms |
10868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |