Discription

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.

Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively.

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n).

Output

Output one line, the string S after applying the queries.

Example

Input
10 5abacdabcda7 10 05 8 11 4 03 6 07 10 1

Output
cbcaaaabdd

Input
10 1agjucbvdfk1 10 1

Output
abcdfgjkuv

Note

First sample test explanation:

大概是第一次坐到沙发hhh

可以发现只有26个小写英文,那么就不难了,就是一个常数*26的带标记线段树。。。

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn 100005
using namespace std;
struct node{int sum[28];int tag;node operator +(const node& u)const{node r; r.tag=0;for(int i=1;i<27;i++) r.sum[i]=sum[i]+u.sum[i];return r;}
}a[maxn<<2|1];
int le,ri,opt,w;
int n,m,v,num[30];
char s[maxn];void build(int o,int l,int r){if(l==r){a[o].sum[s[l]-'a'+1]++;return;}int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;build(lc,l,mid),build(rc,mid+1,r);a[o]=a[lc]+a[rc];
}inline void tol(int o,int tmp,int len){memset(a[o].sum,0,sizeof(a[o].sum));a[o].sum[tmp]=len;a[o].tag=tmp;
}inline void pushdown(int o,int l,int r){if(a[o].tag){int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;tol(lc,a[o].tag,mid-l+1);tol(rc,a[o].tag,r-mid);a[o].tag=0;}
}void update(int o,int l,int r){if(l>=le&&r<=ri){tol(o,v,r-l+1);return;}pushdown(o,l,r);int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;if(le<=mid) update(lc,l,mid);if(ri>mid) update(rc,mid+1,r);a[o]=a[lc]+a[rc];
}int query(int o,int l,int r){if(l>=le&&r<=ri) return a[o].sum[v];pushdown(o,l,r);int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1,an=0;if(le<=mid) an+=query(lc,l,mid);if(ri>mid) an+=query(rc,mid+1,r);return an;
}void print(int o,int l,int r){if(l==r){for(int i=1;i<27;i++) if(a[o].sum[i]){putchar(i-1+'a');break;}return;}pushdown(o,l,r);int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;print(lc,l,mid);print(rc,mid+1,r);
}int main(){scanf("%d%d",&n,&m);scanf("%s",s+1);build(1,1,n);  while(m--){scanf("%d%d%d",&le,&ri,&opt);memset(num,0,sizeof(num));for(v=1;v<=26;v++) num[v]=query(1,1,n);if(opt){int pre=le,nxt;for(int i=1;i<=26;i++) if(num[i]){nxt=pre+num[i]-1,v=i;le=pre,ri=nxt;update(1,1,n);pre=nxt+1;}}else{int pre=le,nxt;for(int i=26;i;i--) if(num[i]){nxt=pre+num[i]-1,v=i;le=pre,ri=nxt;update(1,1,n);pre=nxt+1;}            }
//      print(1,1,n);}print(1,1,n);return 0;
}

  

转载于:https://www.cnblogs.com/JYYHH/p/8407093.html

Codeforces 558E A Simple Task相关推荐

  1. codeforces 558E A Simple Task 线段树

    题目链接 题意较为简单. 思路: 由于仅仅有26个字母,所以用26棵线段树维护就好了,比較easy. #include <iostream> #include <string> ...

  2. Codeforces J. A Simple Task(多棵线段树)

    题目描述: Description This task is very simple. Given a string S of length n and q queries each query is ...

  3. CodeForces - 11D A Simple Task

    Discription Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycl ...

  4. CF-558E(E. A Simple Task)

    CF-558E(E. A Simple Task) 题目链接 题意 长度为NNN的串,给qqq次修改每次修改给出一个区间[L,R][L,R][L,R],你需要将区间的字符按照升序或降序排列.输出qqq ...

  5. CF558E A Simple Task 线段树

    题解: 这种题之前做过一个类似的题目,也是关于选择区间然后给区间进行排序. 这种题用线段树把排序转换成区间修改区间求和即可. 类似的题目:https://vjudge.net/problem/HDU- ...

  6. 使用tensorflow预测函数的参数值(a simple task)

    已知x1,x2,x3,y 根据y = aax1 + bbx2 + abx3 预测参数a和b import tensorflow as tf import numpy as npx1_data = np ...

  7. CF11D-A Simple Task【状压dp】

    正题 题目链接:https://www.luogu.com.cn/problem/CF11D 题目大意 给出nnn个点mmm条边的一张简单无向图,求它的简单环的个数. 1≤n≤191\leq n\le ...

  8. CF11D A Simple Task(状压DP)

    \(solution:\) 思路大家应该都懂: 状压DP:\(f[i][j]\),其中 \(i\) 这一维是需要状压的,用来记录19个节点每一个是否已经走过(走过为 \(1\) ,没走为 \(0\) ...

  9. codeforces 590D Top Secret Task(dp)

    状态:f [ i ][ j ]表示前i个点换了j次的最小和 转移:用f [ i ][ j ]更新f [ i+1 ][ j+k-i-1](k为i后一点) #include<stdio.h> ...

最新文章

  1. lucene底层数据结构——FST,针对field使用列存储,delta encode压缩doc ids数组,LZ4压缩算法...
  2. Linux下为文件增加列的shell脚本
  3. python缩进的用途和使用方法_如何用Python减少循环层次和缩进的技巧
  4. Python之函数的收集参数和分配参数用法(‘*’ 和 ‘**’)
  5. Matrix-Tree (生成树计数)
  6. DISCUZ开启设计插件功能和显示嵌入点功能
  7. 两万字长文读懂 Java 集合!
  8. 数组去重和两个数组求交集
  9. 【开发工具】Window下MinGW下载安装gcc,g++编译器
  10. 基于51单片机超声波测距仪设计倒车雷达防撞报警器
  11. linux驱动面试题目汇总
  12. 2022年6月护肤行业数据洞察报告(小红书)
  13. MySQL存储引擎 lnnoDB逻辑架构 innodb存储引擎表空间(ibd文件)详解 回滚日志的物理空间
  14. 如何判断网页是否更新??
  15. kotlin的?.和!!.
  16. 图解PMP项目管理马斯洛需求层次理论在公司管理中的应用!
  17. 用VirtualWall防止远古盗链的方法
  18. 怎样写robots.txt实例
  19. nginx报错解决connect() to unix:/tmp/php-cgi-73.sock failed (111: Connection refused
  20. 不知名菜鸟的day15

热门文章

  1. Mysql:Access denied for user ‘root@localhost‘ (using password:NO)
  2. 用golang完成tcp协议传输
  3. 湖南大学第十四届ACM程序设计新生杯(重现赛)L-The Digits String (矩阵快速幂)
  4. matlab中对伺服电机,基于Matlab的伺服电机Modbus通讯研究
  5. Ubuntu19.04安装mysql8.0版本(亲测OK)
  6. 8086汇编-实验9-字符打印
  7. java 序列化 clone_利用java序列化进行对象深Clone
  8. 华为xs第几批升级鸿蒙,华为和荣耀老机型用户有福:确定能批量升级到鸿蒙系统!...
  9. springboot拦截请求路径_SpringBoot整合Ant Design Pro进行部署
  10. Linux Increase The Maximum Number Of Open Files / File Descriptors (FD)