# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
669747 |
2022-12-07T08:09:47 Z |
Koful123 |
Sails (IOI07_sails) |
C++17 |
|
202 ms |
2668 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 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){
upd(l,1), upd(r + 1,-1);
}
int get(int pos){
int res = 0; for(; pos; pos -= (pos & -pos)){
res += fw[pos];
}
return res;
}
int find(int x,int sz){
int pos = 0;
for(int i = lg; i >= 0; i--){
if(pos + (1 << i) <= sz && fw[pos + (1 << i)] < x){
pos += (1 << i);
x -= fw[pos];
}
}
return pos;
}
};
void solve(){
int n;
cin >> n;
vector<pair<int,int>> v(n);
for(auto &[x,y] : v){
cin >> x >> y;
}
sort(rall(v));
auto check = [&](int m,int ty){
Fenwick fw(v[0].ff);
for(int i = 0; i < n; i++){
int pos = fw.find(m,v[i].ff);
if(pos - v[i].ss + 1 <= 0) return 0ll;
fw.upd(pos - v[i].ss + 1,pos,1);
}
int res = 0;
for(int i = 1; i <= v[0].ff; i++){
res += fw.get(i) * (fw.get(i) - 1) / 2;
assert(fw.get(i) <= m);
}
return (ty ? res : 1ll);
};
int l = 1,r = n;
while(l < r){
int m = (l + r) / 2;
if(check(m,0)) r = m;
else l = m + 1;
}
cout << check(l,1) << 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
1444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
2268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
175 ms |
2536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
202 ms |
2668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |