cf B. Permutation】的更多相关文章

#include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; int main() { int n,k; scanf("%d%d",&n,&k); ; i<=*n; i++) { a[i]=i; } ; i<=k; i++) { swap(a[*i-],a[*i]); } ; i<=*n; i++) { ) prin…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
大意: 给定01字符串, 求有多少个区间$[l,r]$, 使得存在正整数$x,k$满足$1\le x,k\le n,l\le x<x+2k\le r,s_x=s_{x+k}=s_{x+2k}$. 0和1分开考虑, 那么问题就转化为给定排列求有多少个区间包含等差子序列, 可以用CF 452F Permutation的方法求出最小等差子序列位置, 然后就很容易能统计出答案. 复杂度是$O(n)$的 #include <iostream> #include <sstream> #i…
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible. Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≤ k…
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 序列中的数无论怎么改,都不会改变与绝对值最大的数的逆序对的数量 所以从绝对值最大的数开始,决定它的正负 若这个序列中没有重复的最大值 若i是正数,与右边比他小的形成逆序对 若i是负数,与左边比他小的形成逆序对 所以两边取较小的 若序列中出现重复的最大值 那么最优解的最大值一定是 先是若干个负数,然…
C. Permutation Game http://codeforces.com/contest/1033/problem/C 题意: 一个排列,每个位置i走到的位置j满足:a[j]>a[i],(j-i)是a[i]的倍数.问从每个位置开始,是否有必胜策略. 分析: 博弈论+拓扑. 由于是一个排列,那么可以枚举每个数,判断这个位置的a是否大于它,如果可以连边.这样的复杂度是$nlogn$的. 然后对于一些无路可走的点,这是必败态,根据必胜和必败的定义:必胜态的后继状态中存在至少一个必败态,必败态…
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. F…
Description An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2] , [1][1] , [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,…
LINK:Permutation 休闲一下 开了一道构造题. 看起来毫无头绪 其实仔细观察第二个条件 0<=2k<=n. 容易想到当n是奇数的时候 k的范围更小 再手玩一下第一个条件 容易发现 想要价值 必须使得 后面的式子 正值和负值抵消掉. 这样每次差是偶数倍 所以只需要凑出来k就行了 而后面的式子想刚好抵消掉k如果直接使用两个数字的话构造会略显繁杂. 考虑多个数字抵消 那么容易想到 两个相邻的数字带来的贡献为1 这样使用两个相邻的数字不断构造正数和负数抵消k即可. 刚好这样做 k还是在合…
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,k; int main() { while(scanf("%d%d",&n,&k)!=EOF) { if(n==k) { printf("-1\n"); con…