Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using pii = pair<int, int>;
- constexpr int N = 1e5+1;
- constexpr int MOD = 1e9+7;
- constexpr int INF = 1e9+9;
- int n, q, ql, qr, qk, tr[26][4*N], temp[26], cp, ln;
- char ch;
- void push(int id, int i)
- {
- if (tr[i][id]!=-1)
- {
- tr[i][(id<<1)+1]=tr[i][id];
- tr[i][(id<<1)+2]=tr[i][id];
- tr[i][id] = -1;
- }
- }
- /*void build(int i, int id = 0, int l = 0, int r = n)
- {
- if (l==r)
- return;
- if (l+1==r)
- {
- tr[i][id]=arr[i][l];
- return;
- }
- int mid = (r+l)>>1;
- build(i, (id<<1)+1, l, mid);
- build(i, (id<<1)+2, mid, r);
- tr[i][id]=tr[i][(id<<1)+1]+tr[i][(id<<1)+2];
- }*/
- void upd(int i, int val, int l, int r, int id = 0, int cl = 0, int cr = n)
- {
- if (l>cr||r<cl||l==r)
- return;
- if (l==cl&&r==cr)
- {
- tr[i][id]=val;
- return;
- }
- push(id, i);
- int mid = (cl+cr)>>1;
- upd(i, val, max(l,cl), min(r, mid), (id<<1)+1, cl, mid);
- upd(i, val, max(mid,l), min(r, cr), (id<<1)+2, mid, cr);
- }
- int get(int i, int l, int r, int id = 0, int cl = 0, int cr = n)
- {
- if (l>cr||r<cl||l==r)
- return 0;
- if (tr[i][id]!=-1)
- return (r-l)*tr[i][id];
- int mid = (cl+cr)>>1;
- return get(i, max(l, cl), min(r, mid), (id<<1)+1, cl, mid)+
- get(i, max(l, mid), min(r, cr), (id<<1)+2, mid, cr);
- }
- int get_sum(int i, int l, int r)
- {
- l--;
- return get(i, l, r);
- }
- int close(int n)
- {
- int res = 1;
- while(res<n)
- {
- res<<=1;
- }
- return res;
- }
- void Solve()
- {
- cin >> n >> q;
- ln=n;
- n=close(n);
- for (int i = 0; i < ln; i++)
- {
- cin>>ch;
- upd(ch-'a', 1, i, i+1);
- }
- while(q--)
- {
- cin >> ql >> qr >> qk;
- cp = ql-1;
- for (int i = 0; i < 26; i++)
- {
- temp[i] = get_sum(i, ql, qr);
- upd(i, 0, ql-1, qr);
- }
- if (qk)
- {
- for (int i = 0; i < 26; i++)
- {
- upd(i, 1, cp, cp+temp[i]);
- cp+=temp[i];
- }
- }
- else
- {
- for (int i = 25; i >= 0; i--)
- {
- upd(i, 1, cp, cp+temp[i]);
- cp+=temp[i];
- }
- }
- }
- for (int i = 1; i <= n; i++)
- {
- for (int j = 0; j < 26; j++)
- {
- if (get_sum(j, i, i)==1)
- {
- cout << static_cast<char>('a'+j);
- break;
- }
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement