音乐节拍
1122. 音乐节拍 (Standard IO)
时间限制: 1000 ms 空间限制: 262144 KB 具体限制
答案如下:↓↓↓
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<ctime> 5 #include<algorithm> 6 #include<cmath> 7 using namespace std; 8 #define debug(x) cerr<<#x<<'='<<x<<endl 9 #define MAXN 654321 10 11 int N,Q; 12 int A[MAXN]; 13 int s,y,l,v,a; 14 15 void binary_chop(int low,int high,int y){ 16 while (low<high){ 17 int mid=(low+high)/2; 18 if (A[mid]>=y) high=mid; 19 else low=mid+1; 20 } 21 cout<<low<<endl; 22 } 23 int main(){ 24 cin>>N>>Q; 25 cin>>s; 26 A[1]=s-1; 27 for (int i=2;i<=N;i++){ 28 scanf("%d",&s); 29 A[i]=s+A[i-1]; 30 } 31 for (int j=1;j<=Q;j++){ 32 scanf("%d",&y); 33 binary_chop(1,N,y); 34 } 35 return 0; 36 } 37 38