# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1086905 |
2024-09-11T16:48:08 Z |
djs100201 |
Fish (IOI08_fish) |
C++17 |
|
365 ms |
65536 KB |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ = 5e5 + 100, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k;
ll mod1;
class seg {
public:
vector<ll> tree;
ll base;
seg(int n) {
n += 10;
for (base = 1; base <= n; base *= 2);
tree.resize(n * 4);
for (int i = 0; i < tree.size(); i++) tree[i] = 1;
}
ll f(ll l, ll r) {
ll ret = 1;
l += base, r += base;
while (l <= r) {
if (l % 2) ret = (ret * tree[l++]) % mod1;
if (!(r % 2)) ret = (ret * tree[r--]) % mod1;
l /= 2, r /= 2;
}
return ret;
}
void update(ll i, ll v) {
i += base;
tree[i] += v;
tree[i] %= mod1;
i /= 2;
while (i) {
tree[i] = (tree[i * 2] * tree[i * 2 + 1]) % mod1;
i /= 2;
}
}
};
vector<int> color[n_], A;
int F[n_];
void solve() {
cin >> n >> k >> mod1;
vector<P> v(n), I;
for (int i = 0; i <= k; i++) F[i] = -1;
seg ST(n + 1);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
sort(all(v), greater<>());
for (auto [a, b] : v) {
if (F[b] != -1) {
color[F[b]].push_back(a);
continue;
}
F[b] = k - 1 - I.size();
color[F[b]].push_back(a);
I.push_back({a, F[b]});
}
for (int i = 0; i < n_; i++) sort(all(color[i]));
sort(all(I));
reverse(all(v));
ll idx = 0;
for (auto [a, b] : I) {
A.push_back(a);
while (idx < n && v[idx].first * 2 <= a) {
ST.update(F[v[idx].second], 1);
idx++;
}
ans = (ans + ST.f(0, b)) % mod1;
}
idx = 0;
ll idx2 = 0;
for (int i = 0; i < ST.tree.size(); i++) ST.tree[i] = 1;
for (auto [a, b] : I) {
while (idx < n && v[idx].first * 2 <= a) {
ST.update(F[v[idx].second], 1);
idx++;
}
x = *upper_bound(all(color[b]), a / 2);
auto it = lower_bound(all(A), x * 2);
idx2 = it - A.begin();
ll temp = ST.f(0, b - 1);
temp = (temp * (ST.f(b + 1, idx2 - 1) + mod1 - 1)) % mod1;
ans += temp;
ans %= mod1;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// cin >> tc;
while (tc--) solve();
};
Compilation message
fish.cpp: In constructor 'seg::seg(int)':
fish.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < tree.size(); i++) tree[i] = 1;
| ~~^~~~~~~~~~~~~
fish.cpp: In function 'void solve()':
fish.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < ST.tree.size(); i++) ST.tree[i] = 1;
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12220 KB |
Output is correct |
2 |
Correct |
6 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12124 KB |
Output is correct |
2 |
Correct |
192 ms |
43308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
25244 KB |
Output is correct |
2 |
Correct |
108 ms |
28200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12376 KB |
Output is correct |
2 |
Correct |
7 ms |
12632 KB |
Output is correct |
3 |
Correct |
8 ms |
12328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
31572 KB |
Output is correct |
2 |
Correct |
242 ms |
43764 KB |
Output is correct |
3 |
Correct |
181 ms |
44100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
43480 KB |
Output is correct |
2 |
Correct |
170 ms |
44708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
32080 KB |
Output is correct |
2 |
Correct |
180 ms |
44612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
41680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
45572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
40132 KB |
Output is correct |
2 |
Correct |
161 ms |
49860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
49284 KB |
Output is correct |
2 |
Correct |
183 ms |
39544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
48460 KB |
Output is correct |
2 |
Correct |
269 ms |
49768 KB |
Output is correct |
3 |
Correct |
269 ms |
55480 KB |
Output is correct |
4 |
Correct |
258 ms |
49628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
55756 KB |
Output is correct |
2 |
Correct |
364 ms |
65536 KB |
Output is correct |
3 |
Correct |
276 ms |
65536 KB |
Output is correct |
4 |
Correct |
365 ms |
65536 KB |
Output is correct |