#include <bits/stdc++.h>
using namespace std;
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
struct device { int a,b,c,d; };
device devices[100000];
vi lines;
LLI tree1[1 << 20],tree2[1 << 20];
LLI query(int s,int e,int qs,int qe,int i,LLI *tree) {
if ((s > qe) || (e < qs)) return MAX_VAL_2;
else if ((s >= qs) && (e <= qe)) return tree[i];
int mid = (s+e) / 2;
return min(query(s,mid,qs,qe,2*i+1,tree),query(mid+1,e,qs,qe,2*i+2,tree));
}
LLI update(int s,int e,int ai,int i,LLI num,LLI *tree) {
if ((s > ai) || (e < ai)) return tree[i];
else if (s == e) {
tree[i] = min(tree[i],num);
return tree[i];
}
int mid = (s+e) / 2;
tree[i] = min(update(s,mid,ai,2*i+1,num,tree),update(mid+1,e,ai,2*i+2,num,tree));
return tree[i];
}
int main() {
int i;
int M,N;
scanf("%d %d",&M,&N);
for (i = 0; i < M; i++) {
scanf("%d %d %d %d",&devices[i].a,&devices[i].b,&devices[i].c,&devices[i].d);
lines.push_back(devices[i].a),lines.push_back(devices[i].b),lines.push_back(devices[i].c);
}
lines.push_back(1),lines.push_back(N);
sort(lines.begin(),lines.end());
lines.resize(unique(lines.begin(),lines.end())-lines.begin());
LLI m = MAX_VAL_2;
fill(tree1,tree1+(1 << 20),MAX_VAL_2);
fill(tree2,tree2+(1 << 20),MAX_VAL_2);
update(0,lines.size()-1,0,0,0,tree1);
update(0,lines.size()-1,lines.size()-1,0,0,tree2);
for (i = 0; i < M; i++) {
devices[i].a = lower_bound(lines.begin(),lines.end(),devices[i].a)-lines.begin();
devices[i].b = lower_bound(lines.begin(),lines.end(),devices[i].b)-lines.begin();
devices[i].c = lower_bound(lines.begin(),lines.end(),devices[i].c)-lines.begin();
LLI l = query(0,lines.size()-1,devices[i].a,devices[i].b,0,tree1);
LLI r = query(0,lines.size()-1,devices[i].a,devices[i].b,0,tree2);
update(0,lines.size()-1,devices[i].c,0,l+devices[i].d,tree1);
update(0,lines.size()-1,devices[i].c,0,r+devices[i].d,tree2);
m = min(m,l+r+devices[i].d);
}
if (m < MAX_VAL_2) printf("%lld\n",m);
else printf("-1\n");
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&M,&N);
~~~~~^~~~~~~~~~~~~~~
pinball.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d",&devices[i].a,&devices[i].b,&devices[i].c,&devices[i].d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
16760 KB |
Output is correct |
2 |
Correct |
15 ms |
16760 KB |
Output is correct |
3 |
Correct |
14 ms |
16808 KB |
Output is correct |
4 |
Correct |
17 ms |
16892 KB |
Output is correct |
5 |
Correct |
14 ms |
16900 KB |
Output is correct |
6 |
Correct |
15 ms |
16904 KB |
Output is correct |
7 |
Correct |
17 ms |
16924 KB |
Output is correct |
8 |
Correct |
16 ms |
16924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
16760 KB |
Output is correct |
2 |
Correct |
15 ms |
16760 KB |
Output is correct |
3 |
Correct |
14 ms |
16808 KB |
Output is correct |
4 |
Correct |
17 ms |
16892 KB |
Output is correct |
5 |
Correct |
14 ms |
16900 KB |
Output is correct |
6 |
Correct |
15 ms |
16904 KB |
Output is correct |
7 |
Correct |
17 ms |
16924 KB |
Output is correct |
8 |
Correct |
16 ms |
16924 KB |
Output is correct |
9 |
Correct |
17 ms |
16980 KB |
Output is correct |
10 |
Correct |
17 ms |
16988 KB |
Output is correct |
11 |
Correct |
16 ms |
16996 KB |
Output is correct |
12 |
Correct |
20 ms |
17040 KB |
Output is correct |
13 |
Correct |
18 ms |
17052 KB |
Output is correct |
14 |
Correct |
13 ms |
17148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
16760 KB |
Output is correct |
2 |
Correct |
15 ms |
16760 KB |
Output is correct |
3 |
Correct |
14 ms |
16808 KB |
Output is correct |
4 |
Correct |
17 ms |
16892 KB |
Output is correct |
5 |
Correct |
14 ms |
16900 KB |
Output is correct |
6 |
Correct |
15 ms |
16904 KB |
Output is correct |
7 |
Correct |
17 ms |
16924 KB |
Output is correct |
8 |
Correct |
16 ms |
16924 KB |
Output is correct |
9 |
Correct |
17 ms |
16980 KB |
Output is correct |
10 |
Correct |
17 ms |
16988 KB |
Output is correct |
11 |
Correct |
16 ms |
16996 KB |
Output is correct |
12 |
Correct |
20 ms |
17040 KB |
Output is correct |
13 |
Correct |
18 ms |
17052 KB |
Output is correct |
14 |
Correct |
13 ms |
17148 KB |
Output is correct |
15 |
Correct |
15 ms |
17148 KB |
Output is correct |
16 |
Correct |
17 ms |
17148 KB |
Output is correct |
17 |
Correct |
18 ms |
17248 KB |
Output is correct |
18 |
Correct |
22 ms |
17248 KB |
Output is correct |
19 |
Correct |
20 ms |
17268 KB |
Output is correct |
20 |
Correct |
18 ms |
17308 KB |
Output is correct |
21 |
Correct |
17 ms |
17476 KB |
Output is correct |
22 |
Correct |
20 ms |
17476 KB |
Output is correct |
23 |
Correct |
16 ms |
17476 KB |
Output is correct |
24 |
Correct |
18 ms |
17476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
16760 KB |
Output is correct |
2 |
Correct |
15 ms |
16760 KB |
Output is correct |
3 |
Correct |
14 ms |
16808 KB |
Output is correct |
4 |
Correct |
17 ms |
16892 KB |
Output is correct |
5 |
Correct |
14 ms |
16900 KB |
Output is correct |
6 |
Correct |
15 ms |
16904 KB |
Output is correct |
7 |
Correct |
17 ms |
16924 KB |
Output is correct |
8 |
Correct |
16 ms |
16924 KB |
Output is correct |
9 |
Correct |
17 ms |
16980 KB |
Output is correct |
10 |
Correct |
17 ms |
16988 KB |
Output is correct |
11 |
Correct |
16 ms |
16996 KB |
Output is correct |
12 |
Correct |
20 ms |
17040 KB |
Output is correct |
13 |
Correct |
18 ms |
17052 KB |
Output is correct |
14 |
Correct |
13 ms |
17148 KB |
Output is correct |
15 |
Correct |
15 ms |
17148 KB |
Output is correct |
16 |
Correct |
17 ms |
17148 KB |
Output is correct |
17 |
Correct |
18 ms |
17248 KB |
Output is correct |
18 |
Correct |
22 ms |
17248 KB |
Output is correct |
19 |
Correct |
20 ms |
17268 KB |
Output is correct |
20 |
Correct |
18 ms |
17308 KB |
Output is correct |
21 |
Correct |
17 ms |
17476 KB |
Output is correct |
22 |
Correct |
20 ms |
17476 KB |
Output is correct |
23 |
Correct |
16 ms |
17476 KB |
Output is correct |
24 |
Correct |
18 ms |
17476 KB |
Output is correct |
25 |
Correct |
37 ms |
18128 KB |
Output is correct |
26 |
Correct |
105 ms |
19500 KB |
Output is correct |
27 |
Correct |
304 ms |
23352 KB |
Output is correct |
28 |
Correct |
198 ms |
27824 KB |
Output is correct |
29 |
Correct |
167 ms |
28408 KB |
Output is correct |
30 |
Correct |
259 ms |
33680 KB |
Output is correct |
31 |
Correct |
357 ms |
37564 KB |
Output is correct |
32 |
Correct |
375 ms |
41484 KB |
Output is correct |
33 |
Correct |
57 ms |
41484 KB |
Output is correct |
34 |
Correct |
183 ms |
42720 KB |
Output is correct |
35 |
Correct |
252 ms |
47956 KB |
Output is correct |
36 |
Correct |
457 ms |
51832 KB |
Output is correct |
37 |
Correct |
368 ms |
55692 KB |
Output is correct |
38 |
Correct |
417 ms |
59500 KB |
Output is correct |