Submission #403891

#TimeUsernameProblemLanguageResultExecution timeMemory
403891FidiskSolar Storm (NOI20_solarstorm)C++14
0 / 100
439 ms246576 KiB
#include <bits/stdc++.h> using namespace std; #define oo 1e15 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; typedef pair<pair<long long,long long>,pair<long long,long long>> pllll; typedef pair<pair<long long,long long>,bool> pllb; const ll base=361; const ll mod=998244353; const ld eps=1e-5; const ll maxn=1e6; ll n,s,k,res,pos,sum[20][1000009],pre[1000009],a[1000009],ans; int g[20][1000009],r[1000009],l[1000009],v[1000009],p[1000009],i,j; ll calc(int x,int y) { ll kq=0; for (ll ii=19;ii>=0;ii--) { if (getbit(y,ii+1)==1) { kq+=sum[ii][x]; x=g[ii][x]; } } return kq; } void Trace(ll x,ll y) { if (y==s) { cout<<s<<'\n'; return; } if (x==n+1) { cout<<y<<'\n'; return; } Trace(r[p[x]]+1,y+1); cout<<p[x]<<' '; } int main(){ IO; cin>>n>>s>>k; for (i=1;i<n;i++) { cin>>a[i+1]; a[i+1]+=a[i]; } for (i=1;i<=n;i++) { cin>>v[i]; } for (i=n;i>0;i--) { ans=i; for (j=ans-1;j>0;j/=2) { while (ans-j>0&&a[ans-j]>=a[i]-k) { ans-=j; } } l[i]=ans; p[l[i]]=max(p[l[i]],i); } for (i=1;i<=n;i++) { ans=i; for (j=n;j>0;j/=2) { while (ans+j<=n&&a[ans+j]<=a[i]+k) { ans+=j; } } r[i]=ans; } for (i=1;i<=n;i++) { p[i]=max(p[i-1],p[i]); } for (i=1;i<=n;i++) { pre[i]=pre[i-1]+v[i]; } for (i=1;i<=n;i++) { g[0][i]=r[p[i]]+1; } g[0][n+1]=n+1; sum[0][n+1]=0; for (i=1;i<=n;i++) { sum[0][i]=pre[g[0][i]-1]-pre[i-1]; } for (i=1;i<=19;i++) { for (j=1;j<=n+1;j++) { g[i][j]=g[i-1][g[i-1][j]]; sum[i][j]=sum[i-1][j]+sum[i-1][g[i-1][j]]; } } //cout<<k<<'\n'; for (i=1;i<=n;i++) { ans=calc(i,s)-sum[1][i]+pre[r[p[i]]]-pre[l[p[i]]-1]; if (ans>res) { //cout<<ans<<' '<<res<<' '<<i<<' '<<p[i]<<'\n'; res=ans; pos=i; } } //cout<<res<<'\n'; Trace(pos,0); return 0; for (i=1;i<=n;i++) { cout<<a[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<p[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<l[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<r[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<pre[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<g[1][i]<<' '; } cout<<'\n'; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...