This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 5;
int n, k;
int mark[MAXN], x[MAXN];
int mx[MAXN];
bool big[MAXN];
ll res, mod;
pair< int, int> a[MAXN];
vector< int > vec[MAXN];
ll seg[MAXN * 3];
void add(int ind, int val, int b = 0, int e = k, int id = 1){
if(b + 1 == e){
seg[id] += val, seg[id] %= mod;
return;
}
int mid = (b + e)/2;
if(ind < mid)
add(ind, val, b, mid, id*2);
else add(ind, val, mid, e, id*2 + 1);
seg[id] = (seg[id*2] * seg[id*2 + 1])%mod;
}
ll get(int l, int r, int b = 0, int e = k, int id = 1){
if( r <= b || e <= l)
return 1;
if( l <= b && e <= r)
return seg[id];
int mid = (b + e)/2;
return get(l, r, b, mid, id*2) * get(l, r, mid, id*2 + 1) % mod;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k >> mod;
for(int i = 0; i < n; i ++)
cin >> a[i].first >> a[i].second, a[i].second --;
sort(a, a + n);
for(int i = 0; i < k; i ++)
add(i, 1);
int id = k;
for(int i = n - 1; i >= 0; i --){
if( !mark[a[i].second]){
mark[a[i].second] = id;
mx[id] = a[i].first;
vec[id].push_back(a[i].first);
big[i] = true;
id --;
}
else
vec[mark[a[i].second]].push_back(a[i].first);
}
for(int i = 0; i < k; i ++) reverse(vec[i].begin(), vec[i].end());
id = 0;
for(int i = 0; i < n; i ++){
if( !big[i] ) continue;
while(id < i){
if(2*a[id].first > a[i].first)
break;
x[mark[a[id].second]] ++;
add(mark[a[id].second], 1);
id ++;
}
res = (res + get(0, mark[a[i].second] + 1)) % mod;
int it = lower_bound(mx, mx + k, vec[mark[a[i].second]][x[mark[a[i].second]]] * 2) - mx;
res = (res + get(0, mark[a[i].second])*get(mark[a[i].second] + 1, it)%mod)%mod;
}
cout << res << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |