# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
879692 |
2023-11-27T22:54:21 Z |
OAleksa |
Sails (IOI07_sails) |
C++14 |
|
1000 ms |
41044 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e6 + 69;
int n;
pair<int, int> st[4 * maxn], a[maxn];
void combine(int v) {
auto l1 = st[v * 2];
auto r1 = st[v * 2 + 1];
if (l1.f < r1.f)
st[v] = st[v * 2];
else
st[v] = st[v * 2 + 1];
}
void build(int v, int l, int r) {
if (l == r) {
st[v] = {0, l};
}
else {
int mid = (l + r) / 2;
build(v * 2, l, mid);
build(v * 2 + 1, mid + 1, r);
combine(v);
}
}
void upd(int v, int tl, int tr, int p, int val) {
if (tl == tr) {
st[v].f = val;
}
else {
int mid = (tl + tr) / 2;
if (p <= mid)
upd(v * 2, tl, mid, p, val);
else
upd(v * 2 + 1, mid + 1, tr, p, val);
combine(v);
}
}
pair<int, int> qry(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return {1e9, -1};
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
auto l1 = qry(v * 2, tl, mid, l, r);
auto r1 = qry(v * 2 + 1, mid + 1, tr, l, r);
if (l1.f < r1.f)
return l1;
else
return r1;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i].f >> a[i].s;
build(1, 1, 1e6);
sort(a + 1, a + n + 1);
int ans = 0;
for (int i = 1;i <= n;i++) {
vector<pair<int, int>> x;
while (a[i].s > 0) {
auto r = qry(1, 1, 1e6, 1, a[i].f);
ans += r.f;
x.push_back({r.f, r.s});
upd(1, 1, 1e6, r.s, 1e9);
a[i].s--;
}
for (auto t : x)
upd(1, 1, 1e6, t.s, t.f + 1);
}
cout << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
35164 KB |
Output is correct |
2 |
Correct |
10 ms |
35164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
35164 KB |
Output is correct |
2 |
Correct |
10 ms |
35348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
35164 KB |
Output is correct |
2 |
Correct |
9 ms |
35296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
35356 KB |
Output is correct |
2 |
Correct |
49 ms |
35164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
35724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
35980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
37664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1031 ms |
37712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
41044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
37660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
38044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |