# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
683236 |
2023-01-18T02:04:01 Z |
Hacv16 |
Sails (IOI07_sails) |
C++17 |
|
144 ms |
6028 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
typedef long long ll;
const int MAX = 2e5 + 15;
const int INF = 1e18 + 10;
int n, fim, seg[4 * MAX], lzsum[4 * MAX];
vector<pair<int, int>> v;
void refresh(int p, int l, int r){
if(lzsum[p] == 0) return;
int add = lzsum[p];
seg[p] += add;
lzsum[p] = 0;
if(l == r) return;
int e = 2 * p, d = e + 1;
lzsum[e] += add;
lzsum[d] += add;
}
void update(int a, int b, int x, int p, int l, int r){
refresh(p, l, r);
if(a > r || b < l) return;
if(a <= l && r <= b){
lzsum[p] += x;
refresh(p, l, r);
return;
}
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
update(a, b, x, e, l, m);
update(a, b, x, d, m + 1, r);
seg[p] = min(seg[e], seg[d]);
}
int query(int a, int b, int p, int l, int r){
refresh(p, l, r);
if(a > r || b < l) return INF;
if(a <= l && r <= b) return seg[p];
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
return min(query(a, b, e, l, m), query(a, b, d, m + 1, r));
}
int bb(int x, int p, int l, int r){ //first lower
refresh(p, l, r);
if(l == r) return l;
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
if(seg[e] < x) return bb(x, e, l, m);
return bb(x, d, m + 1, r);
}
int eq(int x, int p, int l, int r){ //first equal
refresh(p, l, r);
if(l == r) return l;
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
if(seg[e] <= x) return eq(x, e, l, m);
return eq(x, d, m + 1, r);
}
void add(int h, int k){
int val = query(h - k + 1, h - k + 1, 1, 1, fim);
if(seg[1] < val){ //atualiza "topo" - "prefixo"
int pos = bb(val, 1, 1, fim);
if(pos <= h){ //atualiza "bottom" - "sufixo"
update(pos, h, 1, 1, 1, fim);
//cerr << "ADDED IN INTERVAL " << pos << ' ' << h << '\n';
k -= h - pos + 1;
}
}
int t = eq(val, 1, 1, fim);
update(t, t + k - 1, 1, 1, 1, fim);
//cerr << "ADDED IN INTERVAL " << t << ' ' << t + k - 1 << '\n';
}
int32_t main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++){
int h, k; cin >> h >> k;
v.push_back({h, k});
fim = max(fim, h);
}
sort(v.begin(), v.end());
for(auto p : v){ add(p.first, p.second); }
int ans = 0;
for(int i = 1; i <= fim; i++){
int cur = query(i, i, 1, 1, fim);
ans += (cur * (cur - 1)) >> 1;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
1856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
3304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
5860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
6008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
144 ms |
6028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |