#include <bits/stdc++.h>
using namespace std;
const int MAXM = 131072;
int N, M;
int T[MAXM], L[MAXM], R[MAXM], C[MAXM];
int XL[MAXM], YL[MAXM], XR[MAXM], YR[MAXM];
bool vis[MAXM];
vector<pair<int, int> > idx[2*MAXM];
int ptr[2*MAXM];
bool in[MAXM];
void build(vector<tuple<int, int, int> > Vxyi)
{
for(auto [x, y, i]: Vxyi)
{
idx[x+MAXM].emplace_back(y, i);
in[i] = true;
}
for(int i=MAXM; i<2*MAXM; ++i)
sort(idx[i].begin(), idx[i].end());
for(int i=MAXM-1; i>=1; --i)
{
idx[i].resize(idx[2*i].size()+idx[2*i+1].size());
merge(idx[2*i].begin(), idx[2*i].end(), idx[2*i+1].begin(), idx[2*i+1].end(), idx[i].begin());
}
}
vector<int> popc(int x, int y)
{
vector<int> ret;
int f = MAXM, t = x+MAXM;
while(f<=t&&t)
{
if(t%2==0 || f==t)
{
while(ptr[t] < (int)idx[t].size())
{
auto [val, iv] = idx[t][ptr[t]];
if(val>y) break;
if(in[iv]) ret.push_back(iv), in[iv]=false;
++ptr[t];
}
--t;
}
f/=2; t/=2;
}
return ret;
}
int main()
{
scanf("%d%d", &N, &M);
vector<int> x, y;
for(int i=0; i<M; ++i)
{
scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
--L[i]; //L[i] = 0, R[i] = N covers whole
XL[i] = L[i]-T[i], YL[i] = L[i]+T[i];
XR[i] = R[i]-T[i], YR[i] = R[i]+T[i];
x.push_back(XL[i]); y.push_back(YL[i]);
}
sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
for(int i=0; i<M; ++i)
{
XL[i] = lower_bound(x.begin(), x.end(), XL[i]) - x.begin();
XR[i] = upper_bound(x.begin(), x.end(), XR[i]) - x.begin() - 1;
YL[i] = lower_bound(y.begin(), y.end(), YL[i]) - y.begin();
YR[i] = upper_bound(y.begin(), y.end(), YR[i]) - y.begin() - 1;
}
using pli = pair<long long, int>;
priority_queue<pli, vector<pli>, greater<pli>> Q;
vector<tuple<int, int, int> > Vxyi;
for(int i=0; i<M; ++i)
if(L[i] == 0)
vis[i] = true, Q.emplace((long long)C[i], i);
else
Vxyi.emplace_back(XL[i], YL[i], i);
build(Vxyi);
while(!Q.empty())
{
auto [cost, idx] = Q.top(); Q.pop();
if(R[idx] == N) return printf("%lld\n", cost), 0;
vector<int> idxs = popc(XR[idx], YR[idx]);
for(auto i: idxs)
{
vis[i] = true;
Q.emplace(cost+C[i], i);
}
}
puts("-1");
}
Compilation message
treatment.cpp: In function 'int main()':
treatment.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
treatment.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", T+i, L+i, R+i, C+i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
30948 KB |
Output is correct |
2 |
Correct |
173 ms |
30944 KB |
Output is correct |
3 |
Correct |
150 ms |
25588 KB |
Output is correct |
4 |
Correct |
149 ms |
25308 KB |
Output is correct |
5 |
Correct |
98 ms |
29400 KB |
Output is correct |
6 |
Correct |
126 ms |
27336 KB |
Output is correct |
7 |
Correct |
130 ms |
27872 KB |
Output is correct |
8 |
Correct |
95 ms |
26980 KB |
Output is correct |
9 |
Correct |
114 ms |
27492 KB |
Output is correct |
10 |
Correct |
110 ms |
27872 KB |
Output is correct |
11 |
Correct |
168 ms |
33268 KB |
Output is correct |
12 |
Correct |
171 ms |
33608 KB |
Output is correct |
13 |
Correct |
206 ms |
34020 KB |
Output is correct |
14 |
Correct |
198 ms |
33872 KB |
Output is correct |
15 |
Correct |
205 ms |
30928 KB |
Output is correct |
16 |
Correct |
212 ms |
31212 KB |
Output is correct |
17 |
Correct |
197 ms |
30948 KB |
Output is correct |
18 |
Correct |
159 ms |
33360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6528 KB |
Output is correct |
2 |
Correct |
9 ms |
6528 KB |
Output is correct |
3 |
Correct |
9 ms |
6528 KB |
Output is correct |
4 |
Correct |
9 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
9 ms |
6528 KB |
Output is correct |
7 |
Correct |
9 ms |
6528 KB |
Output is correct |
8 |
Correct |
9 ms |
6528 KB |
Output is correct |
9 |
Correct |
9 ms |
6528 KB |
Output is correct |
10 |
Correct |
9 ms |
6528 KB |
Output is correct |
11 |
Correct |
9 ms |
6528 KB |
Output is correct |
12 |
Correct |
9 ms |
6528 KB |
Output is correct |
13 |
Correct |
9 ms |
6528 KB |
Output is correct |
14 |
Correct |
9 ms |
6560 KB |
Output is correct |
15 |
Correct |
9 ms |
6528 KB |
Output is correct |
16 |
Correct |
9 ms |
6528 KB |
Output is correct |
17 |
Correct |
11 ms |
6528 KB |
Output is correct |
18 |
Correct |
9 ms |
6528 KB |
Output is correct |
19 |
Correct |
9 ms |
6528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6528 KB |
Output is correct |
2 |
Correct |
9 ms |
6528 KB |
Output is correct |
3 |
Correct |
9 ms |
6528 KB |
Output is correct |
4 |
Correct |
9 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
9 ms |
6528 KB |
Output is correct |
7 |
Correct |
9 ms |
6528 KB |
Output is correct |
8 |
Correct |
9 ms |
6528 KB |
Output is correct |
9 |
Correct |
9 ms |
6528 KB |
Output is correct |
10 |
Correct |
9 ms |
6528 KB |
Output is correct |
11 |
Correct |
9 ms |
6528 KB |
Output is correct |
12 |
Correct |
9 ms |
6528 KB |
Output is correct |
13 |
Correct |
9 ms |
6528 KB |
Output is correct |
14 |
Correct |
9 ms |
6560 KB |
Output is correct |
15 |
Correct |
9 ms |
6528 KB |
Output is correct |
16 |
Correct |
9 ms |
6528 KB |
Output is correct |
17 |
Correct |
11 ms |
6528 KB |
Output is correct |
18 |
Correct |
9 ms |
6528 KB |
Output is correct |
19 |
Correct |
9 ms |
6528 KB |
Output is correct |
20 |
Correct |
15 ms |
7552 KB |
Output is correct |
21 |
Correct |
15 ms |
7552 KB |
Output is correct |
22 |
Correct |
17 ms |
7808 KB |
Output is correct |
23 |
Correct |
16 ms |
7808 KB |
Output is correct |
24 |
Correct |
17 ms |
7808 KB |
Output is correct |
25 |
Correct |
17 ms |
7808 KB |
Output is correct |
26 |
Correct |
17 ms |
7808 KB |
Output is correct |
27 |
Correct |
15 ms |
7808 KB |
Output is correct |
28 |
Correct |
16 ms |
7808 KB |
Output is correct |
29 |
Correct |
18 ms |
7808 KB |
Output is correct |
30 |
Correct |
18 ms |
7808 KB |
Output is correct |
31 |
Correct |
15 ms |
7808 KB |
Output is correct |
32 |
Correct |
17 ms |
7936 KB |
Output is correct |
33 |
Correct |
16 ms |
7936 KB |
Output is correct |
34 |
Correct |
17 ms |
7808 KB |
Output is correct |
35 |
Correct |
16 ms |
7808 KB |
Output is correct |
36 |
Correct |
15 ms |
7936 KB |
Output is correct |
37 |
Correct |
17 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
30948 KB |
Output is correct |
2 |
Correct |
173 ms |
30944 KB |
Output is correct |
3 |
Correct |
150 ms |
25588 KB |
Output is correct |
4 |
Correct |
149 ms |
25308 KB |
Output is correct |
5 |
Correct |
98 ms |
29400 KB |
Output is correct |
6 |
Correct |
126 ms |
27336 KB |
Output is correct |
7 |
Correct |
130 ms |
27872 KB |
Output is correct |
8 |
Correct |
95 ms |
26980 KB |
Output is correct |
9 |
Correct |
114 ms |
27492 KB |
Output is correct |
10 |
Correct |
110 ms |
27872 KB |
Output is correct |
11 |
Correct |
168 ms |
33268 KB |
Output is correct |
12 |
Correct |
171 ms |
33608 KB |
Output is correct |
13 |
Correct |
206 ms |
34020 KB |
Output is correct |
14 |
Correct |
198 ms |
33872 KB |
Output is correct |
15 |
Correct |
205 ms |
30928 KB |
Output is correct |
16 |
Correct |
212 ms |
31212 KB |
Output is correct |
17 |
Correct |
197 ms |
30948 KB |
Output is correct |
18 |
Correct |
159 ms |
33360 KB |
Output is correct |
19 |
Correct |
9 ms |
6528 KB |
Output is correct |
20 |
Correct |
9 ms |
6528 KB |
Output is correct |
21 |
Correct |
9 ms |
6528 KB |
Output is correct |
22 |
Correct |
9 ms |
6528 KB |
Output is correct |
23 |
Correct |
8 ms |
6528 KB |
Output is correct |
24 |
Correct |
9 ms |
6528 KB |
Output is correct |
25 |
Correct |
9 ms |
6528 KB |
Output is correct |
26 |
Correct |
9 ms |
6528 KB |
Output is correct |
27 |
Correct |
9 ms |
6528 KB |
Output is correct |
28 |
Correct |
9 ms |
6528 KB |
Output is correct |
29 |
Correct |
9 ms |
6528 KB |
Output is correct |
30 |
Correct |
9 ms |
6528 KB |
Output is correct |
31 |
Correct |
9 ms |
6528 KB |
Output is correct |
32 |
Correct |
9 ms |
6560 KB |
Output is correct |
33 |
Correct |
9 ms |
6528 KB |
Output is correct |
34 |
Correct |
9 ms |
6528 KB |
Output is correct |
35 |
Correct |
11 ms |
6528 KB |
Output is correct |
36 |
Correct |
9 ms |
6528 KB |
Output is correct |
37 |
Correct |
9 ms |
6528 KB |
Output is correct |
38 |
Correct |
15 ms |
7552 KB |
Output is correct |
39 |
Correct |
15 ms |
7552 KB |
Output is correct |
40 |
Correct |
17 ms |
7808 KB |
Output is correct |
41 |
Correct |
16 ms |
7808 KB |
Output is correct |
42 |
Correct |
17 ms |
7808 KB |
Output is correct |
43 |
Correct |
17 ms |
7808 KB |
Output is correct |
44 |
Correct |
17 ms |
7808 KB |
Output is correct |
45 |
Correct |
15 ms |
7808 KB |
Output is correct |
46 |
Correct |
16 ms |
7808 KB |
Output is correct |
47 |
Correct |
18 ms |
7808 KB |
Output is correct |
48 |
Correct |
18 ms |
7808 KB |
Output is correct |
49 |
Correct |
15 ms |
7808 KB |
Output is correct |
50 |
Correct |
17 ms |
7936 KB |
Output is correct |
51 |
Correct |
16 ms |
7936 KB |
Output is correct |
52 |
Correct |
17 ms |
7808 KB |
Output is correct |
53 |
Correct |
16 ms |
7808 KB |
Output is correct |
54 |
Correct |
15 ms |
7936 KB |
Output is correct |
55 |
Correct |
17 ms |
7808 KB |
Output is correct |
56 |
Correct |
174 ms |
25580 KB |
Output is correct |
57 |
Correct |
179 ms |
26544 KB |
Output is correct |
58 |
Correct |
196 ms |
30940 KB |
Output is correct |
59 |
Correct |
198 ms |
30948 KB |
Output is correct |
60 |
Correct |
204 ms |
30948 KB |
Output is correct |
61 |
Correct |
209 ms |
30992 KB |
Output is correct |
62 |
Correct |
173 ms |
25588 KB |
Output is correct |
63 |
Correct |
190 ms |
30944 KB |
Output is correct |
64 |
Correct |
197 ms |
31076 KB |
Output is correct |
65 |
Correct |
198 ms |
30948 KB |
Output is correct |
66 |
Correct |
202 ms |
30872 KB |
Output is correct |
67 |
Correct |
246 ms |
30820 KB |
Output is correct |
68 |
Correct |
214 ms |
30948 KB |
Output is correct |
69 |
Correct |
177 ms |
30948 KB |
Output is correct |
70 |
Correct |
234 ms |
30940 KB |
Output is correct |
71 |
Correct |
214 ms |
30940 KB |
Output is correct |
72 |
Correct |
179 ms |
30948 KB |
Output is correct |
73 |
Correct |
234 ms |
30820 KB |
Output is correct |
74 |
Correct |
158 ms |
31068 KB |
Output is correct |
75 |
Correct |
137 ms |
30948 KB |
Output is correct |
76 |
Correct |
178 ms |
33488 KB |
Output is correct |
77 |
Correct |
192 ms |
31952 KB |
Output is correct |
78 |
Correct |
217 ms |
33744 KB |
Output is correct |
79 |
Correct |
242 ms |
30948 KB |
Output is correct |
80 |
Correct |
217 ms |
31204 KB |
Output is correct |
81 |
Correct |
187 ms |
30948 KB |
Output is correct |
82 |
Correct |
219 ms |
30944 KB |
Output is correct |
83 |
Correct |
234 ms |
30952 KB |
Output is correct |
84 |
Correct |
240 ms |
30948 KB |
Output is correct |
85 |
Correct |
214 ms |
30948 KB |
Output is correct |
86 |
Correct |
215 ms |
30948 KB |
Output is correct |
87 |
Correct |
222 ms |
30924 KB |
Output is correct |
88 |
Correct |
208 ms |
29668 KB |
Output is correct |
89 |
Correct |
219 ms |
30944 KB |
Output is correct |
90 |
Correct |
187 ms |
33360 KB |
Output is correct |
91 |
Correct |
183 ms |
30948 KB |
Output is correct |
92 |
Correct |
220 ms |
30948 KB |
Output is correct |
93 |
Correct |
242 ms |
30936 KB |
Output is correct |
94 |
Correct |
207 ms |
29260 KB |
Output is correct |
95 |
Correct |
230 ms |
30948 KB |
Output is correct |
96 |
Correct |
187 ms |
31816 KB |
Output is correct |
97 |
Correct |
192 ms |
33744 KB |
Output is correct |
98 |
Correct |
197 ms |
33904 KB |
Output is correct |
99 |
Correct |
196 ms |
33360 KB |
Output is correct |
100 |
Correct |
164 ms |
29636 KB |
Output is correct |
101 |
Correct |
203 ms |
34384 KB |
Output is correct |
102 |
Correct |
189 ms |
33864 KB |
Output is correct |
103 |
Correct |
204 ms |
31048 KB |
Output is correct |