# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011313 |
2024-06-30T10:17:57 Z |
kaopj |
Sails (IOI07_sails) |
C++17 |
|
66 ms |
3932 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#define lgm cin.tie(0)->sync_with_stdio(0);
using namespace std;
#define int long long
#define h first
#define k second
pair<int,int> a[100007];
int dem[100007];
int n;
struct fenwick {
int n;
vector<int> t;
fenwick(){}
fenwick(int n):n(n),t(n+7,0){}
void up(int x,int val) {
for(;x<=n;x+=(x&(-x))) t[x]+=val;
}
int get(int x) {
int ans=0;
for(;x;x-=(x&(-x))) ans+=t[x];
return ans;
}
};
signed main() {
lgm;
cin >> n;
for(int i=1;i<=n;i++) {
cin >> a[i].h >> a[i].k;
}
sort(a+1,a+n+1);
fenwick t(a[n].h);
for (int i=1;i<=n;i++) {
int h=a[i].h,k=a[i].k;
int val=t.get(h-k);
int l=1,r=h;
int res=1;
while (l<=r) {
int m=(l+r)>>1;
if (t.get(m)<=val) {
res=m;
r=m-1;
} else {
l=m+1;
}
}
int left=res;
l=1,r=h;
res=h+1;
while (l<=r) {
int m=(l+r)>>1;
if (t.get(m)>=val) {
res=m;
l=m+1;
} else {
r=m-1;
}
}
int right=res;
if (h==k) {
right=0;
}
t.up(right+1,1);
t.up(h+1,-1);
t.up(left,1);
t.up(left+(k-(h-right)),-1);
}
int ans=0;
for(int i=1;i<=a[n].h;i++){
int x=t.get(i);
ans+=(x)*(x-1)/2;
}
cout<<ans;
return 0;
}
# |
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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
856 KB |
Output is correct |
2 |
Correct |
12 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3160 KB |
Output is correct |
2 |
Correct |
42 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
3672 KB |
Output is correct |
2 |
Correct |
39 ms |
3208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
3932 KB |
Output is correct |
2 |
Correct |
35 ms |
3164 KB |
Output is correct |