제출 #964680

#제출 시각아이디문제언어결과실행 시간메모리
964680Ahmed57휴가 (IOI14_holiday)C++17
100 / 100
682 ms6916 KiB
#include "holiday.h" #include "bits/stdc++.h" using namespace std; int ST , D , N; int L = -1 , R = -1; long long cur = 0; multiset<int> lrg,sml; long long ARR[200001]; long long ma = -1e18; void fix(int l,int r,int sz){ if(L==-1&&R==-1){ for(int i = l;i<=r;i++){ lrg.insert(ARR[i]); cur+=ARR[i]; } L = l; R = r; }else{ while(L>l){ L--; lrg.insert(ARR[L]); cur+=ARR[L]; } while(R<r){ R++; lrg.insert(ARR[R]); cur+=ARR[R]; } while(L<l){ auto it = lrg.lower_bound(ARR[L]); if(it!=lrg.end()&&(*it)==ARR[L]){ cur-=ARR[L]; lrg.erase(it); }else{ sml.erase(sml.lower_bound(ARR[L])); } L++; } while(R>r){ auto it = lrg.lower_bound(ARR[R]); if(it!=lrg.end()&&(*it)==ARR[R]){ cur-=ARR[R]; lrg.erase(it); }else{ sml.erase(sml.lower_bound(ARR[R])); } R--; } } while(sml.size()&&lrg.size()&&*(lrg.begin())<*(--sml.end())){ int a = (*lrg.begin()), b = *(--sml.end()); cur+=b-a; lrg.erase(lrg.begin()); sml.erase((--sml.end())); lrg.insert(b); sml.insert(a); } while(lrg.size()<sz&&sml.size()){ cur+=*(--sml.end()); lrg.insert(*(--sml.end())); sml.erase((--sml.end())); } while(lrg.size()>sz){ cur-=(*lrg.begin()); sml.insert(*(lrg.begin())); lrg.erase((lrg.begin())); } } void dc(int l,int r,int lq,int rq){ if(l>r)return ; int mid = (l+r)/2; long long ans = -1e18 ; int pos = -1; for(int i = lq;i<=rq;i++){ int di = D-min((ST-mid)*2+(i-ST),(i-ST)*2+(ST-mid)); if(di>=0){ fix(mid,i,di); if(ans<cur){ ans = cur; pos = i; } } } ma = max(ma,ans); dc(l,mid-1,lq,min(rq,pos)); dc(mid+1,r,max(lq,pos),rq); } long long findMaxAttraction(int n,int st,int d,int arr[]){ for(int i = 0;i<n;i++)ARR[i] = arr[i]; ST = st; D = d; N = n; dc(0,st,st,n); return ma; }

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

holiday.cpp: In function 'void fix(int, int, int)':
holiday.cpp:59:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |     while(lrg.size()<sz&&sml.size()){
      |           ~~~~~~~~~~^~~
holiday.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while(lrg.size()>sz){
      |           ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...