题目链接

  这题……太暴力了吧……

  开二十六棵线段树维护l到r字符i出现的次数,然后修改的时候暴力修改,输出的时候暴力输出……就过了……

  然后我还没想到……

  qwq

  

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define maxn 100050
#define left (rt<<1)
#define right (rt<<1|1)
#define mid ((l+r)>>1)
#define lson l,mid,left
#define rson mid+1,r,right
using namespace std; inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} inline int count(char c){ return c-'a'+; } char q[maxn]; struct Segtree{
int tree[maxn*];
int tag[maxn*];
int mem[maxn*];
inline void pushup(int rt){
tree[rt]=tree[left]+tree[right];
}
void build(int l,int r,int rt,int o){
tree[rt]=tag[rt]=; mem[rt]=-;
if(l==r){
tree[rt]=count(q[l])==o?:;
return;
}
build(lson,o);
build(rson,o);
pushup(rt);
return;
}
void pushdown(int rt,int m){
if(tag[rt]==&&mem[rt]==-) return;
if(mem[rt]!=-){
mem[left]=mem[right]=mem[rt];
tag[left]=tag[right]=;
tree[left]=mem[rt]*(m-(m>>));
tree[right]=mem[rt]*(m>>);
mem[rt]=-;
}
if(tag[rt]){
tag[left]+=tag[rt];
tag[right]+=tag[rt];
tree[left]+=tag[rt]*(m-(m>>));
tree[right]+=tag[rt]*(m>>);
tag[rt]=;
}
}
void update(int from,int to,int num,int l,int r,int rt){
if(from<=l&&to>=r){
tree[rt]+=num*(r-l+);
tag[rt]=num;
return;
}
pushdown(rt,r-l+);
if(from<=mid) update(from,to,num,lson);
if(to>mid) update(from,to,num,rson);
pushup(rt);
return;
}
void memseg(int from,int to,int l,int r,int rt){
if(from<=l&&to>=r){
tree[rt]=;
mem[rt]=; tag[rt]=;
return;
}
pushdown(rt,r-l+);
if(from<=mid) memseg(from,to,lson);
if(to>mid) memseg(from,to,rson);
pushup(rt);
return;
}
int query(int from,int to,int l,int r,int rt){
if(from<=l&&to>=r) return tree[rt];
pushdown(rt,r-l+);
int ans=;
if(from<=mid) ans+=query(from,to,lson);
if(to>mid) ans+=query(from,to,rson);
return ans;
}
}s[]; int d[]; int main(){
int n=read(),m=read();
scanf("%s",q+);
for(int i=;i<=;++i) s[i].build(,n,,i);
while(m--){
int from=read(),to=read(),opt=read();
for(int i=;i<=;++i){
d[i]=s[i].query(from,to,,n,);
s[i].memseg(from,to,,n,);
}
if(opt){
int pos=from;
for(int i=;i<=;++i){
if(d[i]==) continue;
s[i].update(pos,pos+d[i]-,,,n,);
pos+=d[i];
}
}
else{
int pos=to;
for(int i=;i<=;++i){
if(d[i]==) continue;
s[i].update(pos-d[i]+,pos,,,n,);
pos-=d[i];
}
}
}
for(int i=;i<=n;++i)
for(int j=;j<=;++j)
if(s[j].query(i,i,,n,)==){
printf("%c",j+'a'-);
break;
}
return ;
}

https://vjudge.net/problem/CodeForces-558E

【Vjudge】P558E A Simple Task(线段树暴力)的更多相关文章

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

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

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

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

  5. [Codeforces558E]A Simple Task 线段树

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

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

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

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

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

  8. CF558E A simple task 线段树

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

  9. codeforces 558E A Simple Task 线段树

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

随机推荐

  1. 【Python图像特征的音乐序列生成】GitHub已经有人将mingus改到了Python3版本

    https://github.com/bspaans/python-mingus/issues/45 注意此时的安装方法应该是: git clone https://github.com/edudob ...

  2. Java的三大特性之继承

    此处我会分为这几个部分来理解继承是怎么样的: 1.区分封装.继承和多态 2.区分限定词的范围 3.区分隐藏.覆盖.重载 4.继承的理解 5.一道面试题的原型 --------------------- ...

  3. event loop、进程和线程、任务队列

    本文原链接:https://cloud.tencent.com/developer/article/1106531 https://cloud.tencent.com/developer/articl ...

  4. for...in、for...of、forEach()有什么区别

    本文原链接:https://cloud.tencent.com/developer/article/1360074 for of 和 for in 循环 循环遍历数组的时候,你还在用 for 语句走天 ...

  5. 如何使用动画库animate.css

    animate.css是一个CSS3动画库,里面预设了抖动(shake).闪烁(flash).弹跳(bounce).翻转(flip).旋转(rotateIn/rotateOut).淡入淡出(fadeI ...

  6. python之道10

    写函数,函数可以支持接收任意数字(位置传参)并将所有数据相加并返回. 答案 def func(*args): count = 0 for i in args: count += i return co ...

  7. Core BlueTooth官方文档翻译

    本⽂文是苹果<Core Bluetooth Programming Guide>的翻译. 关于Core Bluetooth Core Bluetooth 框架提供了蓝⽛牙低功耗⽆无线设备与 ...

  8. C语言预处理_05

    凡是以 “#”开头的均为预处理命令! 其定义的一般形式为: #define  标示符  字符串 对于宏定义说明以下几点: 1.宏定义是用宏名来表示一个字符串,在宏展开时又以该字符串取代宏名,这只是一种 ...

  9. 如何挂载一个镜像文件(how to mount an image file)

    如何挂载一个镜像文件(how to mount an image file) 08/16/2012master 4 Comments 在使用KVM或Xen虚拟化的情况下,经常需要使用镜像文件(imag ...

  10. k8s的pod生命周期

    pod的生命周期: 1.init container 2.main contianer (1) post start hook :容器启动后做什么操作(可以命令查看kubectl explain po ...