E. A Simple Task

这个题目的意思是 给你一个由小写字母组成的字符串,有两种操作

i j k 如果k==1 那么就是就把i 到 j 的这个区间非递减排序。

i j k如果k==2 那么就是把 i 到 j 这个区间非递增排序。

n 有 1e5  q(操作次数)  5e4

这个题目不会写,问别人的。

这个要建26棵线段树,首先对这个字符串进行预处理,把每一个位置放到每一个字母放到它的线段树对应的位置。

比如说 acbd     a应该放在第一棵树的1位置,c放到第三颗树,2的位置,b放到第二颗树的3号位置,以此类推。

这个是预处理,然后就是对于操作的写法。

每一个操作给你了一个区间,我们先计算这个区间的每一颗线段树的数量的字母数量,然后清空这个区间的每一颗线段树,

再给定区间进行更新。

知道了这些应该可以很好写了。

这种题不知道算不算一种类型,用26棵线段树来解决排序问题,这里是二十六棵线段树,以后可能是建有限个线段树,对他们进行重新排序,

升序或者降序,然后输出结果,都可以借助这种思想。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
struct node
{
int sum, lazy, len;
}tree[][maxn*];
char s[maxn*]; void push_up(int id)
{
for(int i=;i<;i++)
{
tree[i][id].sum = tree[i][id << ].sum + tree[i][id << | ].sum;
}
} void build(int id,int l,int r)
{
for(int i=;i<;i++)
{
tree[i][id].lazy = -;
tree[i][id].len = r - l + ;
}
if(l==r)
{
int x = s[l] - 'a';
tree[x][id].sum = ;
return;
}
int mid = (l + r) >> ;
build(id << , l, mid);
build(id << | , mid + , r);
push_up(id);
} void push_down(int id)
{
for(int i=;i<;i++)
{
if(tree[i][id].lazy!=-)
{
int val = tree[i][id].lazy;
tree[i][id << ].sum = tree[i][id << ].len*val;
tree[i][id << | ].sum = tree[i][id << | ].len*val;
tree[i][id << ].lazy = tree[i][id << | ].lazy = val;
tree[i][id].lazy = -;
}
}
}
int a[];
void query(int id,int l,int r,int x,int y)
{
if(x<=l&&y>=r)
{
for(int i=;i<;i++)
{
a[i] += tree[i][id].sum;
}
return;
}
push_down(id);
int mid = (l + r) >> ;
if (x <= mid) query(id << , l, mid, x, y);
if (y > mid) query(id << | , mid + , r, x, y);
} void update(int id,int l,int r,int x,int y)//clear
{
if(x<=l&&y>=r)
{
for(int i=;i<;i++)
{
tree[i][id].sum = ;
tree[i][id].lazy = ;
}
return;
}
push_down(id);
int mid = (l + r) >> ;
if (x <= mid) update(id << , l, mid, x, y);
if(y > mid) update(id << | , mid + , r, x, y);
push_up(id);
} void updatenum(int id, int l, int r, int x, int y,int ad)//clear
{
if (x <= l && y >= r) {
tree[ad][id].sum = tree[ad][id].len;
tree[ad][id].lazy = ;
return;
}
push_down(id);
int mid = (l + r) >> ;
if (x <= mid) updatenum(id << , l, mid, x, y, ad);
if (y > mid) updatenum(id << | , mid + , r, x, y, ad);
push_up(id);
} int main()
{
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s + );
build(, , n);
while(m--)
{
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
memset(a, , sizeof(a));
query(, , n, l, r);
update(, , n, l, r);
if(k==)
{
for(int i=;i<;i++)
{
if (a[i] == ) continue;
updatenum(, , n, r - a[i] + , r, i);
r -= a[i];
if (r <= ) break;
}
}
else if(k==)
{
for(int i=;i<;i++)
{
if (a[i] == ) continue;
// printf("i=%d l=%d r=%d\n", i, l, l + a[i] - 1);
updatenum(, , n, l, l + a[i] - , i);
l += a[i];
if (l > n) break;
}
}
}
for(int i=;i<=n;i++)
{
memset(a, , sizeof(a));
query(, , n, i, i);
for(int j=;j<;j++)
{
if(a[j])
{
printf("%c", j + 'a');
}
}
}
printf("\n");
return ;
}
/*
10 5
hbtngdflmj
1 10 1
2 9 0
3 8 1
4 7 0
5 6 1
*/

