fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n,k;
  5. cin>>n;
  6. int a[n+1];
  7. long long pr[n+2]={0,};
  8. for(int i=1; i<=n; i++)
  9. cin>>a[i];
  10. cin>>k;
  11. for(int i=1; i<=k; i++)
  12. if(a[i]==0) pr[i]=pr[i-1]+1;
  13. else pr[i]=pr[i-1];
  14. for(int i=0; i<k; k--){
  15. int x,y;
  16. cin>>x>>y;
  17. cout<<pr[y]-pr[x-1]<<endl;
  18. }
  19. }
Success #stdin #stdout 0s 5220KB
stdin
3 3 2
1 2 3
4 5 6
7 8 9
2 2 3 3
1 1 2 3
stdout
0
15638256800