#include<bits/stdc++.h>
using namespace std;
#define taskname "A"
#define pb push_back
#define mp make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 3e5 + 5;
struct IT{
ll s[maxn * 4];
IT(){fill_n(s,maxn*4,(ll)1e18);};
void update(int x , int l , int r , int id , ll val){
if(l == r){
s[x] = min(s[x] , val);
}else{
int mid = l + r >> 1;
if(id <= mid)update(x * 2 , l , mid , id , val);
else update(x * 2 + 1 , mid + 1 , r , id , val);
s[x] = min(s[x * 2] , s[x * 2 + 1]);
}
}
ll query(int x , int l , int r , int L , int R){
if(L > r || l > R)return (ll)1e18;
if(L <= l && r <= R){
return s[x];
}
int mid = l + r >> 1;
return min(query(x * 2 , l , mid , L , R) , query(x * 2 + 1 , mid + 1 , r , L , R));
}
}s[2];
int m , n , a[maxn] , b[maxn] , c[maxn] , d[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> m >> n;
vector<int> v;
for(int i = 1 ; i <= m ; ++i){
cin >> a[i] >> b[i] >> c[i] >> d[i];
v.pb(a[i]);v.pb(b[i]);v.pb(c[i]);
}
v.pb(1);
v.pb(n);
sort(v.begin(),v.end());
v.erase((unique(v.begin(),v.end())),v.end());
n = v.size();
s[0].update(1 , 1 , n , 1 , 0);
s[1].update(1 , 1 , n , n , 0);
ll res = (ll)1e18;
for(int i = 1 ; i <= m ; ++i){
int a = lower_bound(v.begin(),v.end(),::a[i]) - v.begin() + 1;
int b = lower_bound(v.begin(),v.end(),::b[i]) - v.begin() + 1;
int c = lower_bound(v.begin(),v.end(),::c[i]) - v.begin() + 1;
ll lef = s[0].query(1 , 1 , n , a , b);
ll rig = s[1].query(1 , 1 , n , a , b);
cerr << lef + rig + d[i] << endl;
// cerr << res << endl;
res = min(res , lef + rig + d[i]);
s[0].update(1 , 1 , n , c , lef + d[i]);
s[1].update(1 , 1 , n , c , rig + d[i]);
}
cout << ((res == (ll)1e18) ? -1ll : res);
}
Compilation message
pinball.cpp: In member function 'void IT::update(int, int, int, int, ll)':
pinball.cpp:23:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
pinball.cpp: In member function 'll IT::query(int, int, int, int, int)':
pinball.cpp:34:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:46:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".INP", "r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
pinball.cpp:47:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".OUT", "w",stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
19072 KB |
Output is correct |
2 |
Correct |
15 ms |
19072 KB |
Output is correct |
3 |
Correct |
15 ms |
19200 KB |
Output is correct |
4 |
Correct |
15 ms |
19200 KB |
Output is correct |
5 |
Correct |
14 ms |
19200 KB |
Output is correct |
6 |
Correct |
16 ms |
19200 KB |
Output is correct |
7 |
Correct |
16 ms |
19200 KB |
Output is correct |
8 |
Correct |
16 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
19072 KB |
Output is correct |
2 |
Correct |
15 ms |
19072 KB |
Output is correct |
3 |
Correct |
15 ms |
19200 KB |
Output is correct |
4 |
Correct |
15 ms |
19200 KB |
Output is correct |
5 |
Correct |
14 ms |
19200 KB |
Output is correct |
6 |
Correct |
16 ms |
19200 KB |
Output is correct |
7 |
Correct |
16 ms |
19200 KB |
Output is correct |
8 |
Correct |
16 ms |
19200 KB |
Output is correct |
9 |
Correct |
16 ms |
19200 KB |
Output is correct |
10 |
Correct |
16 ms |
19200 KB |
Output is correct |
11 |
Correct |
16 ms |
19200 KB |
Output is correct |
12 |
Correct |
15 ms |
19200 KB |
Output is correct |
13 |
Correct |
15 ms |
19200 KB |
Output is correct |
14 |
Correct |
16 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
19072 KB |
Output is correct |
2 |
Correct |
15 ms |
19072 KB |
Output is correct |
3 |
Correct |
15 ms |
19200 KB |
Output is correct |
4 |
Correct |
15 ms |
19200 KB |
Output is correct |
5 |
Correct |
14 ms |
19200 KB |
Output is correct |
6 |
Correct |
16 ms |
19200 KB |
Output is correct |
7 |
Correct |
16 ms |
19200 KB |
Output is correct |
8 |
Correct |
16 ms |
19200 KB |
Output is correct |
9 |
Correct |
16 ms |
19200 KB |
Output is correct |
10 |
Correct |
16 ms |
19200 KB |
Output is correct |
11 |
Correct |
16 ms |
19200 KB |
Output is correct |
12 |
Correct |
15 ms |
19200 KB |
Output is correct |
13 |
Correct |
15 ms |
19200 KB |
Output is correct |
14 |
Correct |
16 ms |
19200 KB |
Output is correct |
15 |
Correct |
16 ms |
19200 KB |
Output is correct |
16 |
Correct |
15 ms |
19176 KB |
Output is correct |
17 |
Correct |
16 ms |
19200 KB |
Output is correct |
18 |
Correct |
16 ms |
19200 KB |
Output is correct |
19 |
Correct |
16 ms |
19200 KB |
Output is correct |
20 |
Correct |
16 ms |
19200 KB |
Output is correct |
21 |
Correct |
16 ms |
19244 KB |
Output is correct |
22 |
Correct |
16 ms |
19200 KB |
Output is correct |
23 |
Correct |
16 ms |
19200 KB |
Output is correct |
24 |
Correct |
17 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
19072 KB |
Output is correct |
2 |
Correct |
15 ms |
19072 KB |
Output is correct |
3 |
Correct |
15 ms |
19200 KB |
Output is correct |
4 |
Correct |
15 ms |
19200 KB |
Output is correct |
5 |
Correct |
14 ms |
19200 KB |
Output is correct |
6 |
Correct |
16 ms |
19200 KB |
Output is correct |
7 |
Correct |
16 ms |
19200 KB |
Output is correct |
8 |
Correct |
16 ms |
19200 KB |
Output is correct |
9 |
Correct |
16 ms |
19200 KB |
Output is correct |
10 |
Correct |
16 ms |
19200 KB |
Output is correct |
11 |
Correct |
16 ms |
19200 KB |
Output is correct |
12 |
Correct |
15 ms |
19200 KB |
Output is correct |
13 |
Correct |
15 ms |
19200 KB |
Output is correct |
14 |
Correct |
16 ms |
19200 KB |
Output is correct |
15 |
Correct |
16 ms |
19200 KB |
Output is correct |
16 |
Correct |
15 ms |
19176 KB |
Output is correct |
17 |
Correct |
16 ms |
19200 KB |
Output is correct |
18 |
Correct |
16 ms |
19200 KB |
Output is correct |
19 |
Correct |
16 ms |
19200 KB |
Output is correct |
20 |
Correct |
16 ms |
19200 KB |
Output is correct |
21 |
Correct |
16 ms |
19244 KB |
Output is correct |
22 |
Correct |
16 ms |
19200 KB |
Output is correct |
23 |
Correct |
16 ms |
19200 KB |
Output is correct |
24 |
Correct |
17 ms |
19200 KB |
Output is correct |
25 |
Correct |
31 ms |
19584 KB |
Output is correct |
26 |
Correct |
66 ms |
20088 KB |
Output is correct |
27 |
Correct |
181 ms |
21228 KB |
Output is correct |
28 |
Correct |
152 ms |
22788 KB |
Output is correct |
29 |
Correct |
138 ms |
20988 KB |
Output is correct |
30 |
Correct |
184 ms |
22736 KB |
Output is correct |
31 |
Correct |
293 ms |
22768 KB |
Output is correct |
32 |
Correct |
250 ms |
26324 KB |
Output is correct |
33 |
Correct |
45 ms |
20600 KB |
Output is correct |
34 |
Correct |
132 ms |
22900 KB |
Output is correct |
35 |
Correct |
174 ms |
26352 KB |
Output is correct |
36 |
Correct |
298 ms |
26348 KB |
Output is correct |
37 |
Correct |
252 ms |
26352 KB |
Output is correct |
38 |
Correct |
260 ms |
26348 KB |
Output is correct |