#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 update(int id, int lt, int rt, int pos, int val) {
tree[pos] = val;
}
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);
}
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(a[lt].second, cnt[a[lt].second]);
lt--;
}
if (max_id[i] != max_id[i + 1]) {
int x = max_id[i];
int prod = cnt[x] - 1;
for (int j = x; j <= k; j++) {
if (j != x) {
prod = prod * (cnt[j] % mod) % mod;
}
}
res += prod;
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;
prod = 1;
for (int j = low; j <= k; j++) {
if (j != x) {
prod = prod * (cnt[j] % mod) % mod;
}
}
res += prod;
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 |
11988 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 |
12100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
2 |
Correct |
7 ms |
12008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12016 KB |
Output is correct |
2 |
Correct |
134 ms |
20856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
16064 KB |
Output is correct |
2 |
Correct |
86 ms |
16892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
12116 KB |
Output is correct |
2 |
Correct |
22 ms |
12280 KB |
Output is correct |
3 |
Correct |
44 ms |
12248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
17952 KB |
Output is correct |
2 |
Correct |
229 ms |
20664 KB |
Output is correct |
3 |
Correct |
222 ms |
22404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
21180 KB |
Output is correct |
2 |
Correct |
243 ms |
21552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
17908 KB |
Output is correct |
2 |
Correct |
805 ms |
21160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1902 ms |
20736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3042 ms |
21884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3051 ms |
19768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3016 ms |
24148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3055 ms |
25076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3057 ms |
26368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |