题意:给定一个字符串,以及m次操作,每次操作对字符串的一个子区间进行升序或降序排序,求m次操作后的串

考虑桶排,发现线段树可以模拟桶排的过程,所以对26个字母分别建立线段树即可

#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000000+10
struct tree{int sum,tag;}tr[MAXN*][];
char s[MAXN];
int n,m,cnt[];
void pushup(int k,int x){tr[k][x].sum=tr[k<<][x].sum+tr[k<<|][x].sum;}
void pushdown(int k,int x,int l,int r){
int mid=(l+r)>>;
if(tr[k][x].tag==){
tr[k<<][x].sum=(mid-l+);tr[k<<|][x].sum=(r-mid);
tr[k<<][x].tag=tr[k<<|][x].tag=;
tr[k][x].tag=;
}
else if(tr[k][x].tag==){
tr[k<<][x].sum=tr[k<<|][x].sum=;
tr[k<<][x].tag=tr[k<<|][x].tag=;
tr[k][x].tag=;
}
}
void build(int k,int l,int r,int x){
tr[k][x].tag=;
if(l==r){
tr[k][x].sum=;
return;
}
int mid=(l+r)>>;
build(k<<,l,mid,x);
build(k<<|,mid+,r,x);
pushup(k,x);
}
void update(int k,int l,int r,int L,int R,int val,int x){
if(l>=L&&r<=R){
if(val==)tr[k][x].sum=r-l+;
else tr[k][x].sum=;
tr[k][x].tag=val;
return;
}
pushdown(k,x,l,r);
int mid=(l+r)>>;
if(R<=mid)update(k<<,l,mid,L,R,val,x);
else if(L>mid)update(k<<|,mid+,r,L,R,val,x);
else update(k<<,l,mid,L,R,val,x),update(k<<|,mid+,r,L,R,val,x);
pushup(k,x);
}
int query(int k,int l,int r,int L,int R,int x){
if(l>=L&&r<=R)return tr[k][x].sum;
pushdown(k,x,l,r);
int mid=(l+r)>>;
if(R<=mid)return query(k<<,l,mid,L,R,x);
else if(L>mid)return query(k<<|,mid+,r,L,R,x);
else return query(k<<,l,mid,L,R,x)+query(k<<|,mid+,r,L,R,x);
pushup(k,x);
}
int main(){
scanf("%d%d",&n,&m);
scanf("%s",s+);
for(int i=;i<;i++)build(,,n,i);
for(int i=;i<=n;i++)update(,,n,i,i,,s[i]-'a');
while(m--){
memset(cnt,,sizeof(cnt));
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
for(int i=;i<;i++){
cnt[i]=query(,,n,l,r,i);
update(,,n,l,r,,i);
}
if(x){
int p=l;
for(int i=;i<;i++){
if(cnt[i])update(,,n,p,p+cnt[i]-,,i);
p+=cnt[i];
}
}
else{
int p=l;
for(int i=;i>=;i--){
if(cnt[i])update(,,n,p,p+cnt[i]-,,i);
p+=cnt[i];
}
}
}
for(int i=;i<=n;i++){
for(int k=;k<;k++)
if(query(,,n,i,i,k)){
putchar((char)k+'a');
break;
}
}
return ;
}

Codeforces 558E A Simple Task的更多相关文章

  1. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  2. Codeforces 558E A Simple Task (计数排序&&线段树优化)

    题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...

  3. Codeforces 558E A Simple Task(权值线段树)

    题目链接  A Simple Task 题意  给出一个小写字母序列和若干操作.每个操作为对给定区间进行升序排序或降序排序. 考虑权值线段树. 建立26棵权值线段树.每次操作的时候先把26棵线段树上的 ...

  4. Codeforces 558E A Simple Task(计数排序+线段树优化)

    http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input ...

  5. codeforces 558E A Simple Task 线段树

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

  6. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. CodeForces 588E A Simple Task(线段树)

    This task is very simple. Given a string S of length n and q queries each query is on the format i j ...

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

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

  9. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

随机推荐

  1. TIDB 参数解释

    地址:https://github.com/pingcap/docs-cn/blob/master/op-guide/configuration.md#tidb TiDB --store 用来指定 T ...

  2. idea 配置tomcat(包含tomcat Server找不到的配置方法)

    在配置tomcate时有时候按照网上说的找不到tomcat Server,不知不觉花了很长时间这时我们在这里配置就可以了如图所示 1.这是有tomcat Server的配置(后面是没有的情况下的配置) ...

  3. Webpack打包构建太慢了?试试几个方法

    Webpack是个很流行的打包工具,但其打包速度却一直被吐槽着 如果不用上一些打包的优化建议,单单打包两三个文件就能花上好几秒,放上几十个入口文件依赖几百上千个包的话,几分钟十几分钟妥妥的 本文整理了 ...

  4. Oracle 11g服务器安装详细步骤——图文教程

    1.大家可以根据自己的操作系统是多少位(32位或64位)的,到官网下载相应的安装程序,如下图所示. 有一点需要注意,Oracle的安装程序分成2个文件,下载后将2个文件解压到同一目录即可. 2.下载完 ...

  5. 【译】Asp.Net Identity Cookies 格式化

    原文出处 Trailmax Tech Max Vasilyev: ASP.Net MVC development in Aberdeen, Scotland 中英对照版 我的读者联系到我,并向我提出了 ...

  6. Scrum Meeting Alpha - 9

    Scrum Meeting Alpha - 9 NewTeam 2017/11/03 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了登陆退出功能Pull Request ...

  7. Google Play 购买(IAB)测试流程

    Google Play 购买(IAB)测试流程 0. 前言 虽然Google 官方也有说明,但是说话很含糊(英文原文也很含糊),很多时候不清楚它到底表达什么.而且帮助文档和开发文档是分开的,可能常常出 ...

  8. C#中split分隔字符串的应用

    .用单个字符来分隔:string str="aaajbbbjccc";string[] sArray=str.Split('j');foreach(string i in sArr ...

  9. 初生牛犊不怕虎 golang入坑系列

    读前必读,下面所有内容都是来自这里. 放到这里的目的,就是为了比对一下,哪里的读者多.平心而论,同样的Markdown,博客园排版真心X看,怎么瞅怎么X看.(X := '难' || X :='耐' | ...

  10. gdb分析core文件

    转载自:http://blog.chinaunix.net/u2/83905/showart_2134570.html 在Unix系统下,应用程序崩溃,一般会产生core文件,如何根据core文件查找 ...