#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXM = 1e5;
const ll INF = 1e18;
int N, M;
struct Data { ll t, l, r, c; };
struct Point
{
ll x, y, p;
bool operator < (const Point &p) const { return x<p.x; }
};
struct Queue
{
int v; ll w;
bool operator < (const Queue &p) const { return w>p.w; }
};
Data A[MAXM+10];
Point P[MAXM+10];
ll dist[MAXM+10];
bool vis[MAXM+10];
vector<pll> tree[MAXM*4+10];
void init(int node, int tl, int tr)
{
if(tl==tr)
{
tree[node].push_back({P[tl].y, P[tl].p});
return;
}
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
tree[node].resize(tree[node*2].size()+tree[node*2+1].size());
merge(tree[node*2].begin(), tree[node*2].end(), tree[node*2+1].begin(), tree[node*2+1].end(), tree[node].begin(), greater<pll>());
//for(auto it : tree[node]) printf("%lld %lld / ", it.first, it.second); printf(" => %d %d\n", tl, tr);
}
void query(int node, int tl, int tr, int x, ll y, vector<int> &V)
{
if(x<tl) return;
if(tr<=x)
{
while(!tree[node].empty() && tree[node].back().first<=y)
{
if(!vis[tree[node].back().second]) V.push_back(tree[node].back().second);
tree[node].pop_back();
}
return;
}
int mid=tl+tr>>1;
query(node*2, tl, mid, x, y, V);
query(node*2+1, mid+1, tr, x, y, V);
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=M; i++) scanf("%lld%lld%lld%lld", &A[i].t, &A[i].l, &A[i].r, &A[i].c);
for(i=1; i<=M; i++) P[i]={-A[i].t+A[i].l, A[i].t+A[i].l, i};
sort(P+1, P+M+1);
init(1, 1, M);
for(i=1; i<=M; i++) dist[i]=INF;
priority_queue<Queue> PQ;
for(i=1; i<=M; i++) if(A[i].l==1)
{
vis[i]=true;
dist[i]=A[i].c;
PQ.push({i, A[i].c});
}
while(!PQ.empty())
{
int now=PQ.top().v; PQ.pop();
//printf("!%d\n", now);
ll x, y;
x=upper_bound(P+1, P+M+1, (Point){-A[now].t+A[now].r+1, -1, -1})-P-1;
y=A[now].t+A[now].r+1;
vector<int> V;
query(1, 1, M, x, y, V);
//printf("!!%lld %lld\n", x, y);
for(auto nxt : V)
{
vis[nxt]=true;
dist[nxt]=dist[now]+A[nxt].c;
PQ.push({nxt, dist[nxt]});
}
}
ll ans=INF;
for(i=1; i<=M; i++) if(A[i].r==N) ans=min(ans, dist[i]);
if(ans==INF) ans=-1;
printf("%lld\n", ans);
}
Compilation message
treatment.cpp: In function 'void init(int, int, int)':
treatment.cpp:40:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
treatment.cpp: In function 'void query(int, int, int, int, ll, std::vector<int>&)':
treatment.cpp:60:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
treatment.cpp: In function 'int main()':
treatment.cpp:67:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
treatment.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:70:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=M; i++) scanf("%lld%lld%lld%lld", &A[i].t, &A[i].l, &A[i].r, &A[i].c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
50172 KB |
Output is correct |
2 |
Correct |
135 ms |
50168 KB |
Output is correct |
3 |
Correct |
172 ms |
50392 KB |
Output is correct |
4 |
Correct |
162 ms |
50368 KB |
Output is correct |
5 |
Correct |
181 ms |
52204 KB |
Output is correct |
6 |
Correct |
172 ms |
50424 KB |
Output is correct |
7 |
Correct |
152 ms |
49992 KB |
Output is correct |
8 |
Correct |
132 ms |
50040 KB |
Output is correct |
9 |
Correct |
120 ms |
50204 KB |
Output is correct |
10 |
Correct |
121 ms |
50012 KB |
Output is correct |
11 |
Correct |
215 ms |
52588 KB |
Output is correct |
12 |
Correct |
202 ms |
52488 KB |
Output is correct |
13 |
Correct |
237 ms |
52180 KB |
Output is correct |
14 |
Correct |
228 ms |
52172 KB |
Output is correct |
15 |
Correct |
180 ms |
50040 KB |
Output is correct |
16 |
Correct |
180 ms |
50040 KB |
Output is correct |
17 |
Correct |
178 ms |
49304 KB |
Output is correct |
18 |
Correct |
178 ms |
51820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9764 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
10 ms |
9728 KB |
Output is correct |
6 |
Correct |
13 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
10 ms |
9728 KB |
Output is correct |
9 |
Correct |
13 ms |
9728 KB |
Output is correct |
10 |
Correct |
10 ms |
9728 KB |
Output is correct |
11 |
Correct |
10 ms |
9728 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9728 KB |
Output is correct |
14 |
Correct |
12 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
10 ms |
9728 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
19 |
Correct |
10 ms |
9728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9764 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
10 ms |
9728 KB |
Output is correct |
6 |
Correct |
13 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
10 ms |
9728 KB |
Output is correct |
9 |
Correct |
13 ms |
9728 KB |
Output is correct |
10 |
Correct |
10 ms |
9728 KB |
Output is correct |
11 |
Correct |
10 ms |
9728 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9728 KB |
Output is correct |
14 |
Correct |
12 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
10 ms |
9728 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
19 |
Correct |
10 ms |
9728 KB |
Output is correct |
20 |
Correct |
16 ms |
11520 KB |
Output is correct |
21 |
Correct |
16 ms |
11520 KB |
Output is correct |
22 |
Correct |
16 ms |
11392 KB |
Output is correct |
23 |
Correct |
16 ms |
11392 KB |
Output is correct |
24 |
Correct |
18 ms |
11520 KB |
Output is correct |
25 |
Correct |
18 ms |
11520 KB |
Output is correct |
26 |
Correct |
17 ms |
11392 KB |
Output is correct |
27 |
Correct |
17 ms |
11392 KB |
Output is correct |
28 |
Correct |
18 ms |
11648 KB |
Output is correct |
29 |
Correct |
18 ms |
11520 KB |
Output is correct |
30 |
Correct |
16 ms |
11392 KB |
Output is correct |
31 |
Correct |
15 ms |
11520 KB |
Output is correct |
32 |
Correct |
19 ms |
11648 KB |
Output is correct |
33 |
Correct |
22 ms |
11648 KB |
Output is correct |
34 |
Correct |
17 ms |
11392 KB |
Output is correct |
35 |
Correct |
18 ms |
11648 KB |
Output is correct |
36 |
Correct |
17 ms |
11648 KB |
Output is correct |
37 |
Correct |
17 ms |
11392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
50172 KB |
Output is correct |
2 |
Correct |
135 ms |
50168 KB |
Output is correct |
3 |
Correct |
172 ms |
50392 KB |
Output is correct |
4 |
Correct |
162 ms |
50368 KB |
Output is correct |
5 |
Correct |
181 ms |
52204 KB |
Output is correct |
6 |
Correct |
172 ms |
50424 KB |
Output is correct |
7 |
Correct |
152 ms |
49992 KB |
Output is correct |
8 |
Correct |
132 ms |
50040 KB |
Output is correct |
9 |
Correct |
120 ms |
50204 KB |
Output is correct |
10 |
Correct |
121 ms |
50012 KB |
Output is correct |
11 |
Correct |
215 ms |
52588 KB |
Output is correct |
12 |
Correct |
202 ms |
52488 KB |
Output is correct |
13 |
Correct |
237 ms |
52180 KB |
Output is correct |
14 |
Correct |
228 ms |
52172 KB |
Output is correct |
15 |
Correct |
180 ms |
50040 KB |
Output is correct |
16 |
Correct |
180 ms |
50040 KB |
Output is correct |
17 |
Correct |
178 ms |
49304 KB |
Output is correct |
18 |
Correct |
178 ms |
51820 KB |
Output is correct |
19 |
Correct |
10 ms |
9728 KB |
Output is correct |
20 |
Correct |
10 ms |
9764 KB |
Output is correct |
21 |
Correct |
10 ms |
9728 KB |
Output is correct |
22 |
Correct |
10 ms |
9728 KB |
Output is correct |
23 |
Correct |
10 ms |
9728 KB |
Output is correct |
24 |
Correct |
13 ms |
9728 KB |
Output is correct |
25 |
Correct |
10 ms |
9728 KB |
Output is correct |
26 |
Correct |
10 ms |
9728 KB |
Output is correct |
27 |
Correct |
13 ms |
9728 KB |
Output is correct |
28 |
Correct |
10 ms |
9728 KB |
Output is correct |
29 |
Correct |
10 ms |
9728 KB |
Output is correct |
30 |
Correct |
10 ms |
9728 KB |
Output is correct |
31 |
Correct |
10 ms |
9728 KB |
Output is correct |
32 |
Correct |
12 ms |
9728 KB |
Output is correct |
33 |
Correct |
10 ms |
9728 KB |
Output is correct |
34 |
Correct |
10 ms |
9728 KB |
Output is correct |
35 |
Correct |
10 ms |
9728 KB |
Output is correct |
36 |
Correct |
10 ms |
9728 KB |
Output is correct |
37 |
Correct |
10 ms |
9728 KB |
Output is correct |
38 |
Correct |
16 ms |
11520 KB |
Output is correct |
39 |
Correct |
16 ms |
11520 KB |
Output is correct |
40 |
Correct |
16 ms |
11392 KB |
Output is correct |
41 |
Correct |
16 ms |
11392 KB |
Output is correct |
42 |
Correct |
18 ms |
11520 KB |
Output is correct |
43 |
Correct |
18 ms |
11520 KB |
Output is correct |
44 |
Correct |
17 ms |
11392 KB |
Output is correct |
45 |
Correct |
17 ms |
11392 KB |
Output is correct |
46 |
Correct |
18 ms |
11648 KB |
Output is correct |
47 |
Correct |
18 ms |
11520 KB |
Output is correct |
48 |
Correct |
16 ms |
11392 KB |
Output is correct |
49 |
Correct |
15 ms |
11520 KB |
Output is correct |
50 |
Correct |
19 ms |
11648 KB |
Output is correct |
51 |
Correct |
22 ms |
11648 KB |
Output is correct |
52 |
Correct |
17 ms |
11392 KB |
Output is correct |
53 |
Correct |
18 ms |
11648 KB |
Output is correct |
54 |
Correct |
17 ms |
11648 KB |
Output is correct |
55 |
Correct |
17 ms |
11392 KB |
Output is correct |
56 |
Correct |
173 ms |
50672 KB |
Output is correct |
57 |
Correct |
183 ms |
51160 KB |
Output is correct |
58 |
Correct |
161 ms |
49272 KB |
Output is correct |
59 |
Correct |
164 ms |
49656 KB |
Output is correct |
60 |
Correct |
199 ms |
50300 KB |
Output is correct |
61 |
Correct |
163 ms |
49272 KB |
Output is correct |
62 |
Correct |
165 ms |
50672 KB |
Output is correct |
63 |
Correct |
169 ms |
50168 KB |
Output is correct |
64 |
Correct |
168 ms |
50168 KB |
Output is correct |
65 |
Correct |
165 ms |
50424 KB |
Output is correct |
66 |
Correct |
180 ms |
50296 KB |
Output is correct |
67 |
Correct |
232 ms |
50936 KB |
Output is correct |
68 |
Correct |
227 ms |
50936 KB |
Output is correct |
69 |
Correct |
192 ms |
50808 KB |
Output is correct |
70 |
Correct |
238 ms |
51064 KB |
Output is correct |
71 |
Correct |
217 ms |
50808 KB |
Output is correct |
72 |
Correct |
183 ms |
50808 KB |
Output is correct |
73 |
Correct |
230 ms |
51064 KB |
Output is correct |
74 |
Correct |
133 ms |
50812 KB |
Output is correct |
75 |
Correct |
127 ms |
50936 KB |
Output is correct |
76 |
Correct |
198 ms |
52972 KB |
Output is correct |
77 |
Correct |
234 ms |
53104 KB |
Output is correct |
78 |
Correct |
225 ms |
52624 KB |
Output is correct |
79 |
Correct |
236 ms |
50808 KB |
Output is correct |
80 |
Correct |
180 ms |
50532 KB |
Output is correct |
81 |
Correct |
137 ms |
50864 KB |
Output is correct |
82 |
Correct |
178 ms |
49956 KB |
Output is correct |
83 |
Correct |
190 ms |
50096 KB |
Output is correct |
84 |
Correct |
224 ms |
50040 KB |
Output is correct |
85 |
Correct |
186 ms |
50856 KB |
Output is correct |
86 |
Correct |
167 ms |
50808 KB |
Output is correct |
87 |
Correct |
189 ms |
50860 KB |
Output is correct |
88 |
Correct |
178 ms |
50808 KB |
Output is correct |
89 |
Correct |
173 ms |
50808 KB |
Output is correct |
90 |
Correct |
247 ms |
52976 KB |
Output is correct |
91 |
Correct |
225 ms |
52208 KB |
Output is correct |
92 |
Correct |
180 ms |
50808 KB |
Output is correct |
93 |
Correct |
233 ms |
50936 KB |
Output is correct |
94 |
Correct |
193 ms |
51192 KB |
Output is correct |
95 |
Correct |
221 ms |
50808 KB |
Output is correct |
96 |
Correct |
250 ms |
53120 KB |
Output is correct |
97 |
Correct |
235 ms |
52936 KB |
Output is correct |
98 |
Correct |
235 ms |
53072 KB |
Output is correct |
99 |
Correct |
223 ms |
52960 KB |
Output is correct |
100 |
Correct |
206 ms |
53100 KB |
Output is correct |
101 |
Correct |
237 ms |
52912 KB |
Output is correct |
102 |
Correct |
200 ms |
53400 KB |
Output is correct |
103 |
Correct |
184 ms |
51192 KB |
Output is correct |