Advertisement
abdelrahman_orief

Untitled

Apr 26th, 2020
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(0);
  12.     cout.tie(0);
  13.  
  14.     int n;
  15.     cin>>n;
  16.     int arr[n];
  17.     int cnt=0;
  18.     for (int i=0;i<n;i++)
  19.     {
  20.         int a;
  21.         cin>>a;
  22.         if (a==1)
  23.         {
  24.             cnt++;
  25.             arr[i]=cnt;
  26.         }
  27.         else
  28.             arr[i]=0;
  29.     }
  30.     int q;
  31.     cin>>q;
  32.  
  33.     for (int i=0;i<q;i++)
  34.     {
  35.         int l, r;
  36.         cin>>l>>r;
  37.         if (arr[l-1]==0||arr[r-1]==0)
  38.             cout<<0<<endl;
  39.         else
  40.         {
  41.             if (arr[r-1]-arr[l-1]==r-l)
  42.                 cout<<1<<endl;
  43.             else
  44.                 cout<<0<<endl;
  45.         }
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement