【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> ...
随机推荐
- 说说TCP的三次握手
在说这个问题之前,先说说IP协议和TCP协议 问题:IP协议能做什么?不能做什么? 我们都知道IP协议是无连接的通信协议,它不会占用两个正在通信的计算机的通信线路,这样就降低了IP对网络传输中的需求, ...
- 有关SQL的一道面试题
这是一个学生分数表 StudentName StudySubject SubjectScore Peter ...
- SQL数据库中各种字段类型的说明
(1)char.varchar.text和nchar.nvarchar.ntext char和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是 ...
- 关于UINavigationController的一些技巧
未自定义任何东西的导航条效果如下: 1.自定义了 leftBarButtonItem 之后,左滑返回手势失效了,解决办法: self.navigationController.interactiveP ...
- 51nod——2504 是子序列的个数(一看就会的序列自动机原理)
还以为序列自动机是什么,写完无意间看到帖子原来这就是序列自动机……这算自己发现算法
- 【linux】【磁盘分割】Linux磁盘分割
全部的磁盘阵列容量均给/cluster/raid目录,占有2TB的容量: 2 GB的swap容量: 分割出/, /usr, /var, /tmp等目录,避免程序错误造成系统的困扰: /home也独立出 ...
- python-函数基础、函数参数
目录 函数的基础 什么是函数 为何用函数 如何调用函数 定义函数的三种形式 无参函数 有参函数 空函数 函数的返回值 什么是返回值 为什么要有返回值 函数的调用 函数参数的应用 形参和实参 位置参数 ...
- Python中变量的作用域
一.变量作用域的含义 变量的作用域说白了就是变量的值从哪里获取,或者说变量取值的地方 我们在写代码过程中会用到很多变量,这些变量会出现在各种代码块中,有的出现在函数块里,有的在函数块外,例如: def ...
- leetcode-21-knapsack
322. Coin Change Write a function to compute the fewest number of coins that you need to make up tha ...
- Linux学习-灾难复原的考虑
硬件损毁,且具有完整备份的数据时 由于是硬件损毁,所以我们不需要考虑系统软件的不稳定问题,所以可以直接将完整的系统复原回去 即可. 由于软件的问题产生的被攻破资安事件 由于系统的损毁是因为被攻击,此时 ...