제출 #45089

#제출 시각아이디문제언어결과실행 시간메모리
45089nibnalin금 캐기 (IZhO14_divide)C++17
100 / 100
471 ms176768 KiB
#include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long int lli; const lli maxn = lli(1e5)+5, inf = lli(1e16)+5, maxv = lli(1e16)+10, offset = lli(1e16)+5; lli x[maxn], g[maxn], d[maxn]; struct ppnode { lli val; ppnode *l, *r; ppnode(lli _val = inf, ppnode* _l = NULL, ppnode* _r = NULL) { val = _val, l = _l, r = _r; } }; typedef ppnode* pnode; pnode root[maxn] = {NULL}; pnode upd(pnode root, lli L, lli R, lli a, lli v) { if(L == R) return new ppnode(min(root->val, v), NULL, NULL); else if(a <= (L+R)/2) return new ppnode(min(root->val, v), upd(root->l, L, (L+R)/2, a, v), root->r); else return new ppnode(min(root->val, v), root->l, upd(root->r, (L+R)/2+1, R, a, v)); } lli qry(pnode root, lli L, lli R, lli a, lli b) { if(a > R || b < L) return inf; else if(a <= L && R <= b) return root->val; else { lli res = inf; if(root->l) res = min(res, qry(root->l, L, (L+R)/2, a, b)); if(root->r) res = min(res, qry(root->r, (L+R)/2+1, R, a, b)); return res; } } int main(void) { lli n, res = 0; scanf("%lld", &n); for(lli i = 1;i <= n;i++) { scanf("%lld%lld%lld", &x[i], &g[i], &d[i]); g[i] += g[i-1], d[i] += d[i-1]; } root[0] = new ppnode(); root[0]->l = root[0]->r = root[0]; for(lli i = 1;i <= n;i++) { root[i] = upd(root[i-1], 0, maxv+offset, x[i]-d[i-1]+offset, g[i-1]); res = max(res, g[i]-qry(root[i], 0, maxv+offset, x[i]-d[i]+offset, maxv+offset)); } printf("%lld\n", res); }

컴파일 시 표준 에러 (stderr) 메시지

divide.cpp: In function 'int main()':
divide.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
divide.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x[i], &g[i], &d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...