Advertisement
MiinaMagdy

10324 - Zeros and Ones

Sep 3rd, 2022
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.     int No = 0;
  13.     char s[1000005];
  14.     while (scanf("%s", s)) {
  15.         if (int(strlen(s)) == 0) break;
  16.         int arr[1000005];
  17.         arr[0] = 0;
  18.         for (int i = 1; i <= int(strlen(s)); i++) {
  19.             arr[i] = 0;
  20.             arr[i] += arr[i - 1] + (s[i - 1] == '1');
  21.         }
  22.        
  23.         printf("Case %d:\n", ++No);
  24.         int q = 0;
  25.         scanf("%d", &q);
  26.         char res[2][5] = {"No", "Yes"};
  27.         while (q--) {
  28.             int i, j;
  29.             scanf("%d %d", &i, &j);
  30.             if (i > j) swap(i, j);
  31.             i++, j++;
  32.             printf("%s\n", res[arr[j] - arr[i - 1] == 0 || arr[j] - arr[i - 1] == j - i + 1]);
  33.         }
  34.         strcpy(s, (char*)"");
  35.     }
  36.    
  37. }
  38.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement