# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
697091 |
2023-02-08T08:13:38 Z |
mjhmjh1104 |
Fish (IOI08_fish) |
C++17 |
|
559 ms |
10928 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], 0);
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]) {
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 |
Correct |
6 ms |
2260 KB |
Output is correct |
# |
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 |
2368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 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 |
6 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
257 ms |
8464 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
112 ms |
4752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2456 KB |
Output is correct |
2 |
Incorrect |
11 ms |
2516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
5968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
325 ms |
8280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
6064 KB |
Output is correct |
2 |
Incorrect |
279 ms |
8428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
274 ms |
7912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
283 ms |
8544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
7696 KB |
Output is correct |
2 |
Correct |
250 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
459 ms |
9592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
453 ms |
9688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
559 ms |
10928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |