#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 12, MOD = (int)1e9 + 7;
const ll inf = 1e18;
ll res = inf, d[N];
int n, m, s;
struct tr{
ll t, l, r, c;
};
vector<int> T;
vector<tr> a;
set<pair<ll, int>> st, x[N], y[N];
bool del[N];
void ins(int pos, pair<ll, int> val, bool ok, int v = 1, int tl = 1, int tr = s) {
// cout << tl << ' ' << tr << ' ' << ok << '\n';
if(ok) {
x[v].insert(val);
} else {
y[v].insert(val);
}
if(tl == tr) return;
int tm = (tl + tr) >> 1;
if(pos <= tm) ins(pos, val, ok, v + v, tl, tm);
else ins(pos, val, ok, v + v + 1, tm + 1, tr);
}
int pos[N];
void upd(int l, int r, ll val, ll cost, bool ok, int v = 1, int tl = 1, int tr = s) {
if(l > r || tl > r || l > tr) return;
if(tl >= l && tr <= r) {
if(ok) {
while(!x[v].empty()) {
auto [f, i] = (*x[v].begin());
if(f > val) break;
x[v].erase({f, i});
if(!del[i]) {
del[i] = 1;
st.insert({cost + a[i].c, i});
}
}
} else {
while(!y[v].empty()) {
auto [f, i] = (*y[v].begin());
if(f > val) break;
y[v].erase({f, i});
if(!del[i]) {
del[i] = 1;
st.insert({cost + a[i].c, i});
}
}
}
} else {
int tm = (tl + tr) >> 1;
upd(l, r, val, cost, ok, v + v, tl, tm);
upd(l, r, val, cost, ok, v + v + 1, tm + 1, tr);
}
}
void test() {
cin >> n >> m;
a.resize(m);
for(int i = 0; i < m; i++) {
d[i] = inf;
cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
T.push_back(a[i].t);
}
sort(T.begin(), T.end());
T.resize(unique(T.begin(), T.end()) - T.begin());
s = (int)T.size();
for(int i = 0; i < m; i++) {
int j = lower_bound(T.begin(), T.end(), a[i].t) - T.begin() + 1;
pos[i] = j;
if(a[i].l == 1) {
del[i] = 1;
st.insert({a[i].c, i});
} else {
ins(j, {a[i].l - a[i].t, i}, 1);
ins(j, {a[i].l + a[i].t, i}, 0);
}
}
while(!st.empty()) {
auto [w, v] = (*st.begin());
d[v] = w;
st.erase(st.begin());
int j = pos[v];
upd(1, j, a[v].r - a[v].t + 1, d[v], 1);
upd(j, s, a[v].r + a[v].t + 1, d[v], 0);
}
for(int i = 0; i < m; i++) {
if(a[i].r == n) {
res = min(res, d[i]);
}
}
if(res == inf) {
res = -1;
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
40392 KB |
Output is correct |
2 |
Correct |
94 ms |
40396 KB |
Output is correct |
3 |
Correct |
100 ms |
37836 KB |
Output is correct |
4 |
Correct |
102 ms |
37812 KB |
Output is correct |
5 |
Correct |
104 ms |
40140 KB |
Output is correct |
6 |
Correct |
89 ms |
40052 KB |
Output is correct |
7 |
Correct |
92 ms |
40140 KB |
Output is correct |
8 |
Correct |
87 ms |
40044 KB |
Output is correct |
9 |
Correct |
78 ms |
40052 KB |
Output is correct |
10 |
Correct |
65 ms |
40140 KB |
Output is correct |
11 |
Correct |
130 ms |
40148 KB |
Output is correct |
12 |
Correct |
132 ms |
40140 KB |
Output is correct |
13 |
Correct |
121 ms |
40300 KB |
Output is correct |
14 |
Correct |
121 ms |
40140 KB |
Output is correct |
15 |
Correct |
113 ms |
40148 KB |
Output is correct |
16 |
Correct |
108 ms |
40140 KB |
Output is correct |
17 |
Correct |
119 ms |
39464 KB |
Output is correct |
18 |
Correct |
113 ms |
39376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20956 KB |
Output is correct |
2 |
Correct |
3 ms |
20828 KB |
Output is correct |
3 |
Correct |
3 ms |
20816 KB |
Output is correct |
4 |
Correct |
3 ms |
20816 KB |
Output is correct |
5 |
Correct |
5 ms |
20816 KB |
Output is correct |
6 |
Correct |
3 ms |
20816 KB |
Output is correct |
7 |
Correct |
3 ms |
20816 KB |
Output is correct |
8 |
Correct |
4 ms |
20816 KB |
Output is correct |
9 |
Correct |
4 ms |
20948 KB |
Output is correct |
10 |
Correct |
3 ms |
20816 KB |
Output is correct |
11 |
Correct |
3 ms |
20816 KB |
Output is correct |
12 |
Correct |
3 ms |
20816 KB |
Output is correct |
13 |
Correct |
3 ms |
20816 KB |
Output is correct |
14 |
Correct |
4 ms |
20984 KB |
Output is correct |
15 |
Correct |
3 ms |
20816 KB |
Output is correct |
16 |
Correct |
4 ms |
20816 KB |
Output is correct |
17 |
Correct |
4 ms |
20816 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
19 |
Correct |
4 ms |
20816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20956 KB |
Output is correct |
2 |
Correct |
3 ms |
20828 KB |
Output is correct |
3 |
Correct |
3 ms |
20816 KB |
Output is correct |
4 |
Correct |
3 ms |
20816 KB |
Output is correct |
5 |
Correct |
5 ms |
20816 KB |
Output is correct |
6 |
Correct |
3 ms |
20816 KB |
Output is correct |
7 |
Correct |
3 ms |
20816 KB |
Output is correct |
8 |
Correct |
4 ms |
20816 KB |
Output is correct |
9 |
Correct |
4 ms |
20948 KB |
Output is correct |
10 |
Correct |
3 ms |
20816 KB |
Output is correct |
11 |
Correct |
3 ms |
20816 KB |
Output is correct |
12 |
Correct |
3 ms |
20816 KB |
Output is correct |
13 |
Correct |
3 ms |
20816 KB |
Output is correct |
14 |
Correct |
4 ms |
20984 KB |
Output is correct |
15 |
Correct |
3 ms |
20816 KB |
Output is correct |
16 |
Correct |
4 ms |
20816 KB |
Output is correct |
17 |
Correct |
4 ms |
20816 KB |
Output is correct |
18 |
Correct |
4 ms |
20828 KB |
Output is correct |
19 |
Correct |
4 ms |
20816 KB |
Output is correct |
20 |
Correct |
29 ms |
26960 KB |
Output is correct |
21 |
Correct |
26 ms |
26960 KB |
Output is correct |
22 |
Correct |
28 ms |
27216 KB |
Output is correct |
23 |
Correct |
29 ms |
27216 KB |
Output is correct |
24 |
Correct |
32 ms |
27984 KB |
Output is correct |
25 |
Correct |
37 ms |
29264 KB |
Output is correct |
26 |
Correct |
32 ms |
29508 KB |
Output is correct |
27 |
Correct |
33 ms |
29520 KB |
Output is correct |
28 |
Correct |
32 ms |
27984 KB |
Output is correct |
29 |
Correct |
46 ms |
29264 KB |
Output is correct |
30 |
Correct |
31 ms |
29520 KB |
Output is correct |
31 |
Correct |
28 ms |
29520 KB |
Output is correct |
32 |
Correct |
37 ms |
29688 KB |
Output is correct |
33 |
Correct |
38 ms |
29512 KB |
Output is correct |
34 |
Correct |
38 ms |
29084 KB |
Output is correct |
35 |
Correct |
37 ms |
29456 KB |
Output is correct |
36 |
Correct |
36 ms |
29512 KB |
Output is correct |
37 |
Correct |
38 ms |
29020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
40392 KB |
Output is correct |
2 |
Correct |
94 ms |
40396 KB |
Output is correct |
3 |
Correct |
100 ms |
37836 KB |
Output is correct |
4 |
Correct |
102 ms |
37812 KB |
Output is correct |
5 |
Correct |
104 ms |
40140 KB |
Output is correct |
6 |
Correct |
89 ms |
40052 KB |
Output is correct |
7 |
Correct |
92 ms |
40140 KB |
Output is correct |
8 |
Correct |
87 ms |
40044 KB |
Output is correct |
9 |
Correct |
78 ms |
40052 KB |
Output is correct |
10 |
Correct |
65 ms |
40140 KB |
Output is correct |
11 |
Correct |
130 ms |
40148 KB |
Output is correct |
12 |
Correct |
132 ms |
40140 KB |
Output is correct |
13 |
Correct |
121 ms |
40300 KB |
Output is correct |
14 |
Correct |
121 ms |
40140 KB |
Output is correct |
15 |
Correct |
113 ms |
40148 KB |
Output is correct |
16 |
Correct |
108 ms |
40140 KB |
Output is correct |
17 |
Correct |
119 ms |
39464 KB |
Output is correct |
18 |
Correct |
113 ms |
39376 KB |
Output is correct |
19 |
Correct |
3 ms |
20956 KB |
Output is correct |
20 |
Correct |
3 ms |
20828 KB |
Output is correct |
21 |
Correct |
3 ms |
20816 KB |
Output is correct |
22 |
Correct |
3 ms |
20816 KB |
Output is correct |
23 |
Correct |
5 ms |
20816 KB |
Output is correct |
24 |
Correct |
3 ms |
20816 KB |
Output is correct |
25 |
Correct |
3 ms |
20816 KB |
Output is correct |
26 |
Correct |
4 ms |
20816 KB |
Output is correct |
27 |
Correct |
4 ms |
20948 KB |
Output is correct |
28 |
Correct |
3 ms |
20816 KB |
Output is correct |
29 |
Correct |
3 ms |
20816 KB |
Output is correct |
30 |
Correct |
3 ms |
20816 KB |
Output is correct |
31 |
Correct |
3 ms |
20816 KB |
Output is correct |
32 |
Correct |
4 ms |
20984 KB |
Output is correct |
33 |
Correct |
3 ms |
20816 KB |
Output is correct |
34 |
Correct |
4 ms |
20816 KB |
Output is correct |
35 |
Correct |
4 ms |
20816 KB |
Output is correct |
36 |
Correct |
4 ms |
20828 KB |
Output is correct |
37 |
Correct |
4 ms |
20816 KB |
Output is correct |
38 |
Correct |
29 ms |
26960 KB |
Output is correct |
39 |
Correct |
26 ms |
26960 KB |
Output is correct |
40 |
Correct |
28 ms |
27216 KB |
Output is correct |
41 |
Correct |
29 ms |
27216 KB |
Output is correct |
42 |
Correct |
32 ms |
27984 KB |
Output is correct |
43 |
Correct |
37 ms |
29264 KB |
Output is correct |
44 |
Correct |
32 ms |
29508 KB |
Output is correct |
45 |
Correct |
33 ms |
29520 KB |
Output is correct |
46 |
Correct |
32 ms |
27984 KB |
Output is correct |
47 |
Correct |
46 ms |
29264 KB |
Output is correct |
48 |
Correct |
31 ms |
29520 KB |
Output is correct |
49 |
Correct |
28 ms |
29520 KB |
Output is correct |
50 |
Correct |
37 ms |
29688 KB |
Output is correct |
51 |
Correct |
38 ms |
29512 KB |
Output is correct |
52 |
Correct |
38 ms |
29084 KB |
Output is correct |
53 |
Correct |
37 ms |
29456 KB |
Output is correct |
54 |
Correct |
36 ms |
29512 KB |
Output is correct |
55 |
Correct |
38 ms |
29020 KB |
Output is correct |
56 |
Correct |
1250 ms |
185500 KB |
Output is correct |
57 |
Correct |
1273 ms |
185816 KB |
Output is correct |
58 |
Correct |
1554 ms |
235084 KB |
Output is correct |
59 |
Correct |
1577 ms |
235248 KB |
Output is correct |
60 |
Correct |
1292 ms |
207704 KB |
Output is correct |
61 |
Correct |
1321 ms |
234952 KB |
Output is correct |
62 |
Correct |
1256 ms |
185280 KB |
Output is correct |
63 |
Runtime error |
74 ms |
52752 KB |
Execution killed with signal 11 |
64 |
Halted |
0 ms |
0 KB |
- |