E. A Simple Task的更多相关文章

  1. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  2. HDU-1339 A Simple Task

    http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...

  3. A Simple Task

    A Simple Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. Codeforces 558E A Simple Task (计数排序&&线段树优化)

    题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...

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

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

  7. 【题解】 CF11D A Simple Task

    [题解] CF11D A Simple Task 传送门 \(n \le 20\) 考虑状态压缩\(dp\). 考虑状态,\(dp(i,j,O)\)表示从\(i\)到\(j\)经过点集\(O\)的路径 ...

  8. Codeforces 558E A Simple Task(权值线段树)

    题目链接  A Simple Task 题意  给出一个小写字母序列和若干操作.每个操作为对给定区间进行升序排序或降序排序. 考虑权值线段树. 建立26棵权值线段树.每次操作的时候先把26棵线段树上的 ...

  9. A Simple Task CodeForces - 11D

    A Simple Task CodeForces - 11D 题意:输出一个无向图的简单环数量.简单环指无重复边的环.保证图无重边自环. ans[i][j]表示"包含i中的点,以i中第一个点 ...

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

随机推荐

  1. 钩子函数 Function类

    Function 为 com.google.common.base包下接口类: public interface Function<F, T> { @Nullable T apply(@N ...

  2. Python趣味入门3:变量、字串输入与输出

    安装配置python环境完毕,非常有必要花十分钟对一些基本概念:变量.数学字符.输入.输出等4个概念进行理解,下面通过简单示例,深入了解python的基本语法. 本文的示例均在IDLE的命令行模式中完 ...

  3. thinkphp5.0远程执行漏洞

    0x01 漏洞简介 由于ThinkPHP5 框架控制器名 没有进行足够的安全监测,导致在没有开启强制路由的情况下,可以伪装特定的请求可以直接Getshell(可以控制服务器) 0x02 环境搭建 Ph ...

  4. webWMS开发过程记录(六)- 详细设计之系统管理

    一.功能说明 1. 权限管理 (参考“权限管理-百度百科") 定义:一般指根据系统设置的安全规则或安全策略,用户可以访问而且只能访问自己被授权的资源,不多不少. 分类:从控制力度来看,通常分 ...

  5. 【three.js第五课】光线的添加和感光材料

    材料分类: MeshBasicMaterial:基础网孔材料,一个以简单着色(平面或线框)方式来绘制几何形状的材料.MeshLambertMaterial:兰伯特网孔材料,一种非发光材料(兰伯特)的表 ...

  6. PHP函数:memory_get_usage

    memory_get_usage()  -返回分配给 PHP 的内存量 说明: memory_get_usage ([ bool $real_usage = false ] ) : int 参数: r ...

  7. 常用ElasticSearch 查询语句

    为了演示不同类型的 ElasticSearch 的查询,我们将使用书文档信息的集合(有以下字段:title(标题), authors(作者), summary(摘要), publish_date(发布 ...

  8. Os-Hax: 1 靶机记录

    靶机地址:172.16.1.197 Kali地址:172.16.1.108 1 信息搜集 靶机首页 相关信息查看 端口扫描: 开放22和80 目录扫描: 访问http://172.16.1.197/c ...

  9. [PHP]听说随机数mt_rand()比rand()速度快,闲的无聊测试了一下!

    废话不说上码 //microtime() 函数返回当前 Unix 时间戳的微秒数.//当设置为 TRUE 时,规定函数应该返回一个浮点数,否则返回一个字符串.默认为 FALSE. <?php h ...

  10. 归并排序(归并排序求逆序对数)--16--归并排序--Leetcode面试题51.数组中的逆序对

    面试题51. 数组中的逆序对 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. 示例 1: 输入: [7,5,6,4] 输出 ...