-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC. Anya and 1100.cpp
More file actions
69 lines (57 loc) · 1.55 KB
/
C. Anya and 1100.cpp
File metadata and controls
69 lines (57 loc) · 1.55 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
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
int q;
cin >> s >> q;
int n = s.size();
// Set to store starting indices of "1100"
set<int> indices;
// Function to check if "1100" starts at position `idx` in `s`
auto is1100 = [&](int idx) {
return idx >= 0 && idx + 3 < n && s.substr(idx, 4) == "1100";
};
// Initialize the set with all starting positions of "1100" in `s`
for (int i = 0; i + 3 < n; i++) {
if (is1100(i)) {
indices.insert(i);
}
}
// Process each query
for (int j = 0; j < q; j++) {
int i;
char x;
cin >> i >> x;
i--; // Convert to zero-based index
// Remove potential "1100" patterns in the affected range
for (int k = i - 3; k <= i; k++) {
if (is1100(k)) {
indices.erase(k);
}
}
// Update character in the string
s[i] = x;
// Re-check for "1100" patterns in the affected range
for (int k = i - 3; k <= i; k++) {
if (is1100(k)) {
indices.insert(k);
}
}
// Output result based on whether "1100" is present
if (!indices.empty()) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}