【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> ...
随机推荐
- ABAP Development Tools的语法高亮实现原理
ABAP Development Tools的前端是Java,根本识别不了ABAP.那么在ADT里的ABAP语法高亮是如何实现的? 第一次打开一个report时,显示在ADT里的代码是没有任何语法高亮 ...
- ansys-表格
转自http://blog.sina.com.cn/s/blog_833dee820102xwb3.html ANSYS中表格数组的定义及使用举例 ANSYS中会有许多的参数数据,这些参数的形成后要放 ...
- idea存留
1.导师匿名评价系统 类似看准网 2.在线降重软件 基于翻译api,或者后期写算法 在线查重导流 公众号: e搜罗
- 使用HelpProvide组件调用帮助文件
实现效果: 知识运用: HelpProvider组件的HelpNameSpace属性 //于对象关联的帮助文件名 public virtual string HelpNameSpace {get; s ...
- Python01 VSCode开发环境和入门程序
1.Python的下载和安装 最新版本python3.7.3 https://www.python.org/downloads/release/python-373/ web-based: 在线安装包 ...
- 使用jquery.ajax实现省市的二级联动(SSH架构)
首先实现jquery ajax的二级联动 要下载个jquery.js 我在这里就不准备了 自行百度下载 背景介绍:通过部门的ID来查找部门下的所有班级 我实现二级联动的思路是:先查询所有部门 显示在页 ...
- 点击按钮在表格的某一行下,在添加一行(HTML+JS)
使用js在指定的tr下添加一个新的一行newTr html代码: <table> <tr> <td>用户名:</td> <td><in ...
- Spring XML配置文件无法自动提示 eclipse中XML配置文件open with打开方式选择 XML Editor:注意它的编辑方式也是有两种的design和source
双击XML配置文件,如果打开方式不正确 则如下图: 都是灰色显示,不会有自动提示,也不会有颜色标注 右击XML配置文件,选择打开方式为XML Editor,则会有颜色标注 如果此时没有自动提示 则要手 ...
- GCD之dispatch queue
GCD之dispatch queue iOS中多线程编程工具主要有: NSThread NSOperation GCD 这三种方法都简单易用,各有千秋.但无疑GCD是最有诱惑力的,因为其本身是appl ...
- C#MySQL增删改查
首先在项目中添加引用 using MySql.Data.MySqlClient; 连接字符串 private string connString="server=localhost;use ...