51nod1485 字母排序
【题解】
开26棵线段数,记录区间内每种字母的出现次数,修改的时候就用区间设置为一个数操作即可。同时也有平衡树做
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
#define rg register
#define N 200010
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((a[u].l+a[u].r)>>1)
using namespace std;
int n,m,opt,l,r,q[];
struct tree{
int l,r,cnt[],set;
}a[N<<];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
void build(int u,int l,int r){
a[u].l=l; a[u].r=r; a[u].set=-;
if(l<r){
build(ls,l,mid); build(rs,mid+,r);
for(rg int i=;i<;i++) a[u].cnt[i]=a[ls].cnt[i]+a[rs].cnt[i];
}
else a[u].cnt[getchar()-'a']++;
}
inline void pushdown(int u){
if(a[u].set==-) return; int set=a[u].set;
for(rg int i=;i<;i++) a[ls].cnt[i]=a[rs].cnt[i]=;
a[ls].cnt[a[ls].set=set]=(a[ls].r-a[ls].l+);
a[rs].cnt[a[rs].set=set]=(a[rs].r-a[rs].l+);
a[u].set=-;
}
void update(int u,int l,int r,int set){
if(l<=a[u].l&&a[u].r<=r){
for(rg int i=;i<;i++) a[u].cnt[i]=;
a[u].cnt[a[u].set=set]=(a[u].r-a[u].l+);
return;
}
pushdown(u);
if(l<=mid) update(ls,l,r,set);
if(r>mid) update(rs,l,r,set);
for(rg int i=;i<;i++) a[u].cnt[i]=a[ls].cnt[i]+a[rs].cnt[i];
}
void query(int u,int l,int r){
if(l<=a[u].l&&a[u].r<=r){
for(rg int i=;i<;i++) q[i]+=a[u].cnt[i];
return;
}
pushdown(u);
if(l<=mid) query(ls,l,r);
if(r>mid) query(rs,l,r);
}
void out(int u,int pos){
if(a[u].l==a[u].r) for(rg int i=;i<;i++)if(a[u].cnt[i]){putchar(i+'a'); return;}
pushdown(u);
if(pos<=mid) out(ls,pos); else out(rs,pos);
}
int main(){
n=read(); m=read(); build(,,n);
while(m--){
memset(q,,sizeof(q));
l=read(); r=read(); opt=read();
query(,l,r); int now=l;
if(opt==){
for(rg int i=;i<;i++)if(q[i]) update(,now,now+q[i]-,i),now+=q[i];
}
else{
for(rg int i=;i>=;i--)if(q[i]) update(,now,now+q[i]-,i),now+=q[i];
}
memset(q,,sizeof(q));
}
for(rg int i=;i<=n;i++) out(,i);
return ;
}
法。
51nod1485 字母排序的更多相关文章
- [Android分享] 【转帖】Android ListView的A-Z字母排序和过滤搜索功能
感谢eoe社区的分享 最近看关于Android实现ListView的功能问题,一直都是小伙伴们关心探讨的Android开发问题之一,今天看到有关ListView实现A-Z字母排序和过滤搜索功能 ...
- 联系人的侧边字母索引ListView 将手机通讯录姓名通过首字母排序。
package com.lixu.letterlistview; import java.util.ArrayList; import java.util.List; import org.apa ...
- 获取手机通讯录放入PinnedSectionListView中,按名字首字母排序,并且实现拨打电话功能。
package com.lixu.tongxunlu; import java.util.ArrayList; import com.lixu.tongxunlu.PinnedSectionListV ...
- Android 联系人字母排序(仿微信)
现在很多APP只要涉及到联系人的界面,几乎都会采取字母排序以及导航的方式.作为程序猿,这种已经普及的需求还是需要学习的,于是小生开始了在网上默默的学习之路,网上学习的资料质量参差不齐,不过也有很不错的 ...
- HashMap加入数据后,会自动根据首字母排序
1.Map<String, ArrayList<XX>> entityHashMap = new HashMap<>(); 然后增加一些数据,会发现根据String ...
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
转载:http://blog.csdn.net/xiaanming/article/details/12684155 转载请注明出处:http://blog.csdn.net/xiaanming/ar ...
- mysql中文名字按首字母排序
在mysql数据库中可以使用GBK编码对中文进行排序,如名字按首字母排序 order by convert(substr(tu.username,1,1) using 'GBK') 其中substr方 ...
- string字母排序,
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php按照中文首字母排序
1> 网络上很多php的工具类可以将汉字转为拼音: 2> 将拼音进行排序即可 另一种则是类似mysql转码方式: 1 foreach ($array as $key=>$value) ...
随机推荐
- springcloud 向Eureka中注册服务异常java.net.ConnectException: Connection refused: connect
异常如下: 通过debug发现,服务端的url地址仍然是默认的http://localhost:8761/eureka/apps/,也就是说yml文件中配置没有生效,检查后发现yml中相关配置多写了一 ...
- hdu3018 Ant Trip (并查集+欧拉回路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题意:给你一个图,每条路只能走一次.问至少要多少个人才能遍历所有的点和所有的边. 这是之前没有接 ...
- bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文【区间dp】
只要发现添加一个字符和删除一个字符是等价的,就是挺裸的区间dp了 因为在当前位置加上一个字符x就相当于在他的对称位置删掉字符x,所以只要考虑删除即可,删除费用是添加和删除取min 设f[i][j]为从 ...
- C# 类型转换方法
C# 类型转换方法 C# 提供了下列内置的类型转换方法: 序号 方法 & 描述 1 ToBoolean 如果可能的话,把类型转换为布尔型. 2 ToByte 把类型转换为字节类型. 3 ToC ...
- Oracle取查询结果数据的第一条记录SQL
Oracle取查询结果数据的第一条记录SQL: ; ;
- 为什么,博主我要写下这一系列windows实用网络?
发现,随着自身一路过来所学,无论在大数据领域.还是linux or windows里,菜鸟的我慢慢在长大.把自己比作一个园,面积虽在增加,涉及面增多,但圆外的东西,还是那么多. 现在,正值在校读研 ...
- LR接口测试---webservices
//================================================================================== /* //事务开始 lr_st ...
- ubantu MongoDB安装
转 https://blog.csdn.net/flyfish111222/article/details/51886787 本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的 ...
- 【译】x86程序员手册23-6.5组合页与段保护
6.5 Combining Page and Segment Protection 组合页与段保护 When paging is enabled, the 80386 first evaluates ...
- python学习小结-字典key,val互换
第一种,使用压缩器: >>> m = {'a': 1, 'b': 2, 'c': 3, 'd': 4} >>> zip(m.values(), m.keys()) ...