이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.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(){
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;
}
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;
//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;
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();
rec(1,D,1,a);
RR=2;
rec(1,D,1,a);
}
//
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:13:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int h=1; h<seg[rr].size(); h++) pr[rr][h]=pr[rr][h-1]+T[f[seg[rr][h]]];
| ~^~~~~~~~~~~~~~~
holiday.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int h=1; h<seg[rr].size(); h++){
| ~^~~~~~~~~~~~~~~
holiday.cpp: In function 'void read(int, int, int, int, int)':
holiday.cpp:42:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(R==0||L==seg[rr].size()) return;
| ~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |