# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
483080 |
2021-10-27T16:17:27 Z |
blue |
Sails (IOI07_sails) |
C++17 |
|
1000 ms |
13556 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1'000'000'000'000'000'000LL;
struct segtree
{
int l;
int r;
pair<long long, int> v;
long long lp = 0;
segtree* left = NULL;
segtree* right = NULL;
segtree()
{
;
}
segtree(int L, int R)
{
l = L;
r = R;
v = make_pair(0LL, l);
if(l == r) return;
int m = (l+r)/2;
left = new segtree(l, m);
right = new segtree(m+1, r);
}
void add(int L, int R, long long V)
{
if(R < l || r < L) return;
else if(L <= l && r <= R)
{
v.first += V;
lp += V;
}
else
{
left->add(L, R, V);
right->add(L, R, V);
v = min(left->v, right->v);
v.first += lp;
}
}
pair<long long, int> rangemin(int L, int R)
{
if(R < l || r < L) return make_pair(INF, -1);
else if(L <= l && r <= R) return v;
else
{
pair<long long, int> ans = min(left->rangemin(L, R), right->rangemin(L, R));
ans.first += lp;
return ans;
}
}
};
const int mx = 100'000;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector< pair<int, int> > S(N);
for(int i = 0; i < N; i++) cin >> S[i].first >> S[i].second;
sort(S.begin(), S.end());
segtree ST(1, mx);
for(int i = 0; i < N; i++)
{
int occ_lo = 0;
int occ_hi = S[i].first + 1;
// cerr << "\n\n\n";
// cerr << "i = " << i << '\n';
// cerr << S[i].first << ' ' << S[i].second << '\n';
while(S[i].second > 0)
{
pair<long long, int> mn = ST.rangemin(occ_lo+1, occ_hi-1);
int loc = mn.second;
int upd = min(S[i].second, occ_hi - loc);
S[i].second -= upd;
ST.add(loc, loc + upd - 1, +1);
if(loc == occ_lo+1)
occ_lo += upd;
if(loc+upd-1 == occ_hi - 1)
occ_hi -= upd;
// cerr << "adding +1 to " << loc << ' ' << loc + upd - 1 << '\n';
}
}
// cerr << "updating done\n";
long long ans = 0;
for(int h = 1; h <= mx; h++)
{
pair<long long, int> p = ST.rangemin(h, h);
ans += (p.first * (p.first - 1))/2;
// cerr << h << ": " << p.first << "\n";
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
12752 KB |
Output is correct |
2 |
Correct |
23 ms |
12748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12828 KB |
Output is correct |
2 |
Correct |
20 ms |
12828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
12836 KB |
Output is correct |
2 |
Correct |
20 ms |
12836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
12832 KB |
Output is correct |
2 |
Correct |
29 ms |
12748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
12832 KB |
Output is correct |
2 |
Correct |
26 ms |
12748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
12876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
13004 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
13164 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
13380 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
13420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
13556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |