Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <string>
  6. #include <set>
  7. #include <cstdio>
  8. #include <iomanip>
  9. #include <map>
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include <queue>
  13. #include <random>
  14. using namespace std;
  15. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  16.  
  17. int gcd(int a, int b) { return b ? a : gcd(b, a % b); }
  18.  
  19. int toNum(char s) {
  20. return s - 'a';
  21. }
  22.  
  23. const int INF = 1e10;
  24.  
  25. //#pragma GCC optimize("Ofast")
  26. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  27.  
  28. long long n,k,q,l,r;
  29. double mi;
  30. char kek;
  31. string quest;
  32. int a[100000];
  33.  
  34.  
  35.  
  36.  
  37. bool isPalindrom(int left, int right) {
  38. if (left == right)
  39. return 1;
  40. if ((right - left) % 2 == 0) {
  41. while (right - left != 2) {
  42. if (a[left] != a[right])
  43. return 0;
  44. left++;
  45. right--;
  46. }
  47. }
  48. else {
  49. while (right - left != 1) {
  50. if (a[left] != a[right])
  51. return 0;
  52. left++;
  53. right--;
  54. }
  55.  
  56. }
  57. return 1;
  58. }
  59.  
  60. void change(int left, int right, int z) {
  61. for (int i = left; i <= right; i++)
  62. a[i] = z;
  63. }
  64.  
  65. int main() {
  66. //freopen("sum.in", "r", stdin);
  67. //freopen("sum.out", "w", stdout);
  68.  
  69. IOS;
  70. cin >> n >> q;
  71. for (int i = 0; i < n; i++) {
  72. cin >> kek;
  73. a[i] = toNum(kek);
  74. }
  75. for (int i = 0; i < q; i++) {
  76. cin >> quest;
  77. if (quest == "ask") {
  78. cin >> l >> r;
  79. if (isPalindrom(l - 1, r - 1))
  80. cout << "YES" << "\n";
  81. else
  82. cout << "NO" << "\n";
  83. }
  84. else {
  85. cin >> l >> r >> kek;
  86. change(l - 1, r - 1, toNum(kek));
  87. }
  88. }
  89. return 0;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement