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 k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0. Outpu…
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵线段树,类似计数排序思想. #include <bits/stdc++.h> using namespace std; ; struct SegTree { ], sum[], l, r; }T[N << ]; ][N]; void pushup(int p, int c) { T[p…
题目链接 题意较为简单. 思路: 由于仅仅有26个字母,所以用26棵线段树维护就好了,比較easy. #include <iostream> #include <string> #include <vector> #include <cstring> #include <cstdio> #include <map> #include <queue> #include <algorithm> #include &…
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from…
题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsmemory limit per test512 megabytes 问题描述 This task is very simple. Given a string S of length n and q queries each query is on the format i j k which mea…
E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the sub…
题目链接:http://codeforces.com/problemset/problem/558/E 给一个字符串,每次对一个区间内的子串进行升序或者降序的排列,问最后字符串什么样子. 对于字符串排序,计数排序是比一般的排序要快的,但是仍然不能解决本问题. 建立26个线段树,用于统计某个字符在某个区间的情况. 那么如果对[L,R]排序,则先统计所有字符在其中的情况,并且清空该区间,根据每个字符的数量,从a到z去填充应该在的小区间. #include <iostream> #include &…
这道题好猥琐啊啊啊啊啊啊 写了一个上午啊啊啊啊 没有在update里写pushup啊啊啊啊 题目大意: 给你一个字符串s,有q个操作 l r 1 :把sl..rsl..r按升序排序 l r 0 :把sl..rsl..r按降序排序 Solution: 我们考虑建26棵线段树,第i棵线段树的[x,y]表示在[x,y]中一共有多少个字母'a'+i-1 至于修改时我们可以以升序为例,从a至z按顺序往前丢,记得要清空区间 同理,降序反过来就是了 Code: 我们可以用sort啊啊,只不过会TLE #pra…
链接 题意:给定一个长度不超过 \(10^5\) 的字符串(小写英文字母),和不超过5000个操作. 每个操作 L R K 表示给区间[L,R]的字符串排序,K=1为升序,K=0为降序. 最后输出最终的字符串. 题解 发现只有小写英文字母,26个,直接建26棵线段树,排序的时候,直接统计每个字母的个数暴力安排即可 好像见过值域 \(10^9\) 的,不过不知道在哪了,先留个坑,等看到了或者记起来了再补 #include<bits/stdc++.h> #define REP(i,a,b) for…
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问,最少删除多少个字符,使得串中符合ugly串? 思路:定义dp(i, j),其中i=5,j=5,因为只需要删除2016当中其中一个即可,所以一共所需要删除的字符和需要的字符为20176,因此i和j只要5就够了. 然后转移就是dp(i,i) = 0, 如果说区间大小为1的话,那么如果是2017中的一个…
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作,每次操作将(l,r)内的字符升序或降序排列,输出q次操作后的字符串. analyse: 基本思想是计数排序. 所谓计数排序,是对一个元素分布较集中的数字集群进行排序的算法,时间复杂度为O(n),但使用条件很苛刻.首先对n个数扫一遍,映射出每个数字出现的次数,然后再O(n)扫一遍处理出:对于数字ai,…
题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output   This task is very simple. Given a string S of length n and q queries each qu…
题目链接  A Simple Task 题意  给出一个小写字母序列和若干操作.每个操作为对给定区间进行升序排序或降序排序. 考虑权值线段树. 建立26棵权值线段树.每次操作的时候先把26棵线段树上的所有在该区间内的信息清空. 然后再通过类似计数排序的方式从左往右(或从右往左)依次塞进去. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #de…
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing ord…
http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input 2 agjucbvdfk output 2 abcdfgjkuv 题意:给出一个字母的序列(只包含小写字母),每次对它的一个区间进行排序(递增或递减),问最后的字母序列. 自闭题,身为蒟蒻的我读完题后单纯的觉得这题如名字一一样一个简单的任务(完全没有意识到问题的严重性),直接sort走起,结果..…
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 secondsmemory limit per test 256 megabytes 问题描述 You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on…
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. • A string "()" is balanced. • Concatenation of two balance…
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description When selecting files in an application dialog, Vasya noted that he can get the same selection in different ways. A simple mouse click selects a sing…
题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting game. They have a rooted tree with $n$ vertices, and the vertices are indexed from $1$ to $n$. The root has index $1$. Every other vertex $i≥2$ has its p…
题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or…
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 5*1e5; typedef long lo…
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 = 3的元素累加求和. 解题思路:线段树单点更新,每一个点维护5个值.分别表示从该段区间中i % 5 = t的和.然后两端区间合并时仅仅须要依据左孩子中元素的个数合并.所以有一个c表示区间上元素的个数. 由于有同样的数.所以要离线操做,将全部的数映射成位置,可是对于del则不须要映射,由于集合中肯定…
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You should perform n queries. There are three different types of queries: 1 l r — Add all missing numbers from the interval [l, r] 2 l r — Remove all present…
原文链接http://www.cnblogs.com/zhouzhendong/p/8990745.html 题目传送门 - CodeForces 516C 题意 在一个环上,有$n$棵树. 给出每一个树的高度$h_i$以及每一个树距离他顺时针方向后一个树的距离$d_i$. 有$m$次询问,每次,都会有一段连续区间内的树萎掉.请你找两棵树$x,y$,最大化$2(h_x+h_y)+dist(x,y)$.其中$dist(x,y)$为这两棵树的距离,这个距离不能包含萎掉的树. $n,m\leq 10^…
题目传送门 快速的vjudge通道 快速的Codeforces通道 题目大意 有$n$个火车站,第$i$个火车站出售第$i + 1$到第$a_{i}$个火车站的车票,特殊地,第$n$个火车站不出售车票. 记$\rho_{i, j}$表示从第$i$个火车站出发,到第$j$个火车站最少要购买的车票数. 求$\sum_{i = 1}^{n - 1}\sum_{j=i + 1}^{n}\rho_{i,j}$. 对于在$[i + 1, a_{i}]$中的火车站,肯定直接购买一张从$i$出发的火车票,然后就…
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decid…
Mitya and Vasya are playing an interesting game. They have a rooted tree with n vertices, and the vertices are indexed from 1 to n. The root has index 1. Every other vertex i≥2 has its parent pi, and vertex i is called a child of vertex pi . There ar…
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒消耗b[i]电量,充电器每秒可以给一台电脑充x电,假如有一台电脑在某一秒末电量<0,则会关机,问最小的x使得在k秒内没有任何电脑关机 题解 二分答案x,线段树维护区间[1,n]最小天数,枚举k天每天单点修改天数最小的点 代码 #include<bits/stdc++.h> #define M…
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数组是多少?假设不存在输出no 分析:分析发现要满足全部的区间,而一个点上假如有多个区间的话,这个点的值就是全部区间或的值.由于仅仅有这样才干满足全部区间的.把全部位上的1都保存下来了.那么能够发现用线段树来维护,可是那么怎么推断满不满足条件呢?能够也用线段树,更新了之后在整个维护一遍看看满不满足题意…
Codeforces 834D The Bakery LINK 题目大意是给你一个长度为n的序列分成k段,每一段的贡献是这一段中不同的数的个数,求最大贡献 是第一次做线段树维护DP值的题 感觉还可以,虽然看了一下这题是用线段树维护DP值 然后说思路 有一个很显然的思路是这样的: dpi,j表示前i个数分成j段的最大贡献 dpi,j=max(dpk,j−1+calc(k+1,i)) 然后我们就可以对于每一层j用线段树维护起来 然后就非常愉快地发现dp[i][p]只会从dp[i−1][p−1]之前的…