#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
const int INF = 1e9;
const int MX = 1e5 + 5;
int N, M;
int T[MX], L[MX], R[MX], C[MX], U[MX];
vector<int> cp;
priority_queue<pli> st[MX];
vector<int> v;
void upd(int t, int x) {
while (t<=cp.size())
st[t].em(-(L[x]+T[x]), x), t+=t&-t;
}
void get(int t, int x) {
while (t) {
while (st[t].size()&&-st[t].top().fi<=x)
v.eb(st[t].top().se),
st[t].pop();
t-=t&-t;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin>>N>>M;
for (int i=1; i<=M; i++)
cin>>T[i]>>L[i]>>R[i]>>C[i],
cp.eb(L[i]-T[i]);
sort(cp.begin(), cp.end());
cp.resize(unique(cp.begin(), cp.end())-cp.begin());
for (int i=1; i<=M; i++)
upd(lower_bound(cp.begin(), cp.end(), L[i]-T[i])-cp.begin()+1, i);
priority_queue<pli> pq;
for (int i=1; i<=M; i++) if (L[i]==1)
pq.em(-C[i], i),
U[i]=1;
while (pq.size()) {
auto k=pq.top();
pq.pop();
int n=k.se;
if (R[n]==N) {
cout<<-k.fi<<'\n';
return 0;
}
v.clear();
get(upper_bound(cp.begin(), cp.end(), R[n]-T[n]+1)-cp.begin(), R[n]+T[n]+1);
for (auto &i:v) if (!U[i]) {
U[i]=1;
pq.em(k.fi-C[i], i);
}
}
cout<<"-1\n";
return 0;
}
Compilation message
treatment.cpp: In function 'void upd(int, int)':
treatment.cpp:21:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | while (t<=cp.size())
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
277 ms |
25072 KB |
Output is correct |
2 |
Correct |
209 ms |
24688 KB |
Output is correct |
3 |
Correct |
260 ms |
28264 KB |
Output is correct |
4 |
Correct |
261 ms |
28520 KB |
Output is correct |
5 |
Correct |
119 ms |
18028 KB |
Output is correct |
6 |
Correct |
143 ms |
18800 KB |
Output is correct |
7 |
Correct |
171 ms |
24936 KB |
Output is correct |
8 |
Correct |
78 ms |
14960 KB |
Output is correct |
9 |
Correct |
77 ms |
18160 KB |
Output is correct |
10 |
Correct |
96 ms |
23720 KB |
Output is correct |
11 |
Correct |
193 ms |
28632 KB |
Output is correct |
12 |
Correct |
230 ms |
28444 KB |
Output is correct |
13 |
Correct |
257 ms |
28264 KB |
Output is correct |
14 |
Correct |
251 ms |
28132 KB |
Output is correct |
15 |
Correct |
268 ms |
26352 KB |
Output is correct |
16 |
Correct |
265 ms |
25712 KB |
Output is correct |
17 |
Correct |
263 ms |
25200 KB |
Output is correct |
18 |
Correct |
194 ms |
28132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
3 ms |
3456 KB |
Output is correct |
5 |
Correct |
2 ms |
3456 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
3 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3456 KB |
Output is correct |
13 |
Correct |
3 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
3 ms |
3456 KB |
Output is correct |
16 |
Correct |
3 ms |
3456 KB |
Output is correct |
17 |
Correct |
3 ms |
3456 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
3 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
3 ms |
3456 KB |
Output is correct |
5 |
Correct |
2 ms |
3456 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
3 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3456 KB |
Output is correct |
13 |
Correct |
3 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
3 ms |
3456 KB |
Output is correct |
16 |
Correct |
3 ms |
3456 KB |
Output is correct |
17 |
Correct |
3 ms |
3456 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
3 ms |
3456 KB |
Output is correct |
20 |
Correct |
10 ms |
4480 KB |
Output is correct |
21 |
Correct |
10 ms |
4480 KB |
Output is correct |
22 |
Correct |
10 ms |
4352 KB |
Output is correct |
23 |
Correct |
9 ms |
4352 KB |
Output is correct |
24 |
Correct |
9 ms |
4480 KB |
Output is correct |
25 |
Correct |
14 ms |
4480 KB |
Output is correct |
26 |
Correct |
10 ms |
4480 KB |
Output is correct |
27 |
Correct |
9 ms |
4480 KB |
Output is correct |
28 |
Correct |
10 ms |
4480 KB |
Output is correct |
29 |
Correct |
10 ms |
4480 KB |
Output is correct |
30 |
Correct |
7 ms |
4352 KB |
Output is correct |
31 |
Correct |
7 ms |
4352 KB |
Output is correct |
32 |
Correct |
10 ms |
4608 KB |
Output is correct |
33 |
Correct |
8 ms |
4480 KB |
Output is correct |
34 |
Correct |
11 ms |
4480 KB |
Output is correct |
35 |
Correct |
8 ms |
4480 KB |
Output is correct |
36 |
Correct |
8 ms |
4608 KB |
Output is correct |
37 |
Correct |
10 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
277 ms |
25072 KB |
Output is correct |
2 |
Correct |
209 ms |
24688 KB |
Output is correct |
3 |
Correct |
260 ms |
28264 KB |
Output is correct |
4 |
Correct |
261 ms |
28520 KB |
Output is correct |
5 |
Correct |
119 ms |
18028 KB |
Output is correct |
6 |
Correct |
143 ms |
18800 KB |
Output is correct |
7 |
Correct |
171 ms |
24936 KB |
Output is correct |
8 |
Correct |
78 ms |
14960 KB |
Output is correct |
9 |
Correct |
77 ms |
18160 KB |
Output is correct |
10 |
Correct |
96 ms |
23720 KB |
Output is correct |
11 |
Correct |
193 ms |
28632 KB |
Output is correct |
12 |
Correct |
230 ms |
28444 KB |
Output is correct |
13 |
Correct |
257 ms |
28264 KB |
Output is correct |
14 |
Correct |
251 ms |
28132 KB |
Output is correct |
15 |
Correct |
268 ms |
26352 KB |
Output is correct |
16 |
Correct |
265 ms |
25712 KB |
Output is correct |
17 |
Correct |
263 ms |
25200 KB |
Output is correct |
18 |
Correct |
194 ms |
28132 KB |
Output is correct |
19 |
Correct |
3 ms |
3456 KB |
Output is correct |
20 |
Correct |
4 ms |
3456 KB |
Output is correct |
21 |
Correct |
2 ms |
3456 KB |
Output is correct |
22 |
Correct |
3 ms |
3456 KB |
Output is correct |
23 |
Correct |
2 ms |
3456 KB |
Output is correct |
24 |
Correct |
2 ms |
3456 KB |
Output is correct |
25 |
Correct |
2 ms |
3456 KB |
Output is correct |
26 |
Correct |
2 ms |
3456 KB |
Output is correct |
27 |
Correct |
2 ms |
3456 KB |
Output is correct |
28 |
Correct |
3 ms |
3456 KB |
Output is correct |
29 |
Correct |
2 ms |
3456 KB |
Output is correct |
30 |
Correct |
2 ms |
3456 KB |
Output is correct |
31 |
Correct |
3 ms |
3456 KB |
Output is correct |
32 |
Correct |
2 ms |
3456 KB |
Output is correct |
33 |
Correct |
3 ms |
3456 KB |
Output is correct |
34 |
Correct |
3 ms |
3456 KB |
Output is correct |
35 |
Correct |
3 ms |
3456 KB |
Output is correct |
36 |
Correct |
2 ms |
3456 KB |
Output is correct |
37 |
Correct |
3 ms |
3456 KB |
Output is correct |
38 |
Correct |
10 ms |
4480 KB |
Output is correct |
39 |
Correct |
10 ms |
4480 KB |
Output is correct |
40 |
Correct |
10 ms |
4352 KB |
Output is correct |
41 |
Correct |
9 ms |
4352 KB |
Output is correct |
42 |
Correct |
9 ms |
4480 KB |
Output is correct |
43 |
Correct |
14 ms |
4480 KB |
Output is correct |
44 |
Correct |
10 ms |
4480 KB |
Output is correct |
45 |
Correct |
9 ms |
4480 KB |
Output is correct |
46 |
Correct |
10 ms |
4480 KB |
Output is correct |
47 |
Correct |
10 ms |
4480 KB |
Output is correct |
48 |
Correct |
7 ms |
4352 KB |
Output is correct |
49 |
Correct |
7 ms |
4352 KB |
Output is correct |
50 |
Correct |
10 ms |
4608 KB |
Output is correct |
51 |
Correct |
8 ms |
4480 KB |
Output is correct |
52 |
Correct |
11 ms |
4480 KB |
Output is correct |
53 |
Correct |
8 ms |
4480 KB |
Output is correct |
54 |
Correct |
8 ms |
4608 KB |
Output is correct |
55 |
Correct |
10 ms |
4352 KB |
Output is correct |
56 |
Correct |
295 ms |
26988 KB |
Output is correct |
57 |
Correct |
257 ms |
25452 KB |
Output is correct |
58 |
Correct |
278 ms |
26220 KB |
Output is correct |
59 |
Correct |
267 ms |
26480 KB |
Output is correct |
60 |
Correct |
259 ms |
24560 KB |
Output is correct |
61 |
Correct |
260 ms |
26220 KB |
Output is correct |
62 |
Correct |
265 ms |
26732 KB |
Output is correct |
63 |
Correct |
209 ms |
24560 KB |
Output is correct |
64 |
Correct |
193 ms |
24432 KB |
Output is correct |
65 |
Correct |
254 ms |
25072 KB |
Output is correct |
66 |
Correct |
231 ms |
24688 KB |
Output is correct |
67 |
Correct |
307 ms |
26992 KB |
Output is correct |
68 |
Correct |
257 ms |
26608 KB |
Output is correct |
69 |
Correct |
212 ms |
26084 KB |
Output is correct |
70 |
Correct |
305 ms |
27000 KB |
Output is correct |
71 |
Correct |
282 ms |
25840 KB |
Output is correct |
72 |
Correct |
209 ms |
26404 KB |
Output is correct |
73 |
Correct |
294 ms |
25328 KB |
Output is correct |
74 |
Correct |
142 ms |
26100 KB |
Output is correct |
75 |
Correct |
112 ms |
25280 KB |
Output is correct |
76 |
Correct |
190 ms |
29420 KB |
Output is correct |
77 |
Correct |
200 ms |
27372 KB |
Output is correct |
78 |
Correct |
261 ms |
28096 KB |
Output is correct |
79 |
Correct |
333 ms |
26648 KB |
Output is correct |
80 |
Correct |
299 ms |
25716 KB |
Output is correct |
81 |
Correct |
186 ms |
24812 KB |
Output is correct |
82 |
Correct |
286 ms |
25828 KB |
Output is correct |
83 |
Correct |
318 ms |
26128 KB |
Output is correct |
84 |
Correct |
340 ms |
25456 KB |
Output is correct |
85 |
Correct |
294 ms |
26480 KB |
Output is correct |
86 |
Correct |
248 ms |
26224 KB |
Output is correct |
87 |
Correct |
273 ms |
26500 KB |
Output is correct |
88 |
Correct |
268 ms |
29376 KB |
Output is correct |
89 |
Correct |
243 ms |
26348 KB |
Output is correct |
90 |
Correct |
210 ms |
28648 KB |
Output is correct |
91 |
Correct |
189 ms |
25968 KB |
Output is correct |
92 |
Correct |
251 ms |
27248 KB |
Output is correct |
93 |
Correct |
307 ms |
26092 KB |
Output is correct |
94 |
Correct |
275 ms |
26736 KB |
Output is correct |
95 |
Correct |
263 ms |
26608 KB |
Output is correct |
96 |
Correct |
180 ms |
27240 KB |
Output is correct |
97 |
Correct |
209 ms |
29160 KB |
Output is correct |
98 |
Correct |
216 ms |
29672 KB |
Output is correct |
99 |
Correct |
197 ms |
28520 KB |
Output is correct |
100 |
Correct |
158 ms |
26508 KB |
Output is correct |
101 |
Correct |
298 ms |
28968 KB |
Output is correct |
102 |
Correct |
195 ms |
29664 KB |
Output is correct |
103 |
Correct |
214 ms |
26860 KB |
Output is correct |