# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103786 |
2024-10-21T17:24:13 Z |
_rain_ |
Fish (IOI08_fish) |
C++14 |
|
239 ms |
32596 KB |
#include<bits/stdc++.h>
using namespace std;
#define name "main"
typedef long long ll;
const int N = (int)5e5;
struct Node{
int len;
int gem;
bool operator < (const Node& other) const{
return len < other.len;
}
} p[N+2];
int n,k,MOD;
int add(int a , int b){
return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a,int b){
return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b){
return (ll)a*b%MOD;
}
int id[N+2];
bool last[N+2]={},vis[N+2]={};
vector<int> bag[N+2];
int st[N*4+2];
#define lef(id) id*2
#define rig(id) id*2+1
void build(int id,int l,int r){
if (l==r) st[id]=1;
else{
int m=l+r>>1;
build(lef(id),l,m);
build(rig(id),m+1,r);
st[id]=1;
}
return;
}
void upd(int id,int l,int r,int pos,int t){
if (l>pos||r<pos) return;
if (l==r){
st[id] = add(st[id],t);
}
else{
int m=l+r>>1;
if (l<=m) upd(lef(id),l,m,pos,t);
if (m<r) upd(rig(id),m+1,r,pos,t);
st[id]=mul(st[lef(id)],st[rig(id)]);
}
return;
}
int Get(int id,int l,int r,int u,int v){
if (l>v||r<u) return 1;
if (u<=l&&r<=v) return st[id];
int m=l+r>>1;
return mul(Get(lef(id),l,m,u,v),Get(rig(id),m+1,r,u,v));
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k>>MOD;
for (int i = 1; i <= n; ++i){
cin>>p[i].len>>p[i].gem;
}
sort(p+1,p+n+1);
int cnt=n;
for (int i = n; i >= 1; --i){
if (!vis[p[i].gem]) {
id[p[i].gem] = cnt--;
vis[p[i].gem] = true;
last[i] = true;
}
}
build(1,1,n);
int ans=0;
// cout<<"(DEBUG)\n";
// for (int i=1;i<=n;++i) cout << p[i].len << ' ' << p[i].gem << ' ' << id[p[i].gem] << '\n';
// cout<<"(END-DEBUGGING)\n";
for (int i = 1 , l = 1; i <= n; ++i){
while (l <= i && p[l].len * 2 <= p[i].len){
upd(1,1,n,id[p[l].gem],1);
++l;
}
if (last[i]) ans=add(ans,Get(1,1,n,1,id[p[i].gem]));
}
cout<<ans;
exit(0);
}
Compilation message
fish.cpp: In function 'void build(int, int, int)':
fish.cpp:34:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int m=l+r>>1;
| ~^~
fish.cpp: In function 'void upd(int, int, int, int, int)':
fish.cpp:47:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int m=l+r>>1;
| ~^~
fish.cpp: In function 'int Get(int, int, int, int, int)':
fish.cpp:57:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
57 | int m=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
16844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
17048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16720 KB |
Output is correct |
2 |
Incorrect |
4 ms |
16720 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16888 KB |
Output is correct |
2 |
Incorrect |
170 ms |
30796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
23516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16720 KB |
Output is correct |
2 |
Correct |
6 ms |
16976 KB |
Output is correct |
3 |
Incorrect |
5 ms |
16720 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
105 ms |
27072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
188 ms |
30792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
27464 KB |
Output is correct |
2 |
Incorrect |
171 ms |
31592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
152 ms |
30556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
156 ms |
32072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
30164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
179 ms |
31312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
29512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
239 ms |
32596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |