# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
361450 |
2021-01-30T08:43:00 Z |
RyoPham |
Pinball (JOI14_pinball) |
C++14 |
|
374 ms |
26984 KB |
#define taskname "test"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 3e5 + 5;
const lli inf = 1e18;
int n, m;
int a[maxn], b[maxn], c[maxn], d[maxn];
vector<int> vals;
struct segment_tree
{
lli min_val[maxn * 4];
segment_tree()
{
fill(begin(min_val), end(min_val), inf);
}
void update(int x, int l, int r, int p, lli k)
{
if(l == r)
{
min_val[x] = min(min_val[x], k);
return;
}
int mid = (l + r) / 2;
if(p <= mid) update(x * 2, l, mid, p, k);
else update(x * 2 + 1, mid + 1, r, p, k);
min_val[x] = min(min_val[x * 2], min_val[x * 2 + 1]);
}
lli get(int x, int l, int r, int L, int R)
{
if(L > r || l > R) return inf;
if(l >= L && r <= R)
return min_val[x];
int mid = (l + r) / 2;
return min(get(x * 2, l, mid, L, R),
get(x * 2 + 1, mid + 1, r, L, R));
}
};
segment_tree tree_f, tree_g;
void read_input()
{
cin >> n >> m;
for(int i = 1; i <= n; ++i)
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
int lwb(const vector<int>&arr, int k)
{
return lower_bound(arr.begin(), arr.end(), k) - arr.begin() + 1;
}
void init()
{
vals.push_back(1);
vals.push_back(m);
for(int i = 1; i <= n; ++i)
{
vals.push_back(a[i]);
vals.push_back(b[i]);
vals.push_back(c[i]);
}
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
m = sz(vals);
for(int i = 1; i <= n; ++i)
{
a[i] = lwb(vals, a[i]);
b[i] = lwb(vals, b[i]);
c[i] = lwb(vals, c[i]);
}
}
void solve()
{
tree_f.update(1, 1, m, 1, 0);
tree_g.update(1, 1, m, m, 0);
lli ans = inf;
for(int i = 1; i <= n; ++i)
{
ans = min(ans, tree_f.get(1, 1, m, a[i], b[i]) + tree_g.get(1, 1, m, a[i], b[i]) + d[i]);
lli k = tree_f.get(1, 1, m, a[i], b[i]) + d[i];
tree_f.update(1, 1, m, c[i], k);
k = tree_g.get(1, 1, m, a[i], b[i]) + d[i];
tree_g.update(1, 1, m, c[i], k);
}
if(ans == inf) ans = -1;
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read_input();
init();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
19180 KB |
Output is correct |
2 |
Correct |
12 ms |
19180 KB |
Output is correct |
3 |
Correct |
12 ms |
19180 KB |
Output is correct |
4 |
Correct |
12 ms |
19180 KB |
Output is correct |
5 |
Correct |
14 ms |
19308 KB |
Output is correct |
6 |
Correct |
13 ms |
19180 KB |
Output is correct |
7 |
Correct |
15 ms |
19308 KB |
Output is correct |
8 |
Correct |
12 ms |
19180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
19180 KB |
Output is correct |
2 |
Correct |
12 ms |
19180 KB |
Output is correct |
3 |
Correct |
12 ms |
19180 KB |
Output is correct |
4 |
Correct |
12 ms |
19180 KB |
Output is correct |
5 |
Correct |
14 ms |
19308 KB |
Output is correct |
6 |
Correct |
13 ms |
19180 KB |
Output is correct |
7 |
Correct |
15 ms |
19308 KB |
Output is correct |
8 |
Correct |
12 ms |
19180 KB |
Output is correct |
9 |
Correct |
12 ms |
19180 KB |
Output is correct |
10 |
Correct |
12 ms |
19180 KB |
Output is correct |
11 |
Correct |
12 ms |
19180 KB |
Output is correct |
12 |
Correct |
12 ms |
19180 KB |
Output is correct |
13 |
Correct |
13 ms |
19180 KB |
Output is correct |
14 |
Correct |
12 ms |
19180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
19180 KB |
Output is correct |
2 |
Correct |
12 ms |
19180 KB |
Output is correct |
3 |
Correct |
12 ms |
19180 KB |
Output is correct |
4 |
Correct |
12 ms |
19180 KB |
Output is correct |
5 |
Correct |
14 ms |
19308 KB |
Output is correct |
6 |
Correct |
13 ms |
19180 KB |
Output is correct |
7 |
Correct |
15 ms |
19308 KB |
Output is correct |
8 |
Correct |
12 ms |
19180 KB |
Output is correct |
9 |
Correct |
12 ms |
19180 KB |
Output is correct |
10 |
Correct |
12 ms |
19180 KB |
Output is correct |
11 |
Correct |
12 ms |
19180 KB |
Output is correct |
12 |
Correct |
12 ms |
19180 KB |
Output is correct |
13 |
Correct |
13 ms |
19180 KB |
Output is correct |
14 |
Correct |
12 ms |
19180 KB |
Output is correct |
15 |
Correct |
13 ms |
19180 KB |
Output is correct |
16 |
Correct |
13 ms |
19180 KB |
Output is correct |
17 |
Correct |
14 ms |
19180 KB |
Output is correct |
18 |
Correct |
14 ms |
19180 KB |
Output is correct |
19 |
Correct |
14 ms |
19180 KB |
Output is correct |
20 |
Correct |
14 ms |
19180 KB |
Output is correct |
21 |
Correct |
14 ms |
19180 KB |
Output is correct |
22 |
Correct |
15 ms |
19436 KB |
Output is correct |
23 |
Correct |
16 ms |
19180 KB |
Output is correct |
24 |
Correct |
14 ms |
19200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
19180 KB |
Output is correct |
2 |
Correct |
12 ms |
19180 KB |
Output is correct |
3 |
Correct |
12 ms |
19180 KB |
Output is correct |
4 |
Correct |
12 ms |
19180 KB |
Output is correct |
5 |
Correct |
14 ms |
19308 KB |
Output is correct |
6 |
Correct |
13 ms |
19180 KB |
Output is correct |
7 |
Correct |
15 ms |
19308 KB |
Output is correct |
8 |
Correct |
12 ms |
19180 KB |
Output is correct |
9 |
Correct |
12 ms |
19180 KB |
Output is correct |
10 |
Correct |
12 ms |
19180 KB |
Output is correct |
11 |
Correct |
12 ms |
19180 KB |
Output is correct |
12 |
Correct |
12 ms |
19180 KB |
Output is correct |
13 |
Correct |
13 ms |
19180 KB |
Output is correct |
14 |
Correct |
12 ms |
19180 KB |
Output is correct |
15 |
Correct |
13 ms |
19180 KB |
Output is correct |
16 |
Correct |
13 ms |
19180 KB |
Output is correct |
17 |
Correct |
14 ms |
19180 KB |
Output is correct |
18 |
Correct |
14 ms |
19180 KB |
Output is correct |
19 |
Correct |
14 ms |
19180 KB |
Output is correct |
20 |
Correct |
14 ms |
19180 KB |
Output is correct |
21 |
Correct |
14 ms |
19180 KB |
Output is correct |
22 |
Correct |
15 ms |
19436 KB |
Output is correct |
23 |
Correct |
16 ms |
19180 KB |
Output is correct |
24 |
Correct |
14 ms |
19200 KB |
Output is correct |
25 |
Correct |
37 ms |
19948 KB |
Output is correct |
26 |
Correct |
83 ms |
21128 KB |
Output is correct |
27 |
Correct |
238 ms |
23916 KB |
Output is correct |
28 |
Correct |
204 ms |
26728 KB |
Output is correct |
29 |
Correct |
168 ms |
23020 KB |
Output is correct |
30 |
Correct |
266 ms |
26984 KB |
Output is correct |
31 |
Correct |
360 ms |
26856 KB |
Output is correct |
32 |
Correct |
372 ms |
26856 KB |
Output is correct |
33 |
Correct |
49 ms |
20608 KB |
Output is correct |
34 |
Correct |
157 ms |
23148 KB |
Output is correct |
35 |
Correct |
209 ms |
26856 KB |
Output is correct |
36 |
Correct |
374 ms |
26728 KB |
Output is correct |
37 |
Correct |
306 ms |
26856 KB |
Output is correct |
38 |
Correct |
304 ms |
26728 KB |
Output is correct |