제출 #885902

#제출 시각아이디문제언어결과실행 시간메모리
885902dimashhhBigger segments (IZhO19_segments)C++17
37 / 100
1550 ms5656 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1,MOD = 998244353; typedef long long ll; int n,a[N]; ll dp[N],mn[N],pref[N]; mt19937 rng(123321); struct node{ node *l = 0,*r = 0; ll mx,val,prior,key; node(ll key,ll val):key(key),val(val),mx(val),prior(rng()){} }; using pnode = node *; ll mx(pnode f){ return (f ? f->mx : 0); } void upd(pnode &f){ f->mx = max({f->val,mx(f->l),mx(f->r)}); } pnode merge(pnode a,pnode b){ if(!a) return b; if(!b) return a; if(a->prior >= b->prior){ a->r = merge(a->r,b); upd(a); return a; }else{ b->l = merge(a,b->l); upd(b); return b; } } pair<pnode,pnode> split(pnode x,int val){ if(!x) return {0,0}; if(x->val < val){ auto [a,b] = split(x->r,val); x->r = merge(x->r,a); upd(x); return {x,b}; }else{ auto [a,b] = split(x->l,val); x->l = merge(b,x->l); upd(x); return {a,x}; } } pnode root = NULL; void insert(ll key,ll val){ pnode nv = new node(key,val); auto [x,y] = split(root,key); root = merge(x,merge(nv,y)); } void test(){ cin >> n; for(int i = 1;i <= n;i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } // insert(0,0); for(int i = 1;i <=n;i++){ ll cur = 0; for(int j = i;j >= 1;j--){ if(mn[j - 1] + pref[j - 1] <= pref[i]){ if(dp[j - 1] + 1 > dp[i]){ dp[i] = dp[j - 1] +1; mn[i] = pref[i] - pref[j - 1]; break; } } } } cout << dp[n]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; test(); }

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

segments.cpp: In constructor 'node::node(ll, ll)':
segments.cpp:12:21: warning: 'node::key' will be initialized after [-Wreorder]
   12 |     ll mx,val,prior,key;
      |                     ^~~
segments.cpp:12:11: warning:   'll node::val' [-Wreorder]
   12 |     ll mx,val,prior,key;
      |           ^~~
segments.cpp:13:5: warning:   when initialized here [-Wreorder]
   13 |     node(ll key,ll val):key(key),val(val),mx(val),prior(rng()){}
      |     ^~~~
segments.cpp:12:11: warning: 'node::val' will be initialized after [-Wreorder]
   12 |     ll mx,val,prior,key;
      |           ^~~
segments.cpp:12:8: warning:   'll node::mx' [-Wreorder]
   12 |     ll mx,val,prior,key;
      |        ^~
segments.cpp:13:5: warning:   when initialized here [-Wreorder]
   13 |     node(ll key,ll val):key(key),val(val),mx(val),prior(rng()){}
      |     ^~~~
segments.cpp: In function 'void test()':
segments.cpp:63:12: warning: unused variable 'cur' [-Wunused-variable]
   63 |         ll cur = 0;
      |            ^~~
segments.cpp: In function 'int main()':
segments.cpp:80:9: warning: unused variable 'T' [-Wunused-variable]
   80 |     int T = 1;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...