#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vll>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 23;
const int off = 1 << logo;
const int trsz = off << 1;
vii arr;
int gdid[MAXN];
int seg[trsz];
void update(int x, int val){
x += off;
seg[x] = (seg[x] + val + mod) % mod;
x /= 2;
for(; x; x /= 2) seg[x] = ((ll)seg[x * 2] * (ll)seg[x * 2 + 1]) % mod;
}
ll query(int x, int lo, int hi, int a, int b){
if(lo >= b or hi <= a) return 1;
if(lo >= a and hi <= b) return seg[x];
int mid = (lo + hi) / 2;
return ((ll)query(x * 2, lo, mid, a, b) * (ll)query(x * 2 + 1, mid, hi, a, b)) % mod;
}
vi c;
vpll boje;
int pos[MAXN];
int kol[MAXN];
vi siz[MAXN];
void solve(){
fill(seg, seg + trsz, 1);
fill(gdid, gdid + MAXN - 1, -1);
int n, k, m;
cin >> n >> k >> mod;
arr.resize(n);
REP(i, n) cin >> arr[i].X >> arr[i].Y;
sort(all(arr));
for(int i = n - 1; i >= 0; i--){
siz[arr[i].Y].PB(arr[i].X);
if(gdid[arr[i].Y] == -1) gdid[arr[i].Y] = i, c.PB(arr[i].Y), boje.PB({arr[i].X, i});
}
reverse(all(c));
for(int i=0; i<c.size(); i++) pos[c[i]] = i, reverse(all(siz[c[i]]));
for(int i=0; i<n; i++) update(pos[arr[i].Y], 1);
sort(all(boje));
boje.PB({INF, inf});
//for(auto &x : boje) cout << x.Y << " ";
//cout << "\n";
//cout << "\nSORT\n";
//for(auto &x : arr) cout << x.X << " " << x.Y << "\n";
int ans = 0;
int R = n - 1;
for(int i = n - 1; i >= 0; i--){
while(R >= 0 and arr[R].X * 2 > arr[i].X) update(pos[arr[R].Y], -1), R--;
if(gdid[arr[i].Y] != i) continue;
if(i == n - 1){
REP(i, k + 1) kol[i] = seg[i + off];
}
//cout << i << " " << R << " " << arr[i].X << " " << arr[i].Y << " " << ans << " -> ";
ans = (ans + query(1, 0, off, 0, pos[arr[i].Y] + 1)) % mod;
//cout << ans << " -> ";
int prv = *lower_bound(all(siz[arr[i].Y]), arr[i].X / 2 + 1);
//if(i != n - 1) cout << "PRVI VECI " << prv << "\n";
int poz = lower_bound(all(boje), MP((ll)prv * 2, (ll)-inf)) - boje.begin();
if(pos[arr[i].Y] + 1 < poz){
//cout << i << " " << "ja\n" << "\n";
//cout << "USO\n";
//cout << "\n";
///cout << pos[arr[i].Y] + 1 << " " << poz << " " << seg[pos[arr[i].Y] + 1 + off] << " " << query(1, 0, off, pos[arr[i].Y] + 1, poz) << " ->";
//cout << "\n";
int val = ((ll)query(1, 0, off, 0, pos[arr[i].Y]) * (ll)(((ll)query(1, 0, off, pos[arr[i].Y] + 1, poz) - 1 + mod) % mod)) % mod;
ans = (ans + val) % mod;
}
//cout << ans << "\n";
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin >> t;
while(t--)solve();
return 0;
}
Compilation message
fish.cpp: In function 'void solve()':
fish.cpp:93:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i=0; i<c.size(); i++) pos[c[i]] = i, reverse(all(siz[c[i]]));
| ~^~~~~~~~~
fish.cpp:82:12: warning: unused variable 'm' [-Wunused-variable]
82 | int n, k, m;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
30 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
30 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
37 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
31 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
40 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
37 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
32 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |