# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030762 |
2024-07-22T09:37:30 Z |
huutuan |
Fish (IOI08_fish) |
C++14 |
|
455 ms |
45392 KB |
#include<bits/stdc++.h>
using namespace std;
int mod;
struct SegmentTree{
int n;
vector<int> t;
void init(int _n){
n=_n;
t.assign(4*n+1, 1);
}
void update(int k, int l, int r, int pos, int val){
if (l==r){
t[k]+=val;
return;
}
int mid=(l+r)>>1;
if (pos<=mid) update(k<<1, l, mid, pos, val);
else update(k<<1|1, mid+1, r, pos, val);
t[k]=t[k<<1]*t[k<<1|1]%mod;
}
int get(int k, int l, int r, int L, int R){
if (r<L || R<l) return 1;
if (L<=l && r<=R) return t[k];
int mid=(l+r)>>1;
return get(k<<1, l, mid, L, R)*get(k<<1|1, mid+1, r, L, R)%mod;
}
} st;
const int N=5e5+10;
int n, m, mx[N], pos[N], b[N];
vector<int> v[N];
pair<int, int> a[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> mod;
for (int i=1; i<=n; ++i) cin >> a[i].first >> a[i].second;
sort(a+1, a+n+1);
for (int i=1; i<=n; ++i) mx[a[i].second]=i, v[a[i].second].push_back(a[i].first);
m=0;
for (int i=1; i<=n; ++i) if (mx[a[i].second]==i){
++m;
pos[a[i].second]=m;
b[m]=a[i].second;
}
st.init(m);
int ans=0;
for (int i=1, j=0; i<=n; ++i){
while (j<n && a[j+1].first*2<=a[i].first){
++j;
st.update(1, 1, m, pos[a[j].second], 1);
}
if (mx[a[i].second]==i){
int p1=1, p2=1;
p1=st.get(1, 1, m, 1, pos[a[i].second]-1);
int cnt=st.get(1, 1, m, pos[a[i].second], pos[a[i].second])-1;
p2=p1;
int l=pos[a[i].second]+1, r=m;
while (l<=r){
int mid=(l+r)>>1;
int cc=upper_bound(v[a[i].second].begin(), v[a[i].second].end(), a[mx[b[mid]]].first/2)-v[a[i].second].begin();
if (cc<=cnt) l=mid+1;
else r=mid-1;
}
p2=p2*st.get(1, 1, m, pos[a[i].second]+1, r)%mod;
p1=p1*cnt%mod;
ans=(ans+p1+p2)%mod;
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
2 |
Correct |
5 ms |
12176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
2 |
Correct |
101 ms |
18464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
14936 KB |
Output is correct |
2 |
Correct |
63 ms |
15432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12120 KB |
Output is correct |
2 |
Incorrect |
7 ms |
12124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
16556 KB |
Output is correct |
2 |
Incorrect |
125 ms |
18396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
18764 KB |
Output is correct |
2 |
Correct |
121 ms |
19284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
16464 KB |
Output is correct |
2 |
Incorrect |
124 ms |
18980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
18976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
20052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
19028 KB |
Output is correct |
2 |
Correct |
166 ms |
23636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
24860 KB |
Output is correct |
2 |
Correct |
211 ms |
23560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
224 ms |
25936 KB |
Output is correct |
2 |
Correct |
234 ms |
23632 KB |
Output is correct |
3 |
Correct |
293 ms |
28872 KB |
Output is correct |
4 |
Correct |
234 ms |
23636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
27988 KB |
Output is correct |
2 |
Correct |
437 ms |
45360 KB |
Output is correct |
3 |
Correct |
378 ms |
45392 KB |
Output is correct |
4 |
Correct |
455 ms |
39508 KB |
Output is correct |