# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696835 |
2023-02-07T11:13:48 Z |
puppy |
Fish (IOI08_fish) |
C++17 |
|
262 ms |
21872 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int F, K, M;
pair<int, int> fish[500005]; //(length, color)
struct mulseg
{
vector<int> tree;
mulseg(int n)
{
int sz = 1 << ((int)ceil(log2(n+1))+1);
tree.resize(sz);
}
int init(int s, int e, int node, vector<int> &arr)
{
if (s == e) return tree[node] = arr[s] % M;
return tree[node] = init(s, (s+e)/2, 2*node, arr) * init((s+e)/2+1, e, 2*node+1, arr) % M;
}
void upd(int s, int e, int node, int id, int diff)
{
if (e < id || id < s) return;
if (s == e) {
tree[node] = (tree[node] + diff + M) % M;
return;
}
upd(s, (s+e)/2, 2*node, id, diff);
upd((s+e)/2+1, e, 2*node+1, id, diff);
tree[node] = tree[2*node] * tree[2*node+1] % M;
}
int query(int s, int e, int node, int l, int r)
{
if (l > r) return 1;
if (e < l || r < s) return 1;
if (l <= s && e <= r) return tree[node];
return query(s, (s+e)/2, 2*node, l, r) * query((s+e)/2+1, e, 2*node+1, l, r) % M;
}
};
bool visited[500005];
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> F >> K >> M;
for (int i = 0; i < F; i++) {
cin >> fish[i].first >> fish[i].second;
}
sort(fish, fish + F);
mulseg seg(K);
vector<int> cnt(K+1);
int fin = fish[F-1].first;
int pos = 0;
while (pos < F && fish[pos].first <= fin/2) pos++;
for (int i = 0; i < pos; i++) cnt[fish[i].second]++;
for (int i = 1; i <= K; i++) cnt[i]++;
seg.init(1, K, 1, cnt);
int ans = seg.query(1, K, 1, 1, K);
for (int i = F - 1; i >= 0; i--) {
while (pos > 0 && fish[pos-1].first > fish[i].first/2) {
visited[fish[pos-1].second] = true;
seg.upd(1, K, 1, fish[pos-1].second, -1);
pos--;
}
if (visited[fish[i].second]) continue;
visited[fish[i].second] = true;
ans += seg.query(1, K, 1, 1, fish[i].second-1) * seg.query(1, K, 1, fish[i].second+1, K) % M;
ans %= M;
}
ans = (ans + M - 1) % M;
assert(0 <= ans && ans < M);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
143 ms |
14180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
5908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
9092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
14172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
9444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
14012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
16104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
14164 KB |
Output is correct |
2 |
Correct |
165 ms |
18856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
222 ms |
19912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
225 ms |
17968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
262 ms |
21872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |