# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670364 |
2022-12-08T18:28:19 Z |
Koful123 |
Sails (IOI07_sails) |
C++17 |
|
80 ms |
3184 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int N = (int) 2e5 + 5,lg = 20;
struct Fenwick{
int n; vector<int> fw;
Fenwick(int _n){
fw.assign((n = _n) + 1,0);
};
void upd(int pos,int x){
for(; pos <= n; pos += (pos & -pos)){
fw[pos] += x;
}
}
void upd(int l,int r,int x){
if(l > r) return;
upd(l,1), upd(r + 1,-1);
// cout << l << ' ' << r << endl;
}
int get(int pos){
int res = 0; for(; pos; pos -= (pos & -pos)){
res += fw[pos];
}
return res;
}
void find(int sz,int k,int end){
int val = get(sz),l = 1,r = sz;
while(l < r){
int m = (l + r) / 2;
if(get(m) == val) r = m;
else l = m + 1;
}
int pre = l; l = sz,r = end;
while(l < r){
int m = (l + r + 1) / 2;
if(get(m) == val) l = m;
else r = m - 1;
}
upd(pre,pre + (l - sz),1);
upd(l + 1,l + k - (l - sz + 1),1);
}
};
void solve(){
int n;
cin >> n;
vector<pair<int,int>> v(n);
for(auto &[x,y] : v){
cin >> x >> y;
}
sort(all(v)); Fenwick fw(v[n-1].ff);
for(int i = 0; i < n; i++){
fw.find(v[i].ff - v[i].ss + 1,v[i].ss,v[i].ff);
}
int res = 0;
for(int i = 1; i <= v[n-1].ff; i++){
res += fw.get(i) * (fw.get(i) - 1) / 2;
}
cout << res << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
724 KB |
Output is correct |
2 |
Correct |
17 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
2528 KB |
Output is correct |
2 |
Correct |
63 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
2760 KB |
Output is correct |
2 |
Correct |
44 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
2924 KB |
Output is correct |
2 |
Correct |
50 ms |
3068 KB |
Output is correct |