Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin>>n;
- int arr[n];
- int cnt=0;
- for (int i=0;i<n;i++)
- {
- int a;
- cin>>a;
- if (a==1)
- {
- cnt++;
- arr[i]=cnt;
- }
- else
- arr[i]=0;
- }
- int q;
- cin>>q;
- for (int i=0;i<q;i++)
- {
- int l, r;
- cin>>l>>r;
- if (arr[l-1]==0||arr[r-1]==0)
- cout<<0<<endl;
- else
- {
- if (arr[r-1]-arr[l-1]==r-l)
- cout<<1<<endl;
- else
- cout<<0<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement