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>
#define st first
#define nd second
using namespace std;
const int N=5e5+5;
int tab[N], czy[N], ile[N];
int m;
int main(){
int n, k;
cin>>n>>k>>m;
for(int i=0; i<k; i++)tab[i]=1;
vector<pair<int, int> > V(n);
for(auto &i:V)cin>>i.st>>i.nd, i.nd--;
sort(V.begin(), V.end());
int wsk=0;
while(V[wsk].st*2<=V.back().st){
tab[V[wsk].nd]++;
ile[V[wsk].nd]++;
wsk++;
}
int ans=0;
for(int i=n-1; i>=0; i--){
if(czy[V[i].nd])continue;
while(wsk && V[wsk-1].st*2>V[i].st){
tab[V[--wsk].nd]--;
}
//for(int j=0; j<k; j++)cout<<tab[j]<<" ";
//cout<<"\n";
int t=1;
for(int j=0; j<k; j++){
if(!czy[j])t=(t*tab[j])%m;
}
ans+=t;
//cout<<t<<" ";
if(i+1-n && tab[V[i].nd]>ile[V[i].nd]){
t=1;
int u=1;
for(int j=0; j<k; j++){
if(j!=V[i].nd && !czy[j])t=(t*tab[j])%m;
if(czy[j])u=(u*tab[j])%m;
}
ans+=(t*(u-1))%m;
//cout<<t*(u-1)<<" ";
}
czy[V[i].nd]=1;
//cout<<"\n";
}
cout<<(ans%m+m)%m;
}
# | 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... |