[CF997E] Good SubSegment】的更多相关文章

Description Transmission Gate 给你一个长度为n的排列P,定义一段子区间是好的,当且仅当这个子区间内的值构成了连续的一段.例如对于排列\(\{1,3,2\}\),\([1,1],[2,2],[3,3],[2,3],[1,3]\)是好的区间. 共q次询问,每次询问L,R 求有多少\(L \leq l \leq r\leq R\),满足\([l,r]\)是好的区间.\(1≤n,q≤1.2×10^5\). Solution 可以发现,区间\([l,r]\)是好的,当且仅当$…
Description 原题链接 给你一个长度为\(n\)的排列\(~P\),定义一段子区间是好的,当且仅当这个子区间内的值构成了连续的一段.例如对于排列\(\{1,3,2 \}\),\([1, 1], [2, 2], [3, 3], [2, 3], [1, 3]\)是好的区间. 共\(q\)次询问,每次询问\(L,R\), 求有多少\(L \leq l \leq r \leq R\),满足\([l, r]\)是好的区间.\(1 \leq n, q \leq 1.2 \times 10 ^ 5\…
[CC-SEINC]Sereja and Subsegment Increasings 题目大意: 有长度为\(n(n\le10^5)\)的序列\(A\)和\(B\). 在一次操作中,可以选择一个区间增加\(1\). 求让\(A\)和\(B\)在模\(4\)意义下相等,至少要对\(A\)执行多少次操作. 思路: 对\(A,B\)对应作差,\(C_i=B_i-A_i\). 求\(C\)的查分\(D_i=C_i-C_{i+1}\). 如果不考虑模\(4\),答案即为\(\sum\max(D_i,0)…
CF1117A Best Subsegment 乍一看好像很难,仔细想一下发现就是弱智题... 任意一段平均数显然不会超过最大的数,若只取最大数即可达到平均数为最大数. 于是只用取最长的一段连续的最大数即可. #include<bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pii pair<int,int> inline int read() { int x…
CF997E Good Subsegments 传送门 和 CF526F 差不多,只不过这道题是对多个子区间进行询问. 据说有一个叫析合树的东西可以在线做,不过有时间再说吧. 考虑离线询问,将每个询问固定至其右端点. 则我们要做的是在那道题的基础上,记录每个位置的历史贡献. 由于 \((i,i)\) 这个区间一直是符合条件的,故线段树根节点的最小值一定为 \(0\) ,我们只需要另外再维护一个标记,每次判断其是否与父节点的最小值一样即可. 贴代码 /*---Author:HenryHuang--…
先将问题进行转化,发现满足\((max-min)-(r-l)=0\)的区间即为好区间. 对于本题这样的统计子区间的问题,先将询问离线,按右端点排序一个一个解决,固定右端点,然后通过数据结构来处理出区间信息,询问直接查询区间合法的贡献即可,扫一遍就能解决所有询问. 继续看这个式子\((max-min)-(r-l)=0\),发现如果去维护这个式子的值,对于固定的右端点,可以统计出其之前的左端点与该右端点的区间最小值及其个数,最小值个数即为在这个区间内可以对这个固定的右端点有贡献的左端点. 但这只能记…
一个区间为好区间当且仅当$\max_{l\le i\le r}a_{i}-\min_{l\le i\le r}a_{i}=r-l$,考虑固定右端点$r$,维护所有左端点$l$的上述式子左-右的值,那么答案即求0的个数,也就是最小值的个数(该值必然非负且$l=r$时必然为0) 如何维护右端点移动:先将所有位置减1,再用单调栈找到之前第一个小于和大于其的位置,然后由于这两个位置中必然有一个为$r-1$,不需要考虑,记剩下的位置为$x$,不妨假设$a_{x}>a_{r}$ 那么也就是考虑以$a[1..…
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols fr…
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered wit…
E. George and Cards   George is a cat, so he loves playing very much. Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the…