版本比较
闲话
正文
增加 126 行删除 0 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127https://www.luogu.me/article/yqq5ndyb
https://www.luogu.me/article/ko0wj771
https://www.luogu.me/article/yqsyixog
https://www.luogu.me/article/r229355i
https://www.luogu.me/article/79pgcyp7
```cpp#include <bits/stdc++.h>#define int long long#define N 1000005using namespace std;int s[N],d[N];struct node{ int n,m,mp[5][5]; node() { memset(mp,0x3f,sizeof(mp)); } node (int x,int y) { n=x,m=y; memset(mp,0x3f,sizeof(mp)); } node operator *(const node&a) const { node res(n,a.m); for(int i=0;i<=n;i++) for(int k=0;k<=m;k++) for(int j=0;j<=a.m;j++) res.mp[i][j]=min(res.mp[i][j],mp[i][k]+a.mp[k][j]); return res; } void init() { memset(mp,0x3f,sizeof(mp)); for(int i=0;i<=n;i++) mp[i][i]=0; }};node tree[4*N];void update(int l,int r,int x,node y,int p){ if(l==r) { tree[p]=y; return; } int mid=(l+r)>>1; if(x<=mid) update(l,mid,x,y,p<<1); else update(mid+1,r,x,y,p<<1|1); tree[p]=tree[p<<1]*tree[p<<1|1];}int x;node query(int l,int r,int ansl,int ansr,int p){ if(ansl>ansr) { node t(x-1,x-1); t.init(); return t; } if(ansl<=l && ansr>=r) return tree[p]; int mid=(l+r)>>1; node t(x-1,x-1); t.init(); if(ansl<=mid) t=t*query(l,mid,ansl,ansr,p<<1); if(ansr>mid) t=t*query(mid+1,r,ansl,ansr,p<<1|1); return t;}node build(int i){ node res(x-1,x-1); for(int j=0;j<min(x,d[i]);j++) { for(int k=0;k<x;k++) { res.mp[j][k]=(d[i]+k-j-1)/x*s[i]; } } return res;} signed main(){ int n,q; cin>>n>>q>>x; for(int i=1;i<=n;i++) cin>>d[i]; for(int i=1;i<=n;i++) cin>>s[i]; for(int i=1;i<=n;i++) update(1,n,i,build(i),1); while(q--) { char op; int l,r; cin>>op>>l>>r; if(op=='1') { d[l]=l; update(1,n,l,build(l),1); } if(op=='2') { s[l]=r; update(1,n,l,build(l),1); } if(op=='?') { node a(x-1,0); for(int i=0;i<min(x,d[r]);i++) a.mp[i][0]=+(d[r]-i+x-2)/x*s[r]; a=query(1,n,l,r-1,1)*a; cout<<a.mp[0][0]<<endl; } }}```