이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;
struct fish {
int len, col;
bool operator < (const fish &a) const {
return len<a.len;
}
} F[MX];
int n,k,mod;
struct seg {
static const int MX=1100000;
int n, tree[MX];
void init(int sz){
n=sz;
for(int i=1; i<MX; i++) tree[i]=1;
}
void upt(int v, int s, int e, int pos, int val){
if(pos<s || e<pos) return;
if(s==e){
tree[v]+=val;
return;
}
upt(v*2,s,(s+e)/2,pos,val);
upt(v*2+1,(s+e)/2+1,e,pos,val);
tree[v]=tree[v*2]*tree[v*2+1]%mod;
}
void upt(int pos, int val){
upt(1,1,n,pos,val);
}
int prod(int v, int s, int e, int l, int r){
if(r<s || e<l) return 1;
if(l<=s && e<=r) return tree[v];
return prod(v*2,s,(s+e)/2,l,r) * prod(v*2+1,(s+e)/2+1,e,l,r) % mod;
}
int prod(int l, int r){
if(r<l) return 1;
return prod(1,1,n,l,r);
}
} Tree;
int solve(){
int last[MX];
fill(last+1, last+k+1, 0);
for(int i=1; i<=n; i++){
last[F[i].col]=i;
}
bool calc[MX]={};
for(int i=1; i<=k; i++){
int x=last[i];
if(F[x].len*2<=F[n].len) continue;
calc[last[i]]=true;
}
int ans=0;
int cnt[MX]={};
Tree.init(k);
for(int i=1, pos=0; i<=n; i++){
if(!calc[i]) continue;
int c=F[i].col;
while(pos<n && F[pos+1].len*2<=F[i].len){
pos++;
cnt[F[pos].col]++;
// Tree.upt(F[pos].col,1);
}
if(i==n) cnt[c]++;
int now=1;
for(int j=1; j<=k; j++){
if(i!=n && j==c) continue;
now=(now*(cnt[j]+1))%mod;
}
if(i==n) now=(now+mod-1)%mod;
/*
if(i==n) now=(Tree.prod(1,k)+mod-1)%mod;
else now=Tree.prod(1,c-1) * Tree.prod(c+1, k) % mod;
*/
// cout<<i<<' '<<F[i].len<<' '<<F[i].col<<": "<<now<<'\n';
ans=(ans+now)%mod;
}
return ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>k>>mod;
for(int i=1; i<=n; i++)
cin>>F[i].len>>F[i].col;
sort(F+1, F+n+1);
cout<<solve();
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... |