Submission #105501

#TimeUsernameProblemLanguageResultExecution timeMemory
105501onjo0127Pinball (JOI14_pinball)C++11
100 / 100
323 ms14260 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL * 1e18; vector<int> S; int A[100009], B[100009], C[100009], D[100009]; long long lm[100009], rm[100009]; struct segtree { vector<long long> T; segtree(int N) { T.resize(4*N, 0); } void upd(int idx, int s, int e, int x, long long y) { if(x < s || e < x) return; if(s == e) { T[idx] = y; return; } int m = s+e >> 1; upd(idx*2, s, m, x, y); upd(idx*2+1, m+1, e, x, y); T[idx] = min(T[idx*2], T[idx*2+1]); } long long mn(int idx, int s, int e, int l, int r) { if(r < s || e < l) return INF; if(l <= s && e <= r) return T[idx]; int m = s+e >> 1; return min(mn(idx*2, s, m, l, r), mn(idx*2+1, m+1, e, l, r)); } }; int main() { int M, N; scanf("%d%d",&M,&N); for(int i=1; i<=M; i++) { scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]); S.push_back(C[i]); } S.push_back(1); S.push_back(N); sort(S.begin(), S.end()); S.resize(unique(S.begin(), S.end()) - S.begin()); long long ans = INF; int sz = S.size(); segtree lseg(sz), rseg(sz); for(int i=1; i<sz; i++) {lseg.upd(1, 0, sz-1, i, INF); lm[i] = INF;} for(int i=0; i<sz-1; i++) {rseg.upd(1, 0, sz-1, i, INF); rm[i] = INF;} for(int i=1; i<=M; i++) { int l = lower_bound(S.begin(), S.end(), A[i]) - S.begin(); int r = lower_bound(S.begin(), S.end(), B[i]+1) - S.begin() - 1; int x = lower_bound(S.begin(), S.end(), C[i]) - S.begin(); long long lmn = lseg.mn(1, 0, sz-1, l, r); long long rmn = rseg.mn(1, 0, sz-1, l, r); ans = min(ans, lmn + rmn + D[i]); lm[x] = min(lm[x], lmn + D[i]); rm[x] = min(rm[x], rmn + D[i]); lseg.upd(1, 0, sz-1, x, lm[x]); rseg.upd(1, 0, sz-1, x, rm[x]); } if(ans == INF) puts("-1"); else printf("%lld", ans); return 0; }

Compilation message (stderr)

pinball.cpp: In member function 'void segtree::upd(int, int, int, int, long long int)':
pinball.cpp:21:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = s+e >> 1;
                 ~^~
pinball.cpp: In member function 'long long int segtree::mn(int, int, int, int, int)':
pinball.cpp:29:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = s+e >> 1;
                 ~^~
pinball.cpp: In function 'int main()':
pinball.cpp:35:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int M, N; scanf("%d%d",&M,&N);
               ~~~~~^~~~~~~~~~~~~~
pinball.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d",&A[i],&B[i],&C[i],&D[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...