标签:xom ast asm asmb bgp jsb dsl any style
分析
RMQ不解释咯
#include <iostream> #include <cstdio> #include <cmath> using namespace std; const int N=1e5+10; const int M=41; struct Structure { int to; long long sm,mn; }f[N][M]; int n; long long k; int main() { scanf("%d%lld",&n,&k); for (int i=0;i<n;i++) for (int j=0;j<=40;j++) f[i][j].mn=2147483647; for (int i=0;i<n;i++) scanf("%d",&f[i][0].to); for (int i=0;i<n;i++) scanf("%lld",&f[i][0].sm),f[i][0].mn=f[i][0].sm; for (int j=1;j<=log(k)/log(2)+1;j++) for (int i=0;i<n;i++) { f[i][j].to=f[f[i][j-1].to][j-1].to; f[i][j].sm=f[i][j-1].sm+f[f[i][j-1].to][j-1].sm; f[i][j].mn=min(f[i][j-1].mn,f[f[i][j-1].to][j-1].mn); } for (int i=0;i<n;i++) { long long k1=k,anss=0,ansm=2147483647; int now=i; for (int j=0;k1;j++,k1>>=1) if (k1&1) { anss+=f[now][j].sm; ansm=min(ansm,f[now][j].mn); now=f[now][j].to; } printf("%lld %lld\n",anss,ansm); } }
标签:xom ast asm asmb bgp jsb dsl any style
原文地址:https://www.cnblogs.com/mastervan/p/9787887.html