#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, m;
int t[100010];
int l[100010];
int r[100010];
int c[100010];
vector<int> com;
vector<int> v;
ll dp[300010];
ll tree[1200010];
void update(int node, int s, int e, int i) {
if(s == e) {
tree[node] = dp[i];
return;
}
int m = s + e >> 1;
if(i <= m) update(node*2, s, m, i);
else update(node*2+1, m+1, e, i);
tree[node] = min(tree[node*2], tree[node*2+1]);
}
ll cal(int node, int s, int e, int l, int r) {
if(r < s || e < l) return INF;
if(l <= s && e <= r) return tree[node];
return min(cal(node*2, s, (s+e)/2, l, r), cal(node*2+1, (s+e)/2+1, e, l, r));
}
int main() {
fast;
cin >> n >> m;
for(int i=0; i<m; i++) {
cin >> t[i] >> l[i] >> r[i] >> c[i];
v.eb(i);
com.eb(l[i]-1);
com.eb(l[i]);
com.eb(r[i]);
}
com.eb(0);
com.eb(n);
sort(all(com));
com.erase(unique(all(com)), com.end());
sort(all(v), [&] (int i, int j) {
return r[i] < r[j];
});
for(int i=1; i<com.size(); i++)
dp[i] = INF, update(1, 0, com.size()-1, i);
for(auto i : v) {
r[i] = lower_bound(all(com), r[i]) - com.begin();
l[i] = lower_bound(all(com), l[i]) - com.begin();
dp[r[i]] = min(dp[r[i]], cal(1, 0, com.size()-1, l[i]-1, r[i]) + c[i]);
update(1, 0, com.size()-1, r[i]);
}
if(dp[com.size()-1] == INF) cout << -1;
else cout << dp[com.size()-1];
}
Compilation message
treatment.cpp: In function 'void update(int, int, int, int)':
treatment.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int m = s + e >> 1;
| ~~^~~
treatment.cpp: In function 'int main()':
treatment.cpp:76:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=1; i<com.size(); i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
9704 KB |
Output is correct |
2 |
Correct |
173 ms |
9704 KB |
Output is correct |
3 |
Correct |
127 ms |
5992 KB |
Output is correct |
4 |
Correct |
121 ms |
5864 KB |
Output is correct |
5 |
Correct |
73 ms |
5104 KB |
Output is correct |
6 |
Correct |
81 ms |
5104 KB |
Output is correct |
7 |
Correct |
99 ms |
5104 KB |
Output is correct |
8 |
Correct |
80 ms |
5104 KB |
Output is correct |
9 |
Correct |
87 ms |
5232 KB |
Output is correct |
10 |
Correct |
108 ms |
5224 KB |
Output is correct |
11 |
Correct |
202 ms |
10476 KB |
Output is correct |
12 |
Correct |
202 ms |
10472 KB |
Output is correct |
13 |
Correct |
208 ms |
14952 KB |
Output is correct |
14 |
Correct |
217 ms |
15080 KB |
Output is correct |
15 |
Correct |
199 ms |
14956 KB |
Output is correct |
16 |
Correct |
201 ms |
14948 KB |
Output is correct |
17 |
Correct |
193 ms |
15080 KB |
Output is correct |
18 |
Correct |
193 ms |
10472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
9704 KB |
Output is correct |
2 |
Correct |
173 ms |
9704 KB |
Output is correct |
3 |
Correct |
127 ms |
5992 KB |
Output is correct |
4 |
Correct |
121 ms |
5864 KB |
Output is correct |
5 |
Correct |
73 ms |
5104 KB |
Output is correct |
6 |
Correct |
81 ms |
5104 KB |
Output is correct |
7 |
Correct |
99 ms |
5104 KB |
Output is correct |
8 |
Correct |
80 ms |
5104 KB |
Output is correct |
9 |
Correct |
87 ms |
5232 KB |
Output is correct |
10 |
Correct |
108 ms |
5224 KB |
Output is correct |
11 |
Correct |
202 ms |
10476 KB |
Output is correct |
12 |
Correct |
202 ms |
10472 KB |
Output is correct |
13 |
Correct |
208 ms |
14952 KB |
Output is correct |
14 |
Correct |
217 ms |
15080 KB |
Output is correct |
15 |
Correct |
199 ms |
14956 KB |
Output is correct |
16 |
Correct |
201 ms |
14948 KB |
Output is correct |
17 |
Correct |
193 ms |
15080 KB |
Output is correct |
18 |
Correct |
193 ms |
10472 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |