Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int mx=1e5+123;
- int n;
- int a[mx];
- int b[mx];
- int find_val(int p)
- {
- int l=1,r=n;
- while(l<=r)
- {
- int mid=(l+r)/2;
- if(p>=a[mid]&&p<=b[mid])
- {
- return mid;
- }
- else if(p<a[mid]) r=mid-1;
- else l=mid+1;
- }
- }
- int main()
- {
- cin>>n;
- vector<int>v(n);
- for(int i=1;i<=n;i++) cin>>v[i];
- int last=0;
- for(int i=1;i<=n;i++)
- {
- a[i]=last+1;
- b[i]=last+v[i];
- last=b[i];
- }
- int q;
- cin>>q;
- while(q--)
- {
- int p;
- cin>>p;
- cout<<find_val(p)<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement