# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
514936 |
2022-01-18T20:32:48 Z |
kevin |
Sails (IOI07_sails) |
C++17 |
|
82 ms |
1484 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
#define nl cout<<"\n"
const int MAXN = 5e5 + 5;
struct BIT {
vector<int> f;
int n;
void init(int N) { f = vector<int>(N+1, 0); n = N;}
int lsb(int x) { return x & -x; }
void update(int p, int v){
while(p <= n){ f[p] += v; p += lsb(p); }
}
int query(int p) {
int sum = 0;
while (p > 0) { sum += f[p]; p -= lsb(p); }
return sum;
}
};
int findup(BIT &bit, int x, int r){
int l = 1;
int a = r;
while(l <= r){
int m = (l + r) / 2;
if(bit.query(m) >= x) { a = m; l = m+1; }
else r = m-1;
}
return a;
}
int finddn(BIT &bit, int x, int r){
int l = 1;
int a = 1;
while(l <= r){
int m = (l + r) / 2;
if(bit.query(m) <= x) { a = m; r = m-1; }
else l = m+1;
}
return a;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<pair<int, int>> ar;
for(int i=0; i<n; i++){
int h, k; cin>>h>>k;
ar.push_back({h, k});
}
BIT bit; bit.init(100005);
sort(ar.begin(), ar.end());
for(int i=0; i<n; i++){
int x = bit.query(ar[i].f - ar[i].s + 1);
int l = finddn(bit, x, ar[i].f);
int r = findup(bit, x, ar[i].f);
bit.update(r+1, 1);
bit.update(ar[i].f+1, -1);
bit.update(l, 1);
bit.update(l + ar[i].s - (ar[i].f-r), -1);
}
ll tot = 0;
for(int i=1; i<=100000; i++){
int x = bit.query(i);
tot += (ll)x * (x-1) / 2;
}
cout<<tot;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
716 KB |
Output is correct |
2 |
Correct |
18 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
1484 KB |
Output is correct |
2 |
Correct |
55 ms |
1396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
1484 KB |
Output is correct |
2 |
Correct |
57 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
1484 KB |
Output is correct |
2 |
Correct |
59 ms |
1452 KB |
Output is correct |