#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 5e5 + 20;
pair<int, int> a[maxn];
vector<int> pos[maxn];
int cnt[maxn];
int tree[maxn];
int id[maxn];
int max_id[maxn];
int mod;
void build(int id, int lt, int rt) {
for (int i = lt; i <= rt; i++) {
tree[i] = cnt[i] % mod;
}
}
void update(int id, int lt, int rt, int pos, int val) {
tree[pos] = val % mod;
}
int get(int id, int lt, int rt, int ql, int qr) {
if (ql > qr) {
return 1;
}
int res = 1;
for (int i = ql; i <= qr; i++) {
res = res * cnt[i] % mod;
}
return res;
}
void just_do_it() {
int n, k;
cin >> n >> k >> mod;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + n + 1);
k = 0;
for (int i = n; i >= 1; i--) {
if (!id[a[i].second]) {
id[a[i].second] = ++k;
}
a[i].second = id[a[i].second];
}
for (int i = 1; i <= n; i++) {
cnt[a[i].second]++;
pos[a[i].second].push_back(i);
}
for (int i = 1; i <= k; i++) {
cnt[i]++;
}
for (int i = n; i >= 1; i--) {
max_id[i] = max(max_id[i + 1], a[i].second);
}
build(1, 1, k);
int lt = n;
int res = 0;
for (int i = n; i >= 1; i--) {
while (lt > 0 && a[lt].first * 2 > a[i].first) {
cnt[a[lt].second]--;
update(1, 1, k, a[lt].second, cnt[a[lt].second]);
lt--;
}
if (max_id[i] != max_id[i + 1]) {
int x = max_id[i];
res += (cnt[x] - 1) % mod * get(1, 1, k, x + 1, k) % mod;
res %= mod;
int low = max_id[lower_bound(a + 1, a + n + 1, make_pair(a[pos[x][cnt[x] - 1]].first * 2, -1)) - a] + 1;
res += get(1, 1, k, low, x - 1) * get(1, 1, k, x + 1, k) % mod;
res %= mod;
}
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12040 KB |
Output is correct |
2 |
Correct |
8 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12140 KB |
Output is correct |
2 |
Correct |
146 ms |
21600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
16832 KB |
Output is correct |
2 |
Correct |
87 ms |
17588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
12220 KB |
Output is correct |
2 |
Correct |
16 ms |
12332 KB |
Output is correct |
3 |
Correct |
25 ms |
12244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
18724 KB |
Output is correct |
2 |
Incorrect |
196 ms |
21556 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
21904 KB |
Output is correct |
2 |
Correct |
207 ms |
22284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
18712 KB |
Output is correct |
2 |
Correct |
506 ms |
21820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1059 ms |
21592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2397 ms |
22732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3022 ms |
20848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3051 ms |
25572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
26328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3048 ms |
27960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |