# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
723799 |
2023-04-14T10:25:47 Z |
kkts |
Pinball (JOI14_pinball) |
C++14 |
|
250 ms |
21992 KB |
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int tl[N], tr[N], M;
int getl(int id) {
int mn = 1e18;
for(id; id <= M; id += id & (-id)) mn = min(mn, tl[id]);
return mn;
}
int getr(int id) {
int mn = 1e18;
for(id; id >= 1; id -= id & (-id)) mn = min(mn, tr[id]);
return mn;
}
void updl(int id, int val) {
for(id; id >= 1; id -= id & (-id)) tl[id]= min(tl[id], val);
}
void updr(int id, int val) {
for(id; id <= M; id += id & (-id)) tr[id] = min(tr[id], val);
}
main(){
int m, n;
cin >> m >> n;
vector<int> a(m + 2), b(m + 2), c(m + 2), d(m + 2);
vector<int> x;
for(int i = 1; i <= m; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
x.push_back(a[i]);
x.push_back(b[i]);
x.push_back(c[i]);
}
x.push_back(1);
x.push_back(n);
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
M = x.size();
for(int i = 1; i <= M; i++) tl[i] = tr[i] = 1e18;
int ans = 1e18;
updl(1, 0);
updr(x.size(), 0);
for(int i = 1; i <= m; i++) {
a[i] = lower_bound(x.begin(), x.end(), a[i]) - x.begin() + 1;
b[i] = lower_bound(x.begin(), x.end(), b[i]) - x.begin() + 1;
c[i] = lower_bound(x.begin(), x.end(), c[i]) - x.begin() + 1;
int L = getl(a[i]), R = getr(b[i]);
ans = min(ans, L + R + d[i]);
updl(c[i], L + d[i]);
updr(c[i], R + d[i]);
}
cout << (ans == 1e18 ? -1 : ans);
}
Compilation message
pinball.cpp: In function 'long long int getl(long long int)':
pinball.cpp:11:9: warning: statement has no effect [-Wunused-value]
11 | for(id; id <= M; id += id & (-id)) mn = min(mn, tl[id]);
| ^~
pinball.cpp: In function 'long long int getr(long long int)':
pinball.cpp:16:9: warning: statement has no effect [-Wunused-value]
16 | for(id; id >= 1; id -= id & (-id)) mn = min(mn, tr[id]);
| ^~
pinball.cpp: In function 'void updl(long long int, long long int)':
pinball.cpp:20:9: warning: statement has no effect [-Wunused-value]
20 | for(id; id >= 1; id -= id & (-id)) tl[id]= min(tl[id], val);
| ^~
pinball.cpp: In function 'void updr(long long int, long long int)':
pinball.cpp:23:9: warning: statement has no effect [-Wunused-value]
23 | for(id; id <= M; id += id & (-id)) tr[id] = min(tr[id], val);
| ^~
pinball.cpp: At global scope:
pinball.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
448 KB |
Output is correct |
21 |
Correct |
2 ms |
404 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
448 KB |
Output is correct |
21 |
Correct |
2 ms |
404 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
396 KB |
Output is correct |
25 |
Correct |
18 ms |
1424 KB |
Output is correct |
26 |
Correct |
52 ms |
3520 KB |
Output is correct |
27 |
Correct |
147 ms |
8268 KB |
Output is correct |
28 |
Correct |
250 ms |
11248 KB |
Output is correct |
29 |
Correct |
110 ms |
6432 KB |
Output is correct |
30 |
Correct |
202 ms |
11352 KB |
Output is correct |
31 |
Correct |
234 ms |
12424 KB |
Output is correct |
32 |
Correct |
222 ms |
11668 KB |
Output is correct |
33 |
Correct |
37 ms |
3064 KB |
Output is correct |
34 |
Correct |
126 ms |
7372 KB |
Output is correct |
35 |
Runtime error |
169 ms |
21992 KB |
Execution killed with signal 11 |
36 |
Halted |
0 ms |
0 KB |
- |