/* There's someone in my head but it's not me */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 2e5 + 10;
ll dp[N]; vector<pii> adj[N]; vector<int> cp; int w[N], l[N], r[N], T[N], M[N], n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d%d", &T[i], &l[i], &r[i], &w[i]);
assert(T[i] < 2);
r[i]++;
cp.push_back(r[i]);
cp.push_back(l[i]);
}
cp.push_back(1), cp.push_back(n + 1);
sort(cp.begin(), cp.end());
cp.resize(unique(cp.begin(), cp.end()) - cp.begin());
for (int i = 1; i <= m; i++) {
l[i] = lower_bound(begin(cp), end(cp), l[i]) - begin(cp);
r[i] = lower_bound(begin(cp), end(cp), r[i]) - begin(cp);
adj[r[i]].push_back({l[i], w[i]});
}
for (int i = 0; i + 1 < SZ(cp); i++) {
adj[i].emplace_back(i + 1, 0);
}
priority_queue<pair<ll, int>> pq;
fill(dp, dp + N, 1e18);
pq.emplace(dp[SZ(cp) - 1] = 0, SZ(cp) - 1);
while (SZ(pq)) {
int v = pq.top().S; pq.pop();
if (M[v]) continue;
M[v] = 1;
for (auto u : adj[v])
if (dp[u.F] > dp[v] + u.S)
dp[u.F] = dp[v] + u.S, pq.emplace(-dp[u.F], u.F);
}
printf("%lld\n", dp[0] >= 1e18 ? -1 : dp[0]);
return 0;
}
Compilation message
treatment.cpp: In function 'int main()':
treatment.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
17 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
19 | scanf("%d%d%d%d", &T[i], &l[i], &r[i], &w[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
12340 KB |
Output is correct |
2 |
Correct |
107 ms |
12288 KB |
Output is correct |
3 |
Correct |
86 ms |
14108 KB |
Output is correct |
4 |
Correct |
88 ms |
14136 KB |
Output is correct |
5 |
Correct |
63 ms |
12864 KB |
Output is correct |
6 |
Correct |
68 ms |
12980 KB |
Output is correct |
7 |
Correct |
75 ms |
13464 KB |
Output is correct |
8 |
Correct |
77 ms |
12792 KB |
Output is correct |
9 |
Correct |
94 ms |
13072 KB |
Output is correct |
10 |
Correct |
82 ms |
13752 KB |
Output is correct |
11 |
Correct |
135 ms |
19488 KB |
Output is correct |
12 |
Correct |
135 ms |
19640 KB |
Output is correct |
13 |
Correct |
169 ms |
20168 KB |
Output is correct |
14 |
Correct |
168 ms |
20204 KB |
Output is correct |
15 |
Correct |
148 ms |
19088 KB |
Output is correct |
16 |
Correct |
156 ms |
19016 KB |
Output is correct |
17 |
Correct |
146 ms |
18284 KB |
Output is correct |
18 |
Correct |
143 ms |
18804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
12340 KB |
Output is correct |
2 |
Correct |
107 ms |
12288 KB |
Output is correct |
3 |
Correct |
86 ms |
14108 KB |
Output is correct |
4 |
Correct |
88 ms |
14136 KB |
Output is correct |
5 |
Correct |
63 ms |
12864 KB |
Output is correct |
6 |
Correct |
68 ms |
12980 KB |
Output is correct |
7 |
Correct |
75 ms |
13464 KB |
Output is correct |
8 |
Correct |
77 ms |
12792 KB |
Output is correct |
9 |
Correct |
94 ms |
13072 KB |
Output is correct |
10 |
Correct |
82 ms |
13752 KB |
Output is correct |
11 |
Correct |
135 ms |
19488 KB |
Output is correct |
12 |
Correct |
135 ms |
19640 KB |
Output is correct |
13 |
Correct |
169 ms |
20168 KB |
Output is correct |
14 |
Correct |
168 ms |
20204 KB |
Output is correct |
15 |
Correct |
148 ms |
19088 KB |
Output is correct |
16 |
Correct |
156 ms |
19016 KB |
Output is correct |
17 |
Correct |
146 ms |
18284 KB |
Output is correct |
18 |
Correct |
143 ms |
18804 KB |
Output is correct |
19 |
Runtime error |
8 ms |
9932 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |