# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
683233 |
2023-01-18T01:29:43 Z |
Hacv16 |
Sails (IOI07_sails) |
C++17 |
|
154 ms |
4584 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 15;
const int INF = 0x3f3f3f3f;
struct Node{
int f, lzsum;
Node(int a = 0, int b = 0){
f = a, lzsum = b;
}
Node operator + (Node other){
if(f < other.f) return (*this);
return other;
}
};
int n, fim;
vector<pair<int, int>> v;
Node seg[4 * MAX];
void build(int p, int l, int r){
if(l == r){
seg[p].f = 0;
seg[p].lzsum = 0;
return;
}
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
build(e, l, m); build(d, m + 1, r);
seg[p] = seg[e] + seg[d];
}
void refresh(int p, int l, int r){
if(seg[p].lzsum == 0) return;
int add = seg[p].lzsum;
seg[p].f += add;
seg[p].lzsum = 0;
if(l == r) return;
int e = 2 * p, d = e + 1;
seg[e].lzsum += add;
seg[d].lzsum += 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){
seg[p].lzsum += 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] = seg[e] + seg[d];
}
Node query(int a, int b, int p, int l, int r){
refresh(p, l, r);
if(a > r || b < l) return Node(INF, 0);
if(a <= l && r <= b) return seg[p];
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
return 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
if(l == r) return l;
refresh(p, l, r);
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
if(seg[e].f < 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
if(l == r) return l;
refresh(p, l, r);
int m = (l + r) >> 1, e = 2 * p, d = e + 1;
if(seg[e].f <= 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).f;
if(seg[1].f < val){
int pos = bb(val, 1, 1, fim);
if(pos <= h){
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';
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++){
int h, k; cin >> h >> k;
v.emplace_back(h, k);
fim = max(fim, h);
}
build(1, 1, fim);
sort(v.begin(), v.end());
for(auto p : v){ add(p.first, p.second); }
ll ans = 0;
for(int i = 1; i <= fim; i++){
ll cur = query(i, i, 1, 1, fim).f;
ans += (cur * (cur - 1)) / 2;
}
cout << ans << '\n';
exit(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
3540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
3800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
4056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
4564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
4552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
154 ms |
4584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |