time limit per test5 seconds

memory limit per test512 megabytes

inputstandard input

outputstandard output

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.

Examples

input

10 5

abacdabcda

7 10 0

5 8 1

1 4 0

3 6 0

7 10 1

output

cbcaaaabdd

input

10 1

agjucbvdfk

1 10 1

output

abcdfgjkuv

Note

First sample test explanation:

【题目链接】:http://codeforces.com/contest/558/problem/E

【题解】



计数排序.

因为数字的范围是1..26(把a..z看成是1..26);

则对于一个操作x,y;

如果想变成升序;

那么就看把x..y这个区间里面a..z的个数分别处理出来;

则从左到右放a..z;(有几个a就放几个a,有几个b就…按顺序就行);

为了快速获取x..y这个区间里面有多少个a..z;

可以用一个vector存每个字母在哪些位置出现过;

因为进行更改后原本位置在x..y这个区间的字母还是在x..y这个区间;

只不过“变得更密集了”;

所以vector始终会是单调递增。则用二分搞一下就能快速检索这个区间里面各个字母的个数了;

也可以用线段树搞。



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define rei(x) scanf("%d",&x)
  13. #define rel(x) scanf("%I64d",&x)
  14. #define pri(x) printf("%d",x)
  15. #define prl(x) printf("%I64d",x)
  16. typedef pair<int,int> pii;
  17. typedef pair<LL,LL> pll;
  18. const int MAXN = 1e5+100;
  19. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  20. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  21. const double pi = acos(-1.0);
  22. int n,q;
  23. char s[MAXN];
  24. vector <int> g[28];
  25. int main()
  26. {
  27. //freopen("F:\\rush.txt","r",stdin);
  28. rei(n);rei(q);
  29. scanf("%s",s+1);
  30. rep1(i,1,n)
  31. g[s[i]-'a'+1].pb(i);
  32. rep1(i,1,q)
  33. {
  34. int x,y,k;
  35. rei(x);rei(y);rei(k);
  36. if (k==1)
  37. {
  38. int now = x;
  39. rep1(j,1,26)
  40. {
  41. int ll = lower_bound(g[j].begin(),g[j].end(),x)-g[j].begin();
  42. int rr = upper_bound(g[j].begin(),g[j].end(),y)-g[j].begin()-1;
  43. rep1(k,ll,rr)
  44. g[j][k] = now++;
  45. }
  46. }
  47. else
  48. {
  49. int now = x;
  50. rep2(j,26,1)
  51. {
  52. int ll = lower_bound(g[j].begin(),g[j].end(),x)-g[j].begin();
  53. int rr = upper_bound(g[j].begin(),g[j].end(),y)-g[j].begin()-1;
  54. rep1(k,ll,rr)
  55. g[j][k] = now++;
  56. }
  57. }
  58. }
  59. rep1(j,1,26)
  60. {
  61. int len = g[j].size();
  62. char ke = 'a'+j-1;
  63. rep1(k,0,len-1)
  64. s[g[j][k]] =ke;
  65. }
  66. rep1(j,1,n)
  67. cout << s[j];
  68. cout << endl;
  69. return 0;
  70. }

【30.93%】【codeforces 558E】A Simple Task的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. codeforces 558 E A Simple Task

    题目大意就是给一个字符串,然后多个操作.每次操作能够把每一段区间的字符进行升序或者降序排序,问终于的字符串是如何的. 做法的话就是用线段树维护区间和 一開始仅仅考虑字符串中字符'a'的情况.如果操作区 ...

  3. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  8. 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理

    [微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...

  9. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

随机推荐

  1. Ueditor 七牛集成

    UEDITOR修改成功的 http://blog.csdn.net/uikoo9/article/details/41844747 http://blog.csdn.net/u010717403/ar ...

  2. Irrlicht 3D Engine 笔记系列 之 教程5- User Interface

    作者:i_dovelemon 日期:2014 / 12 / 18 来源:CSDN 主题:GUI 引言 今天.博主学习了第五个教程. 这个教程解说了怎样使用Irrlicht内置的一个基础模块.GUI模块 ...

  3. OPENSSL 制作 Ikev2证书

    OPENSSL 制作 Ikev2证书 在一个 VPS 上配置 IKEV2 VPN 服务器时,用 OPENSSL 制作了所需的数字证书,奇怪的怎么弄都无法连接服务器,一直提示 "IKE_SA ...

  4. VNC Server模拟攻击实战

    VNC目前已被广泛应用的一个远程控制程序,很多攻击者对VNC的攻击技术研究热情是高涨的,丝毫不亚于对Windows的远程桌面(3389).PcAnywhere的攻击研究.从最开始爆发出来的VNC的低版 ...

  5. Java学习笔记二.1

    和其他高级语言类似,Java也具有以下部分 1.关键字:见下表,注意Java严格区分大小写,关键字都是小写 2.标识符:见下图 3.注释.有两种://(单行注释)和/**/(多行注释).还有一种文档注 ...

  6. Input File选择图片后,未保存预览

    今天实现上传图片到服务器 简单的jQuery实现input file选择图片后,可以预览图片的效果 简单的HTML代码: <div> <img src="" cl ...

  7. 免费的EmBitz可替代Keil MDK开发STM32、NXP项目

    一.背景 由于使用之前开发STM32是基于Keil MDK编译环境开发的,由于该软件是收费的,想用个免费开源的软件来替代Keil,EmBitz编译器是免费的,可以完全替代开发.下载程序支持J-Link ...

  8. SpringMVC,Mybatis,FreeMarker连接mycat示例(一)

    首页 > 程序开发 > 软件开发 > Java > 正文 SpringMVC,Mybatis,FreeMarker连接mycat示例(一) 项目结构如图: 首先是各种配置文件, ...

  9. SQL server 2012 安装SQL2012出现报错: 启用 Windows 功能 NetFx3 时出错

    在window server 2012服务器上,安装 SQL Server 2012的过程中,报了一个错误,一个安装失败, 在安装SQL 2012的过程中.出现下面错误:启用 Windows 功能 N ...

  10. HTML基础第四讲---图像

    转自:https://blog.csdn.net/likaier/article/details/326735 图像,也就是images,在html语法中用img来表示,其基本的语法是:   < ...