#include <bits/stdc++.h>
using namespace std;
int N,M;
int mod;
int l,h;
vector<pair<int,int>> v;
vector<pair<int,int>> ro;
vector<pair<int,int>> oh;
int mepu[500100];
int total[500100];
bool usable[500100];
int mapping[500100];
bool o[500100];
int iv[500100];
struct node{
int s,e,m;
long long int v;
node *l,*r;
node(int S, int E){
s = S;
e = E;
m = (s + e)/2;
v = 1;
if(s != e){
l = new node(s,m);
r = new node(m + 1, e);
}
}
void update(int i, int k){
if(s == e){
v += k;
v %= mod;
return;
}
if(i <= m){
l -> update(i,k);
}
else{
r -> update(i,k);
}
v = (l -> v * r -> v) % mod;
}
long long int query(int S, int E){
if(E < S) return 1;
if(S <= s && e <= E){
return v;
}
long long int V = 1;
if(S <= m){
V *= l -> query(S,E);
}
if(m < E){
V *= r -> query(S,E);
}
return V % mod;
}
}*root,*lroot;
int main(){
scanf(" %d",&N);
scanf(" %d",&M);
scanf(" %d",&mod);
int next[500100];
for(int i = 1; i <= M; i++){
mepu[i] = -1;
total[i] = 0;
next[i] = -1;
}
for(int i = 0; i <= M; i++) usable[i] = false;
for(int i = 0; i < N; i++){
scanf(" %d",&l);
scanf(" %d",&h);
v.push_back(make_pair(l,h));
}
sort(v.begin(),v.end(),greater<pair<int,int>>());
for(int i = 0; i <= M; i++){
o[i] = true;
}
for(int i = 0; i < v.size(); i++){
if(o[v[i].second]){
oh.push_back(v[i]);
o[v[i].second] = false;
iv[v[i].second] = v[i].first;
}
else if(v[i].first * 2 > iv[v[i].second]){
next[v[i].second] = v[i].first;
}
}
root = new node(0,M);
lroot = new node(0,M);
int it = 0;
int it1 = 0;
ro = oh;
reverse(ro.begin(),ro.end());
for(int i = 0; i < ro.size(); i++){
mapping[ro[i].second] = i;
}
reverse(v.begin(),v.end());
long long int bigans = 0;
/*for(int i = 0; i < N; i++){
total[v[i].second]++;
while(it != N && v[i].first >= v[it].first * 2){
lroot -> update(mapping[v[it].second], 1);
if(usable[v[it].second]){
root -> update(mapping[v[it].second],1);
it++;
}
else{
if(mepu[v[it].second] == -1){
mepu[v[it].second] = 1;
}
else{
mepu[v[it].second]++;
}
it++;
}
}
if(v[i] == oh.back()){
if(mepu[oh.back().second] != -1){
root -> update(mapping[oh.back().second],mepu[oh.back().second] );
}
usable[oh.back().second] = true;
bigans += lroot -> query(0,M - oh.size());
//printf("v: %d %d\n",root -> query(0,M - oh.size()),bigans);
bigans %= mod;
//printf("%d %d\n",next[v[i].second],v[i].first);
if(next[v[i].second] == -1){
pair<int,int> f = *lower_bound(oh.begin(),oh.end(),make_pair(v[i].first * 2 - 1, 1100100100),greater<pair<int,int>>());
//printf("%d %d\n",mapping[v[i].second],mapping[f.second]);
//printf("g: %d\n",(lroot -> query(mapping[v[i].second] + 1, mapping[f.second] ) - 1));
bigans += (lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[f.second] ) - 1);
}
else{
int e = lower_bound(oh.begin(),oh.end(),make_pair(next[v[i].first] * 2 - 1, 1100100100),greater<pair<int,int>>()) -> second;
//printf("%d\n",(lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[e] ) - 1));
bigans += (lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[e] ) - 1);
}
//bigans += lroot -> query(1,v[i].second - 1) * (long long int) lroot -> query(v[i].second + 1, M);
bigans %= mod;
//printf("%d %d %d %d\n",v[i].first,bigans,lroot -> query(1,v[i].second - 1) , (long long int) lroot -> query(v[i].second + 1, M));
oh.pop_back();
}
}*/
printf("%d",bigans);
}
/*
*
5
3
700
8 3
7 2
4 1
2 3
2 2
5
3
7
2 2
5 1
8 3
4 1
2 3
*
*/
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
fish.cpp:124:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int i = 0; i < ro.size(); i++){
| ~~^~~~~~~~~~~
fish.cpp:188:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
188 | printf("%d",bigans);
| ~^ ~~~~~~
| | |
| | long long int
| int
| %lld
fish.cpp:80:6: warning: variable 'next' set but not used [-Wunused-but-set-variable]
80 | int next[500100];
| ^~~~
fish.cpp:117:6: warning: unused variable 'it' [-Wunused-variable]
117 | int it = 0;
| ^~
fish.cpp:118:6: warning: unused variable 'it1' [-Wunused-variable]
118 | int it1 = 0;
| ^~~
fish.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
fish.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf(" %d",&M);
| ~~~~~^~~~~~~~~~
fish.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | scanf(" %d",&mod);
| ~~~~~^~~~~~~~~~~~
fish.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf(" %d",&l);
| ~~~~~^~~~~~~~~~
fish.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | scanf(" %d",&h);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
2444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
4452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
4632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
4572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
136 ms |
6448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
149 ms |
8120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
14516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
153 ms |
41824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
155 ms |
38964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
171 ms |
56352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |