Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33139 | hi_hi | 【J】T3 | C++ | 运行超时 | 50 | 1000 MS | 1068 KB | 940 | 2024-10-04 15:16:23 |
#include<bits/stdc++.h> using namespace std; int n,T,x,y; int dis[100005],vis[100005],nmin,top; struct ss{ int id,v; }b[100005]; struct sss{ int v,w; }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); scanf("%d%d",&n,&T); for(int i=1;i<=n;i++){ int w; scanf("%d",&w); while(top && b[top].v>=w)top--; b[++top].id=i; b[top].v=w; } while(T--){ nmin=0x3f3f3f3f; scanf("%d%d",&x,&y); for(int i=0;i<=x;i++){ dis[i]=0x3f3f3f3f; } if(x<=y){ printf("0\n"); continue; } queue<int>q; dis[x]=0,vis[x]=1,q.push(x); while(!q.empty()){ int now=q.front(); q.pop(),vis[now]=0; for(int i=1;i<=top;i++){ int nv=now/b[i].id; if(dis[nv]>dis[now]+b[i].v){ dis[nv]=dis[now]+b[i].v; if(vis[nv]==0){ vis[nv]=1; q.push(nv); } } } if(now<=y)nmin=min(nmin,dis[now]); } printf("%d\n",nmin); } }