题解 | 音符

音符

https://www.nowcoder.com/practice/fbef4a433583436cbf1a7861a5c110d7

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;


ll b[N];
ll pres[N];

void solve(){
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        pres[i] = pres[i-1]+b[i];
    }

    while(q--)
    {
        ll t;
        cin>>t;
        int ans = upper_bound(pres+1,pres+1+n,t)-pres;
        cout<<ans<<'\n';

    }


    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--) 
    {
        solve();
    }
    return 0;
}

二分模板题

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务