# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104055 |
2024-10-22T15:56:33 Z |
_rain_ |
Fish (IOI08_fish) |
C++14 |
|
54 ms |
65536 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]={};
int b[N+2],c[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;
upd(lef(id),l,m,pos,t);
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);
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
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=0;
for (int i = n; i >= 1; --i){
if (!vis[p[i].gem]) {
last[i] = true;
vis[p[i].gem] = true;
}
}
for (int i = 1; i <= n;++i){
if (last[i]) {
id[p[i].gem]=++cnt;
b[cnt]=p[i].len;
}
bag[p[i].gem].push_back(p[i].len);
}
build(1,1,cnt);
int ans=0;
for (int i = 1 , l = 1; i <= n; ++i){
while (l<=i&&p[l].len*2<=p[i].len){
upd(1,1,cnt,id[p[l].gem],1);
c[p[l].gem]=add(c[p[l].gem],1);
++l;
}
if (last[i]){
int x=p[i].gem;
int l=id[x]+1,r=cnt;
while(l<=r){
int m=l+r>>1;
int lime=upper_bound(bag[x].begin(),bag[x].end(),b[m]/2)-bag[x].begin();
if (lime<=c[x]) l=m+1;
else r=m-1;
}
ans = add(ans,mul(Get(1,1,cnt,1,id[x]-1),add(Get(1,1,cnt,id[x]+1,l-1),c[x])));
}
}
cout<<ans;
exit(0);
}
Compilation message
fish.cpp: In function 'void build(int, int, int)':
fish.cpp:35:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int m=l+r>>1;
| ~^~
fish.cpp: In function 'void upd(int, int, int, int, int)':
fish.cpp:48:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int m=l+r>>1;
| ~^~
fish.cpp: In function 'int Get(int, int, int, int, int)':
fish.cpp:58:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int m=l+r>>1;
| ~^~
fish.cpp: In function 'int32_t main()':
fish.cpp:99:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
99 | int m=l+r>>1;
| ~^~
fish.cpp:65:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:66:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
53 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
49 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
54 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
46 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
51 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
52 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
46 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
45 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
51 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |