This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |