计数排序的原理,只要知道了有几个数比i小,就可以知道i的位置

这道题只有26个字母,搞26颗线段树,然后区间更新

 #include <cstdio>
#include <cstring>
#include <algorithm> //using namespace std;
const int maxn = 1e5+; int N,Q;
char line[maxn]; #define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define root 1,1,N struct SegrTree{
int num[maxn<<];
int lazy[maxn<<];
void init()
{
memset(lazy,-,sizeof lazy);
}
void push_up(int rt)
{
num[rt] = num[rt<<] + num[rt<<|];
}
void push_down(int rt,int m)
{
if(lazy[rt] != -)
{
num[rt<<] = (m-(m>>))*lazy[rt] ;
num[rt<<|] = (m>>)*lazy[rt] ;
lazy[rt<<] = lazy[rt<<|] = lazy[rt];
lazy[rt] = -;
}
}
void build(int kind,int rt,int l,int r)
{
if(l == r)
{
num[rt] = line[l-]==kind+'a';
//if(line[l-1]=='c') printf("%c pos:%d \n",kind+'a',l);
return ;
}
int mid = (l+r)>>;
build(kind,lson);
build(kind,rson);
push_up(rt);
}
void update(int L,int R,int d,int rt,int l,int r)
{
if(L <= l && R >= r)
{
num[rt] = (r-l+)*d;
lazy[rt] = d;
return ;
}
push_down(rt,r-l+);
int mid = (l+r)>>;
if(L <= mid) update(L,R,d,lson);
if(R > mid) update(L,R,d,rson);
push_up(rt);
}
int query(int L,int R,int rt,int l,int r)
{
if(L <= l && R >= r)
{
return num[rt];
}
push_down(rt,r-l+);
int mid = (l+r)>>;
int res = ; if(R <= mid) res = query(L,R,lson);
else if(L > mid) res = query(L,R,rson);
else res = query(L,R,lson)+query(L,R,rson); push_up(rt);
return res;
}
}alpha[]; void sort(int l,int r,int k)
{
int pos,cnt;
if(k == )
{
pos = l;
for(int i=;i<;i++)
{
cnt = alpha[i].query(l,r,root);
//printf("[%d,%d]%c k:%d pos:%d cnt:%d\n",l,r,i+'a',k,pos,cnt);
if(cnt)
{
alpha[i].update(l,r,,root);
alpha[i].update(pos,pos+cnt-,,root);
pos += cnt;
}
}
}
else
{
pos = l;
for(int i=;i>=;i--)
{
cnt = alpha[i].query(l,r,root);
//printf("[%d,%d] %c k:%d pos:%d cnt:%d\n",l,r,i+'a',k,pos,cnt);
if(cnt)
{
alpha[i].update(l,r,,root);
alpha[i].update(pos,pos+cnt-,,root);
pos += cnt;
}
}
}
} int main()
{
//freopen("input.txt","r",stdin); scanf("%d%d",&N,&Q);
scanf("%s",line); for(int i=;i<;i++)
{
alpha[i].init();
alpha[i].build(i,root);
//printf("tot num:%c %d\n",i+'a',alpha[i].query(1,N,root));
}
//printf("c:%d c:%d\n",alpha[2].query(1,N,root),alpha[2].query(7,10,root));
for(int i=,l,r,k;i<Q;i++)
{
scanf("%d%d%d",&l,&r,&k);
sort(l,r,k);
}
for(int i=;i<=N;i++)
{
for(int j=;j<;j++) if(alpha[j].query(i,i,root))
{
printf("%c",'a'+j);
}
}
puts("");
}

CF558E-A Simple Task-线段树+计数排序的更多相关文章

  1. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树+计数排序

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

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

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

  3. CF558E A simple task 线段树

    这道题好猥琐啊啊啊啊啊啊 写了一个上午啊啊啊啊 没有在update里写pushup啊啊啊啊 题目大意: 给你一个字符串s,有q个操作 l r 1 :把sl..rsl..r按升序排序 l r 0 :把s ...

  4. [Codeforces558E]A Simple Task 线段树

    链接 题意:给定一个长度不超过 \(10^5\) 的字符串(小写英文字母),和不超过5000个操作. 每个操作 L R K 表示给区间[L,R]的字符串排序,K=1为升序,K=0为降序. 最后输出最终 ...

  5. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树

    E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...

  6. 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 ...

  7. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树 延时标记

    E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input ...

  8. CF #312 E. A Simple Task 线段树

    题目链接:http://codeforces.com/problemset/problem/558/E 给一个字符串,每次对一个区间内的子串进行升序或者降序的排列,问最后字符串什么样子. 对于字符串排 ...

  9. codeforces 558E A Simple Task 线段树

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

随机推荐

  1. Linux运维必会的MySQL企业面试题大全

    (1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...

  2. Linux ip netns 命令

    ip netns 命令用来管理 network namespace.它可以创建命名的 network namespace,然后通过名字来引用 network namespace,所以使用起来很方便. ...

  3. Item 22: 当使用Pimpl机制时,在实现文件中给出特殊成员函数的实现

    本文翻译自<effective modern C++>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 如果你曾经同过久的编译时间斗争过,那么你肯定对Pi ...

  4. Redux 入门教程(三):React-Redux 的用法

    为了方便使用,Redux 的作者封装了一个 React 专用的库 React-Redux,本文主要介绍它. 这个库是可以选用的.实际项目中,你应该权衡一下,是直接使用 Redux,还是使用 React ...

  5. linux下的shell脚本(基本)

    shell有些命令和格式不用老是容易忘,学而时习之,不亦说乎~ 先说明以下内容来自: http://c.biancheng.net/cpp/shell/ ,C语言中文网,请大家支持原作,点击链接查看. ...

  6. eclipes个人配置

    设置字体:https://jingyan.baidu.com/article/f96699bb9442f3894e3c1b15.html general->appearance->colo ...

  7. 【评分】Alpha 事后诸葛亮(团队)

    [评分]Alpha 事后诸葛亮(团队) 总结 按时交 - 有分 晚交 - 0分 迟交一周以上 - 倒扣本次作业分数 抄袭 - 倒扣本次作业分数 本次作业都是以问答形式进行,大部分同学在回答问题方面都一 ...

  8. 初次使用git上传代码到github远程仓库

    https://blog.csdn.net/loner_fang/article/details/80488385 2018年05月28日 21:02:31 蒲公英上的尘埃 阅读数:697 因为最近在 ...

  9. 一些iptables配置

    第一条是封堵22,80,8080端口的输出,第二条是为该ip的80端口设置输出白名单,亲测有效:第三条是禁止所有UDP报文的输出 iptables -I OUTPUT -p tcp -m multip ...

  10. 福州大学软件工程1816 | W班 第4次作业(团队展示)成绩排名

    作业链接 评分细则 队员姓名与学号(标记组长),其中4-7人一组,特殊情况经老师允许后可以突破限制:(1分) 队名(体现项目内容,并要求有亮点与个性):(1分) 拟作的团队项目描述:一句话(中英文不限 ...