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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| #include <bits/stdc++.h> using namespace std;
typedef long long ll; typedef pair<int, int> pii; typedef unsigned long long ull; const ll inf = 1e18; const int N = 2e5 + 10; const int M = 1e6 + 10; const double eps = 1e-8; const int mod = 998244353;
#define fi first #define se second #define re register #define lowbit (-x&x) struct Tree { int l, r; int mi, tag; }t[N<<2]; int sum[N]; char s[N]; void push_up(int u) { t[u].mi = min(t[u<<1].mi, t[u<<1|1].mi); } void push_down(int u) { if (t[u].tag) { t[u<<1].mi += t[u].tag; t[u<<1|1].mi += t[u].tag; t[u<<1].tag += t[u].tag; t[u<<1|1].tag += t[u].tag; t[u].tag = 0; } } void build(int u, int l, int r) { t[u].l = l, t[u].r = r; t[u].mi = 1e9; if (l == r) { t[u].mi = sum[l]; return; } int mid = (l + r) >> 1; build(u<<1, l, mid); build(u<<1|1, mid+1, r); push_up(u); } void modify(int u, int ql, int qr, int val) { if (ql <= t[u].l && qr >= t[u].r) { t[u].mi += val; t[u].tag += val; return; } push_down(u); int mid = (t[u].l + t[u].r) >> 1; if (ql <= mid) modify(u<<1, ql, qr, val); if (qr > mid) modify(u<<1|1, ql, qr, val); push_up(u); } int query(int u, int ql, int qr) { if (ql <= t[u].l && qr >= t[u].r) return t[u].mi; push_down(u); int mid = (t[u].l + t[u].r) >> 1; int mi = 1e9; if (ql <= mid) mi = min(mi, query(u<<1, ql, qr)); if (qr > mid) mi = min(mi, query(u<<1|1, ql, qr)); return mi; } void solve() { int n, m; cin >> n >> m; cin >> (s + 1); for (int i = 1; i <= n; i++) { if (s[i] == '(') sum[i] = sum[i-1] + 1; else sum[i] = sum[i-1] - 1; } build(1, 0, n); for (int i = 1; i <= m; i++) { int opt, l, r; cin >> opt >> l >> r; if (opt == 1) { if (s[l] == '(' && s[r] == ')') { s[l] = ')'; s[r] = '('; modify(1, l, n, -2); modify(1, r, n, 2); } else if (s[l] == ')' && s[r] == '(') { s[l] = '('; s[r] = ')'; modify(1, l, n, 2); modify(1, r, n, -2); } } else { int pre = query(1, l - 1, l - 1); int lst = query(1, r, r); if (lst != pre || query(1, l, r) < pre) printf("No\n"); else printf("Yes\n"); } } }
signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef ACM_LOCAL freopen("input", "r", stdin); freopen("output", "w", stdout); #endif
#ifdef ACM_LOCAL auto start = clock(); #endif int t = 1;
while (t--) solve(); #ifdef ACM_LOCAL auto end = clock(); cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl; #endif return 0; }
|