#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, m;
const ll inf = 1e17 + 5;
const int nmax = 3e5 + 33;
#define left deobiceicineintreabasussy
#define right deobiceicineintreababaka
mt19937 rng(time(0));
struct Treap {
struct node {
int pri;
ll mn, val;
int area;
node *l, *r;
int ind() {
return l -> area + 1;
}
} *nil = new node{-1, inf, inf, 0, 0, 0};
using ns = node*;
struct pns {
ns l, r;
};
ns updnode(ns nde, ns x, int val) {
(val? nde -> r : nde -> l) = x;
nde -> area = nde -> l -> area + nde -> r -> area + 1;
nde -> mn = min({nde -> l -> mn, nde -> r -> mn, nde -> val});
return nde;
}
ns merge(ns l, ns r) {
return l == nil? r:
r == nil? l:
l -> pri > r -> pri? updnode(l, merge(l -> r, r), 1):
updnode(r, merge(l, r -> l), 0);
}
pns split(ns x, int val) {
pns temp;
return val == 0? pns{nil, x}:
x -> area <= val? pns{x, nil}:
x -> ind() <= val? (temp = split(x -> r, val - x -> ind()), temp.l = updnode(x, temp.l, 1), temp):
(temp = split(x -> l, val), temp.r = updnode(x, temp.r, 0), temp);
}
ns root = nil;
void append() {
root = merge(root, new node{abs((int)rng()), inf, inf, 1, nil, nil});
}
ll query(int l, int r) {
pns temp[2] = {split(root, l - 1), split(temp[0].r, r - l + 1)};
ll rez = temp[1].l -> mn;
root = merge(temp[0].l, merge(temp[1].l, temp[1].r));
return rez;
}
void upd(int poz, ll val) {
pns temp[2] = {split(root, poz - 1), split(temp[0].r, 1)};
temp[1].l -> val = min(temp[1].l -> val, val);
temp[1].l -> mn = temp[1].l -> val;
root = merge(temp[0].l, merge(temp[1].l, temp[1].r));
return;
}
};
Treap left, right;
#define norm deobiceicineintreaba
map<int,int> norm;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> m >> n;
vector<tuple<int,int,int,ll> > v(m);
for(auto &[a, b, c, d] : v) {
cin >> a >> b >> c >> d;
norm[a];
norm[b];
norm[c];
}
norm[1];
norm[n];
int cnt = 1;
for(auto &x : norm)
x.second = cnt++;
n = cnt - 1;
for(int i = 1; i <= n; i++) {
left.append();
right.append();
}
left.upd(1, 0);
right.upd(n, 0);
ll minn = inf;
bool ok = 0;
for(auto [a, b, c, d] : v) {
a = norm[a];
b = norm[b];
c = norm[c];
ll l = left.query(a, b), r = right.query(a, b);
//cout << l << ' ' << r << '\n';
if(minn > l + r + d)
minn = l + r + d, ok = 1;
left.upd(c, l + d);
right.upd(c, r + d);
}
if(!ok)
cout << -1 << '\n';
else
cout << minn << '\n';
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:73:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
73 | for(auto &[a, b, c, d] : v) {
| ^
pinball.cpp:93:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
93 | for(auto [a, b, c, d] : v) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
716 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
824 KB |
Output is correct |
23 |
Correct |
3 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
716 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
4 ms |
824 KB |
Output is correct |
23 |
Correct |
3 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
50 ms |
3508 KB |
Output is correct |
26 |
Correct |
195 ms |
10472 KB |
Output is correct |
27 |
Correct |
582 ms |
19328 KB |
Output is correct |
28 |
Correct |
245 ms |
2864 KB |
Output is correct |
29 |
Correct |
411 ms |
17176 KB |
Output is correct |
30 |
Correct |
443 ms |
5668 KB |
Output is correct |
31 |
Execution timed out |
1049 ms |
31508 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |