// #include <bits/stdc++.h>
// #define int long long
// using namespace std;
// const int Nmax=5010, INF=1e18;
// int N, M, T[Nmax], L[Nmax], R[Nmax], C[Nmax], D[Nmax];
// vector<int> adj[Nmax];
// priority_queue<pair<int, int>> PQ;
// signed main() {
// ios_base::sync_with_stdio(0); cin.tie(0);
// cin>>N>>M;
// for(int i=1; i<=M; i++) {
// cin>>T[i]>>L[i]>>R[i]>>C[i];
// if(L[i]==1) adj[0].push_back(i);
// if(R[i]==N) adj[i].push_back(M+1);
// }
// for(int i=1; i<=M; i++) for(int j=i+1; j<=M; j++) {
// int l1=L[i]+max(0ll, T[j]-T[i]), r1=R[i]-max(0ll, T[j]-T[i]);
// int l2=L[j]+max(0ll, T[i]-T[j]), r2=R[j]-max(0ll, T[i]-T[j]);
// if(l1>r1 || l2>r2) continue;
// if(!(l1>r2+1 || l2>r1+1)) adj[i].push_back(j), adj[j].push_back(i);
// }
// fill(D+1, D+M+2, INF);
// PQ.push({0, 0});
// while(!PQ.empty()) {
// int curr=PQ.top().second, dist=-PQ.top().first; PQ.pop();
// if(dist!=D[curr]) continue;
// for(int next:adj[curr]) if(D[next]>D[curr]+C[next]) D[next]=D[curr]+C[next], PQ.push({-D[next], next});
// }
// if(D[M+1]==INF) cout<<-1;
// else cout<<D[M+1];
// return 0;
// }
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=100010, S=(1<<17), INF=1e18;
int N, M, ans=INF;
struct Data {int t, l, r, c;}A[Nmax];
vector<int> V;
class Seg {
public:
Seg() {fill(Tree+1, Tree+2*S, INF);}
void Update(int k, int v) {
k+=S-1;
Tree[k]=min(Tree[k], v);
for(k>>=1; k; k>>=1) Tree[k]=min(Tree[k<<1], Tree[k<<1|1]);
}
int Query(int l, int r) {
int ret=INF;
for(l+=S-1, r+=S-1; l<r; l>>=1, r>>=1) {
if(l&1) ret=min(ret, Tree[l++]);
if(!(r&1)) ret=min(ret, Tree[r--]);
}
if(l==r) ret=min(ret, Tree[l]);
return ret;
}
private:
int Tree[2*S];
}T;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>M;
for(int i=1; i<=M; i++) cin>>A[i].t>>A[i].l>>A[i].r>>A[i].c, V.push_back(A[i].r);
sort(A+1, A+M+1, [](Data a, Data b) {return a.r<b.r;});
V.push_back(0), V.push_back(M);
sort(V.begin(), V.end()), V.erase(unique(V.begin(), V.end()), V.end());
T.Update(1, 0);
for(int i=1; i<=M; i++) {
int tmp=T.Query(lower_bound(V.begin(), V.end(), A[i].l-1)-V.begin()+1, V.size())+A[i].c;
T.Update(lower_bound(V.begin(), V.end(), A[i].r)-V.begin()+1, tmp);
if(A[i].r==N) ans=min(ans, tmp);
}
if(ans==INF) cout<<-1;
else cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
9932 KB |
Output is correct |
2 |
Correct |
47 ms |
9576 KB |
Output is correct |
3 |
Correct |
36 ms |
8548 KB |
Output is correct |
4 |
Correct |
38 ms |
8664 KB |
Output is correct |
5 |
Correct |
30 ms |
9412 KB |
Output is correct |
6 |
Correct |
31 ms |
9432 KB |
Output is correct |
7 |
Correct |
33 ms |
9424 KB |
Output is correct |
8 |
Correct |
30 ms |
9436 KB |
Output is correct |
9 |
Correct |
30 ms |
9568 KB |
Output is correct |
10 |
Correct |
32 ms |
9432 KB |
Output is correct |
11 |
Correct |
45 ms |
9688 KB |
Output is correct |
12 |
Correct |
45 ms |
9504 KB |
Output is correct |
13 |
Correct |
44 ms |
9432 KB |
Output is correct |
14 |
Correct |
45 ms |
9432 KB |
Output is correct |
15 |
Correct |
44 ms |
9428 KB |
Output is correct |
16 |
Correct |
44 ms |
9432 KB |
Output is correct |
17 |
Correct |
40 ms |
8632 KB |
Output is correct |
18 |
Correct |
43 ms |
8920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
9932 KB |
Output is correct |
2 |
Correct |
47 ms |
9576 KB |
Output is correct |
3 |
Correct |
36 ms |
8548 KB |
Output is correct |
4 |
Correct |
38 ms |
8664 KB |
Output is correct |
5 |
Correct |
30 ms |
9412 KB |
Output is correct |
6 |
Correct |
31 ms |
9432 KB |
Output is correct |
7 |
Correct |
33 ms |
9424 KB |
Output is correct |
8 |
Correct |
30 ms |
9436 KB |
Output is correct |
9 |
Correct |
30 ms |
9568 KB |
Output is correct |
10 |
Correct |
32 ms |
9432 KB |
Output is correct |
11 |
Correct |
45 ms |
9688 KB |
Output is correct |
12 |
Correct |
45 ms |
9504 KB |
Output is correct |
13 |
Correct |
44 ms |
9432 KB |
Output is correct |
14 |
Correct |
45 ms |
9432 KB |
Output is correct |
15 |
Correct |
44 ms |
9428 KB |
Output is correct |
16 |
Correct |
44 ms |
9432 KB |
Output is correct |
17 |
Correct |
40 ms |
8632 KB |
Output is correct |
18 |
Correct |
43 ms |
8920 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |