lina_os

Untitled

Feb 1st, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8. #include <vector>
  9. #include <stack>
  10.  
  11. using namespace std;
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  15. int t; cin >> t;
  16. while (t--) {
  17. string s; cin >> s;
  18. int n=s.length();
  19. int f=0;
  20. if (n>3) {
  21. for (int i=0; i<n-3; i++) {
  22. if (s.substr(i,4)=="1100") f++;
  23. }
  24. }
  25. int q; cin >> q;
  26. while (q--) {
  27. int y, x; cin >> y >> x; y--;
  28. if (n<4) cout << "NO" << endl;
  29. else if (n<10) {
  30. int no=1;
  31. for (int i=0; i<n-3; i++) {
  32. s[y]=x+'0';
  33. if (s.substr(i,4)=="1100") {
  34. cout << "YES" << endl;
  35. no=0;
  36. break;
  37. }
  38. }
  39. if (no) cout << "NO" << endl;
  40. }
  41. else {
  42. if (s.substr(y,4)=="1100" && y<n-3) f--;
  43. if (s.substr(y-1,4)=="1100" && y>0 && y<n-2) f--;
  44. if (s.substr(y-2,4)=="1100" && y>1 && y<n-1) f--;
  45. if (s.substr(y-3,4)=="1100" && y>2) f--;
  46. s[y]=x+'0';
  47. if (s.substr(y,4)=="1100" && y<n-3) f++;
  48. if (s.substr(y-1,4)=="1100" && y>0 && y<n-2) f++;
  49. if (s.substr(y-2,4)=="1100" && y>1 && y<n-1) f++;
  50. if (s.substr(y-3,4)=="1100" && y>2) f++;
  51.  
  52. if (f) cout << "YES" << endl;
  53. else cout << "NO" << endl;
  54. }
  55. }
  56. }
  57. return 0;
  58. }
  59.  
  60. /*
  61. */
  62.  
Advertisement
Add Comment
Please, Sign In to add comment