#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1e6+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 22;
const int off = 1 << logo;
const int treesiz = off << 1;
int n, k, m;
pair<int, int> niz[maxn];
int cnt[maxn];
int tour[treesiz];
bool bio[maxn];
int id[maxn], fir[maxn];
int nex[maxn], las[maxn];
vector< int > v[maxn];
int mul(int a, int b) {
a %= m, b %= m;
return (a * b) % m;
}
void update(int x, int val) {
x += off;
tour[x] += val;
x /= 2;
while (x > 0) tour[x] = mul(tour[x * 2], tour[x * 2 + 1]), x /= 2;
}
int query(int a, int b, int l, int r, int node) {
if (l > b || r < a) return 1;
if (l >= a && r <= b) return tour[node];
int mid = (l + r) / 2;
return mul(query(a, b, l, mid, node * 2), query(a, b, mid + 1, r, node * 2 + 1));
}
int main() {
scanf("%d%d%d", &n, &k, &m);
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
niz[i] = {a, b};
}
sort(niz, niz+n);
reverse(niz, niz+n);
int cnt = 1;
for (int i = 0; i < n; i++) {
int col = niz[i].Y;
if (bio[col]) continue;
bio[col] = true;
fir[cnt] = i;
id[col] = cnt++;
}
for (int i = 0; i < n; i++)
niz[i].Y = id[niz[i].Y];
for (int i = 0; i < n; i++)
v[niz[i].Y].push_back(i);
for (int i = 1; i <= k; i++) {
nex[fir[i]] = n;
for (int tren : v[i]) {
if (niz[tren].X * 2 > niz[fir[i]].X) {
nex[fir[i]] = tren;
break;
}
}
}
for (int i = 0; i < treesiz; i++) tour[i] = 1;
for (int i = 0; i < n; i++) update(niz[i].Y, 1);
int sol = 0;
int ptr = 0;
memset(bio, false, sizeof bio);
for (int i = 0; i < n; i++) {
int len = niz[i].X;
int col = niz[i].Y;
if (bio[col]) continue;
bio[col] = true;
while (ptr < n && niz[ptr].X * 2 > niz[i].X)
update(niz[ptr++].Y, -1);
//printf("debug: %d %d (%d) --> %d\n", len, col, i, ptr);
//for (int i = 1; i <= k; i++) printf("%d ", tour[i + off]); printf("\n");
update(col, -1);
sol += query(col, k + 1, 0, off - 1, 1);
update(col, 1);
sol %= m;
int lo = 0, hi = col;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
if (niz[fir[mid]].X >= 2 * niz[nex[i]].X) lo = mid;
else hi = mid - 1;
}
//printf("found: %d\n", lo);
sol += mul(query(lo + 1, col - 1, 0, off - 1, 1), query(col + 1, k + 1, 0, off - 1, 1));
sol %= m;
}
printf("%d\n", sol);
return 0;
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:86:7: warning: unused variable 'len' [-Wunused-variable]
86 | int len = niz[i].X;
| ^~~
fish.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d%d", &n, &k, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
57548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
57536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
57632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
57620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
57548 KB |
Output is correct |
2 |
Incorrect |
28 ms |
57544 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
57608 KB |
Output is correct |
2 |
Incorrect |
386 ms |
64220 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
57592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
57612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
201 ms |
60692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
57684 KB |
Output is correct |
2 |
Incorrect |
34 ms |
57684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
242 ms |
62096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
452 ms |
64944 KB |
Output is correct |
2 |
Incorrect |
399 ms |
64712 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
295 ms |
63052 KB |
Output is correct |
2 |
Incorrect |
421 ms |
64612 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
406 ms |
64652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
339 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
483 ms |
63992 KB |
Output is correct |
2 |
Runtime error |
181 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
178 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
164 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
201 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |