【Vjudge】P558E A Simple Task(线段树暴力)
这题……太暴力了吧……
开二十六棵线段树维护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(线段树暴力)的更多相关文章
- 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 ...
 - 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 ...
 - 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 ...
 - 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 ...
 - [Codeforces558E]A Simple Task 线段树
		
链接 题意:给定一个长度不超过 \(10^5\) 的字符串(小写英文字母),和不超过5000个操作. 每个操作 L R K 表示给区间[L,R]的字符串排序,K=1为升序,K=0为降序. 最后输出最终 ...
 - Codeforces 588E. A Simple Task (线段树+计数排序思想)
		
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...
 - CF #312  E. A Simple Task  线段树
		
题目链接:http://codeforces.com/problemset/problem/558/E 给一个字符串,每次对一个区间内的子串进行升序或者降序的排列,问最后字符串什么样子. 对于字符串排 ...
 - CF558E A simple task 线段树
		
这道题好猥琐啊啊啊啊啊啊 写了一个上午啊啊啊啊 没有在update里写pushup啊啊啊啊 题目大意: 给你一个字符串s,有q个操作 l r 1 :把sl..rsl..r按升序排序 l r 0 :把s ...
 - codeforces 558E A Simple Task 线段树
		
题目链接 题意较为简单. 思路: 由于仅仅有26个字母,所以用26棵线段树维护就好了,比較easy. #include <iostream> #include <string> ...
 
随机推荐
- ASP.NET WebForm & MongoDB
			
ASP.NET WebForm & MongoDB 最近在朋友介绍下,也跟着看AngularJS 买了一本三合一的书,Node.JS+MongoDB+AngularJS http://www. ...
 - 使用ABAP批量下载有道云笔记中的图片
			
Jerry喜欢用有道云笔记这款软件做自己的知识管理和知识体系的构建. 当您看到一篇好的有道云笔记分享时,可能会想将其精美的图片下载到本地.作为程序猿,我们不会去手动一张张下载.写个程序帮我们自动下载吧 ...
 - jquery的uploadify插件实现的批量上传V3.2.1版
			
你需要如下配置(包括引入文件)HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&quo ...
 - 第010课_掌握ARM芯片时钟体系
			
from:第010课_掌握ARM芯片时钟体系 第001节_S3C2440时钟体系结构 S3C2440是System On Chip(SOC),在芯片省不仅仅有CPU,还有一堆外设. 至于有哪些外设,可 ...
 - Twisted 综述
			
Twisted 框架概况 Twisted 是一个有着10多年历史的开源事件驱动框架.Twisted 支持很多协议,包括传输层的TCP.UDP.TLS,以及应用层的HTTP.FTP等.对所有这些协议,T ...
 - RabbitMQ 学习资料
			
https://www.rabbitmq.com/getstarted.html http://www.cnblogs.com/luxiaoxun/p/3918054.html http://back ...
 - HTML5<nav>元素
			
HTML5中<nav>元素定义页面导航链接的部分区域,但并不是所有的链接都放到nav元素里面. 实例: <header id="pageHeader"> & ...
 - AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?
			
问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...
 - 二十一、C++中的临时对象
			
思考: 构造函数是一个特殊的函数 是否可以直接调用? 是否可以在构造函数中调用构造函数? 直接调用构造函数的行为是什么? 答: 直接调用构造函数将产生一个临时对象 临时对象的生命周期只有一条语句的时间 ...
 - 16Shell脚本—计划任务服务程序
			
计划任务服务程序 尽管我们现在已近有了功能彪悍的脚本程序来执行一些批处理工作,但是,如果仍然需要每天凌晨两点敲击键盘回车键来执行这个脚本程序,这简直太痛苦了.为此,我们需要学习如何设置服务器的计划任务 ...