제출 #515819

#제출 시각아이디문제언어결과실행 시간메모리
515819mosiashvililuka휴가 (IOI14_holiday)C++14
24 / 100
72 ms65540 KiB
#include"holiday.h" //#include "grader.h" #include<bits/stdc++.h> using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[100009],D,pas,jm,n,g[100009],LF[300009][3],RG[300009][3],RR,za,T[100009],l,r,z,k; map <int, int> M; map <int, int>::iterator IT; vector <long long> pr[270009]; vector <int> seg[270009],B[270009]; void upd(int q, int w, int rr){ if(q>w) return; int mid=(q+w)/2; B[rr].resize(seg[rr].size());pr[rr].resize(seg[rr].size()); for(int h=1; h<seg[rr].size(); h++) pr[rr][h]=pr[rr][h-1]+T[f[seg[rr][h]]]; if(q==w) return; seg[rr*2].push_back(0);seg[rr*2+1].push_back(0); for(int h=1; h<seg[rr].size(); h++){ if(f[seg[rr][h]]<=mid){ seg[rr*2].push_back(seg[rr][h]); B[rr][h]=B[rr][h-1]+1; }else{ seg[rr*2+1].push_back(seg[rr][h]); B[rr][h]=B[rr][h-1]; } } upd(q,mid,rr*2); upd(mid+1,w,rr*2+1); } void wv(){ M.clear(); for(i=1; i<=a; i++) M[f[i]]=1; zx=0; for(IT=M.begin(); IT!=M.end(); IT++){ zx++;M[(*IT).first]=zx;T[zx]=(*IT).first; } for(i=1; i<=a; i++) f[i]=M[f[i]]; /*cout<<"FF "; for(i=1; i<=a; i++) cout<<f[i]<<" "; cout<<"\n";cout<<"TT "; for(i=1; i<=a; i++) cout<<T[f[i]]<<" "; cout<<"\n";*/ // za=1; while(za<a) za*=2; for(i=0; i<=za*2; i++){ seg[i].clear();B[i].clear();pr[i].clear(); } seg[1].push_back(0); for(i=1; i<=a; i++){ seg[1].push_back(i); } upd(1,a,1); } void read(int q, int w, int rr, int L, int R){ if(L>R||q>w||k<=0) return; if(R==0||L==seg[rr].size()) return; //cout<<q<<" "<<w<<" "<<rr<<" "<<L<<" "<<R<<" "<<seg[rr].size()<<" "<<k<<"\n"; if(R-L+1<=k){ k-=R-L+1; z+=pr[rr][R]-pr[rr][L-1]; return; } if(q==w){ z+=T[q]*k; k=0; return; } read((q+w)/2+1,w,rr*2+1,((L-1)-B[rr][L-1])+1,R-B[rr][R]); read(q,(q+w)/2,rr*2,B[rr][L-1]+1,B[rr][R]); } void rec(int q, int w, int qq, int ww){ if(q>w) return; /*if(RR==1&&a==2){ cout<<q<<" "<<w<<" "<<qq<<" "<<ww<<"\n"; }*/ int mid=(q+w)/2,we=0; long long qw=0; for(int h=qq; h<=ww; h++){ k=mid-(h-1)*RR;z=0; if(k<=0) break; read(1,a,1,1,h); //cout<<h<<"\n"; if(qw<z){ qw=z;we=h; } } LF[mid][RR]=qw; //if(RR==1&&a==2) cout<<mid<<" "<<qw<<"\n"; rec(q,mid-1,qq,we); rec(mid+1,w,we,ww); } long long int findMaxAttraction(int Nn, int start, int Dd, int attraction[]) { n=Nn;start++;D=Dd;a=n; for(i=1; i<=n; i++){ g[i]=attraction[i-1];f[i]=g[i]; } /*for(i=1; i<=n; i++) M[g[i]]=1; zx=0; for(IT=M.begin(); IT!=M.end(); IT++){ zx++;M[(*IT).first]=zx;T[zx]=(*IT).first; } for(i=1; i<=n; i++) g[i]=M[g[i]];*/ /* for(i=1; i<=a; i++){ if(i-1>D) break; s.push(-f[i]);jm+=f[i]; //cout<<"+ "<<f[i]<<"\n"; while(s.size()>max(0LL,D-(i-1))){ jm-=-s.top(); //cout<<"- "<<-s.top()<<"\n"; s.pop(); } pas=max(pas,jm); }*/ /*for(i=1; i<=n; i++){ cout<<g[i]<<" "; } cout<<"\n"; for(i=1; i<=n; i++){ cout<<T[g[i]]<<" "; } cout<<"\n";*/ for(i=start; i<=n; i++){ f[i-start+1]=g[i]; } a=n-start+1;RR=1; wv(); rec(1,D,1,a); //return 0; RR=2; rec(1,D,1,a); for(i=1; i<=D; i++){ RG[i][1]=LF[i][1];RG[i][2]=LF[i][2]; LF[i][1]=LF[i][2]=0; } if(start!=1){ for(i=start-1; i>=1; i--){ f[start-1-i+1]=g[i]; } a=start-1;RR=1; wv(); /*for(i=1; i<=a; i++){ cout<<T[f[i]]<<" f "; } cout<<"\n";*/ rec(1,D,1,a); RR=2; rec(1,D,1,a); } // /*cout<<RG[4][2]<<" r\n"; cout<<LF[2][1]<<" l\n";*/ if(start==1) return RG[D][1]; pas=max(pas,RG[D][1]); for(i=0; i<=D; i++){ if(D-i-2>=0){ zx=LF[i][2]+RG[D-i-2][1]; pas=max(pas,zx); } if(D-i-1>=0){ zx=RG[i][2]+LF[D-i-1][1]; pas=max(pas,zx); } } return pas; }

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

holiday.cpp: In function 'void upd(int, int, int)':
holiday.cpp:14:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int h=1; h<seg[rr].size(); h++) pr[rr][h]=pr[rr][h-1]+T[f[seg[rr][h]]];
      |               ~^~~~~~~~~~~~~~~
holiday.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int h=1; h<seg[rr].size(); h++){
      |               ~^~~~~~~~~~~~~~~
holiday.cpp: In function 'void read(int, int, int, int, int)':
holiday.cpp:56:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  if(R==0||L==seg[rr].size()) return;
      |           ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...