#include <bits/stdc++.h>
using namespace std;
// trans rights
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
int f, k, MOD;
struct node{
int l, r;
node *lft, *rht;
int val;
node(int tl, int tr): l(tl), r(tr), val(1) {
if (l + 1 == r) {
lft = rht = NULL;
return;
}
lft = new node(l, (l + r) / 2);
rht = new node((l + r) / 2, r);
}
void upd(int x, int tval) {
if (x < l || x >= r) return;
if (l + 1 == r) {
val = tval % MOD;
return;
}
lft->upd(x, tval);
rht->upd(x, tval);
val = (lft->val * rht->val) % MOD;
}
int fnd(int tl, int tr) {
if (tr <= l || r <= tl) return 1;
if (tl <= l && r <= tr) return val;
return (lft->fnd(tl, tr) * rht->fnd(tl, tr)) % MOD;
}
} *root;
int ans;
int maxi[500069], loc[500069];
int chng[500069];
int cnt[500069];
vector<int> vals[500069];
priority_queue<pair<int,int>> pq;
vector<pair<int,int>> ord;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen("fish.in", "r", stdin);
// freopen("fish.out", "w", stdout);
cin>>f>>k>>MOD;
root = new node(0, k);
for (int i = 0; i < f; i++) {
int a, b;
cin>>a>>b; b--;
maxi[b] = max(maxi[b], a);
vals[b].push_back(a);
pq.push({a, b});
}
for (int i = 0; i < k; i++) {
ord.push_back({maxi[i], i});
}
sort(all(ord));
for (int i = 0; i < k; i++) loc[ord[i].s] = i;
for (int i = 0; i < k; i++) {
sort(all(vals[i]));
int t = *upper_bound(all(vals[i]), *vals[i].rbegin() / 2);
chng[loc[i]] = lower_bound(all(ord), make_pair(t * 2, INT_MIN)) - begin(ord);
cnt[loc[i]] = vals[i].size();
root->upd(loc[i], cnt[loc[i]] + 1);
}
for (int i = k - 1; ~i; i--) {
while (pq.size()) {
auto t = pq.top();
if (t.f * 2 <= ord[i].f) break;
pq.pop();
int pos = loc[t.s];
cnt[pos]--;
root->upd(pos, cnt[pos] + 1);
}
root->upd(i, 1);
ans = (ans + root->fnd(0, chng[i])) % MOD;
root->upd(i, cnt[i]);
ans = (ans + root->fnd(0, i + 1)) % MOD;
root->upd(i, cnt[i] + 1);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12060 KB |
Output is correct |
2 |
Correct |
6 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12080 KB |
Output is correct |
2 |
Correct |
164 ms |
24564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
17448 KB |
Output is correct |
2 |
Correct |
82 ms |
19076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12372 KB |
Output is correct |
2 |
Correct |
10 ms |
12372 KB |
Output is correct |
3 |
Correct |
10 ms |
12396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
21736 KB |
Output is correct |
2 |
Correct |
202 ms |
25296 KB |
Output is correct |
3 |
Correct |
179 ms |
26416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
25456 KB |
Output is correct |
2 |
Correct |
189 ms |
26412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
22340 KB |
Output is correct |
2 |
Correct |
209 ms |
26824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
26356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
271 ms |
29136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
30420 KB |
Output is correct |
2 |
Correct |
498 ms |
41360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
607 ms |
47580 KB |
Output is correct |
2 |
Correct |
444 ms |
43708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
428 ms |
46828 KB |
Output is correct |
2 |
Correct |
513 ms |
41356 KB |
Output is correct |
3 |
Correct |
555 ms |
55672 KB |
Output is correct |
4 |
Correct |
486 ms |
41272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
713 ms |
55928 KB |
Output is correct |
2 |
Runtime error |
84 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |