# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
688139 |
2023-01-27T07:40:08 Z |
finn__ |
Fish (IOI08_fish) |
C++17 |
|
307 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
class SegmentTree
{
vector<unsigned> t;
size_t l, m;
public:
SegmentTree(size_t _n, size_t _m)
{
l = 1 << (32 - __builtin_clz(_n));
m = _m;
t = vector<unsigned>(2 * l, 1);
}
void increment(size_t i)
{
i += l;
t[i] = (t[i] + 1) % m;
while (i >>= 1)
t[i] = (t[2 * i] * t[2 * i + 1]) % m;
}
unsigned range_prod(size_t i, size_t j)
{
if (j > l)
return 1;
unsigned x = 1;
i += l, j += l;
while (i <= j)
{
if (i & 1)
x = (x * t[i++]) % m;
if (!(j & 1))
x = (x * t[j--]) % m;
i >>= 1;
j >>= 1;
}
return x;
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, k, m;
cin >> n >> k >> m;
vector<pair<unsigned, unsigned>> fish(n);
vector<pair<unsigned, unsigned>> largest(k, {0, 0});
vector<unsigned> F(k);
for (auto &[l, g] : fish)
{
cin >> l >> g;
g--;
largest[g] = max(largest[g], {l, g});
F[g] = max(F[g], l);
}
sort(fish.begin(), fish.end());
sort(largest.begin(), largest.end());
vector<unsigned> c(k);
vector<vector<unsigned>> e(k, vector<unsigned>(k));
unsigned ans = 0;
SegmentTree tree(k, m);
size_t p = 0;
for (size_t i = 0; i < k; i++)
{
while (p < n && 2 * fish[p].first <= largest[i].first)
{
c[fish[p].second]++;
p++;
}
for (size_t j = 0; j < k; j++)
{
e[largest[i].second][j] = c[j] % m;
}
}
for (size_t i = 0; i < k; i++)
{
unsigned x = 1, y = 1;
for (size_t j = 0; j < k; j++)
{
if (!(e[j][i] >= e[i][i] + 1) && F[j] > F[i])
y = (y * (e[i][j] + 1)) % m;
else if (F[i] > F[j])
x = (x * (e[i][j] + 1)) % m, y = (y * (e[i][j] + 1)) % m;
}
ans = (ans + x * e[i][i]) % m;
ans = (ans + y) % m;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
328 KB |
Output is correct |
2 |
Correct |
123 ms |
10288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
2892 KB |
Output is correct |
2 |
Incorrect |
61 ms |
5564 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16924 KB |
Output is correct |
2 |
Incorrect |
17 ms |
4408 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
13860 KB |
Output is correct |
2 |
Incorrect |
200 ms |
31776 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
171 ms |
20788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
65536 KB |
Output is correct |
2 |
Runtime error |
149 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
139 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
147 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
135 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
163 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
154 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
185 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |