# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1019455 |
2024-07-10T21:23:52 Z |
ttamx |
Fish (IOI08_fish) |
C++17 |
|
269 ms |
27708 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=1e6+5;
const int K=1<<21;
int n,k,mod;
pair<int,int> a[N];
int b[N],ord[N],last[N],nxt[N];
bool ok[N];
int cnt;
ll ans;
struct SegTree{
ll t[N];
void build(int l,int r,int i){
t[i]=1;
if(l==r)return;
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
}
void build(){
build(1,k,1);
}
void update(int l,int r,int i,int x,int v){
if(x<l||r<x)return;
if(l==r)return void(t[i]+=v);
int m=(l+r)/2;
update(l,m,i*2,x,v);
update(m+1,r,i*2+1,x,v);
t[i]=t[i*2]*t[i*2+1]%mod;
}
void update(int x,int v){
update(1,k,1,x,v);
}
ll query(int l,int r,int i,int x,int y){
if(y<l||r<x)return 1;
if(x<=l&&r<=y)return t[i];
int m=(l+r)/2;
return query(l,m,i*2,x,y)*query(m+1,r,i*2+1,x,y)%mod;
}
ll query(int x,int y){
return query(1,k,1,x,y);
}
}seg;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k >> mod;
for(int i=1;i<=n;i++)cin >> a[i].first >> a[i].second;
sort(a+1,a+n+1);
cnt=k;
for(int i=n;i>=1;i--){
auto [l,t]=a[i];
if(!ord[t]){
b[cnt]=l;
ord[t]=cnt;
last[t]=l;
ok[i]=true;
cnt--;
}
nxt[i]=last[t];
last[t]=l;
}
seg.build();
for(int i=1,j=1;i<=n;i++)if(ok[i]){
auto [l,t]=a[i];
while(j<=n&&l>=a[j].first*2){
int x=a[j].second;
seg.update(ord[x],1);
last[x]=nxt[j];
j++;
}
int id=lower_bound(b+1,b+k+1,last[t]*2)-b-1;
ans+=seg.query(1,ord[t]);
ans+=mod+seg.query(1,ord[t]-1)*(seg.query(ord[t]+1,id)-1);
ans%=mod;
assert(0<=ans&&ans<mod);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
98 ms |
6160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2708 KB |
Output is correct |
2 |
Correct |
53 ms |
3240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
3956 KB |
Output is correct |
2 |
Correct |
120 ms |
6224 KB |
Output is correct |
3 |
Correct |
119 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
6740 KB |
Output is correct |
2 |
Correct |
113 ms |
6276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4416 KB |
Output is correct |
2 |
Correct |
118 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
6868 KB |
Output is correct |
2 |
Correct |
124 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
11904 KB |
Output is correct |
2 |
Correct |
163 ms |
14756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
11860 KB |
Output is correct |
2 |
Correct |
193 ms |
17744 KB |
Output is correct |
3 |
Correct |
258 ms |
19792 KB |
Output is correct |
4 |
Correct |
180 ms |
17728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
13392 KB |
Output is correct |
2 |
Incorrect |
269 ms |
27708 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |