-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10324.cpp
More file actions
70 lines (67 loc) · 2 KB
/
Copy path10324.cpp
File metadata and controls
70 lines (67 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Author: btjanaka (Bryon Tjanaka)
// Problem: (UVa) 10324
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORe(i, a, b) for (int i = a; i <= b; ++i)
#define PAI(arr, len) /*Print array of integers*/ \
{ \
for (int _i = 0; _i < len; ++_i) { \
if (_i != len - 1) { \
printf("%d ", arr[_i]); \
} else { \
printf("%d", arr[_i]); \
} \
} \
putchar('\n'); \
}
#define PBS(n, len) /*Print a bitset*/ \
{ \
for (int _i = 0; _i < len; ++_i) { \
putchar(n % 2 + '0'); \
n /= 2; \
} \
putchar('\n'); \
}
#define GET(x) scanf("%d", &x)
#define PLN putchar('\n')
#define INF 2147483647
typedef long long ll;
using namespace std;
// Each index holds the sum of all the numbers in the original bit string up to
// and including that index.
int cum_sum[1001000];
int main() {
for (int cas = 1;; ++cas) {
// Get string
int len = 0;
char ch;
while ((ch = getchar()) != EOF && ch != '\n') {
if (len == 0) {
cum_sum[len++] = ch - '0';
} else {
cum_sum[len] = ch - '0' + cum_sum[len - 1];
++len;
}
}
if (len == 0) break;
// Process queries
printf("Case %d:\n", cas);
int n;
GET(n);
int i, j, t1, t2;
FOR(k, 0, n) {
scanf("%d %d", &t1, &t2);
i = min(t1, t2);
j = max(t1, t2);
int lo_sum = i == 0 ? 0 : cum_sum[i - 1];
int hi_sum = cum_sum[j];
if (hi_sum - lo_sum == 0 || hi_sum - lo_sum == j - i + 1) {
printf("Yes\n");
} else {
printf("No\n");
}
}
getchar(); // Stray newline
}
return 0;
}