1318: [Spoj744] Longest Permutation Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 361  Solved: 215[Submit][Status][Discuss] Description 给你一个序列A含有n个正整数(1<=Ai<=n).A的子集形式类如Au, Au+1 ... , Av (1<=u<=v<=n),即必须是连续的.我们感兴趣的是一种子集,它含有元素包括1,2,…k.(k是子…
大意: 给定序列, 求选出一个长度为k的区间, 使得区间内的数为[1,k]的排列, 且要求k最大 这题好神啊. 每个排列有且仅有一个1, 我们按1将序列分成若干子问题来处理, 而每个位置最多属于两个子问题, 所以复杂度还是$O(n)$的. 假设最大值在当前1的左侧, 每个数向右最大延伸的距离可以预处理出来, 就从1开始向左滑动, 维护当前最大值k, 排列用和为k*(k+1)/2来O(1)判断即可, 最大值在右侧时同理. 复杂度$O(n)$…
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1318 这道题的大意是要求一个长度为len,并包含1~len所有数,并使len最大的子区间.开始看题的时候一脸懵逼(好像可以二分?),然后写到一半突然发现二分有反例. 于是上网搜了一波题解. 正确解法: 我们可以发现这个区间必定满足这样的性质:假设它的长度为len,则区间内最大值为len,区间内所有数的和为(len+1)*len/2,并且区间内所有数两两不相等. 因为区间内一定包含1,…
[BZOJ 2759] 一个动态树好题 题目描述 首先这是个基环树. 然后根节点一定会连出去一条非树边.通过一个环就可以解除根的答案,然后其他节点的答案就可以由根解出来. 因为要修改\(p_i\),所以我们用\(lct\). 还是有点难写的. 代码: #include<bits/stdc++.h> #define ll long long #define N 30005 #define ls ch[v][0] #define rs ch[v][1] using namespace std; i…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among t…
KD-Tree KD-Tree的进阶姿势戳这里 http://zyfzyf.is-programmer.com/posts/92431.html 为啥有种线段树&平衡树的即视感……(树形结构的相似性?) 每次插入之后,判断下如果某个子树的size>父亲size*0.7,那么重构一下……(替罪羊树的即视感) 查询的时候,如果当前点表示的坐标范围被查询范围完全包含,则直接返回sum: 否则:当前点若在范围内则更新答案,左子树若不全在范围外则递归进入查询,右子树同理(线段树的即视感) TLE:re…
1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Status][Discuss] Description 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b.中位数是指把所有元素从小到大排列后,位于中间的数. Input 第一行为两个正整数n和b ,第二行为1~n 的排列. Output 输出一个整数,即中位数为b的连续子序列个数.…
B. Guess the Permutation 题目连接: http://www.codeforces.com/contest/618/problem/B Description Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i,…
题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permu…