Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33154 hi_hi 【J】T3 C++ 解答错误 0 365 MS 776 KB 1251 2024-10-04 16:05:24

Tests(0/10):


#include<bits/stdc++.h> using namespace std; const int N=100100; int idx=0; struct node{ int z,c; }a[N]; struct kk{ int z,h; }; int d[N]; int n,q; bool b[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>q; int w; for(int i=1;i<=n;i++){ cin>>w; while(idx&&a[idx].z>=w) idx--; a[++idx].z=w; a[idx].c=i; //cout<<idx<<" "<<a[idx].c<<" "; } while(q--){ int x,y; cin>>x>>y; if(x<=y){ printf("0\n"); continue; } queue<int> q; q.push(x); memset(d,0x3f,sizeof d); memset(b,0,sizeof b); d[x]=0; b[x]=1; int ans=0x3f3f3f; while(!q.empty()){ int z=q.front(); q.pop(); b[z]=0; for(int i=1;i<=idx;i++){ if(d[z/a[i].c]>d[z]+a[i].z){ d[z/a[i].c]=d[z]+a[i].z; if(!b[z/a[i].c]){ q.push(z/a[i].c); b[z/a[i].c]=1; } } } if(z<=y) ans=min(ans,d[z]); } cout<<ans<<"\n"; } }


测评信息: