Codeforces 1244G. Running in Pairs】的更多相关文章

传送门 首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应 显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值 所以直接把第一个排列固定为 $1,2,3,...,n$ 然后考虑第二个排列 $B$ 怎么排比较好 首先最少的时间一定就是 $B_i=i$ 的情况 然后考虑让时间变大,容易想到把 $B_1$ 和 $B_n$ 交换,变成 $n,2,3,...,n-1,1$ 那么时间增加了 $n-1$,一直操作最后 $B$ 就变…
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task…
先上题目: B. Running Student time limit per test 1 second memory limit per test 64 megabytes   And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they dr…
You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the number of pairs of indexes (i,j)(i,j) (1≤i<j≤n1≤i<j≤n) for which (ai+aj)(a2i+a2j)≡kmodp(ai+aj)(ai2+aj2)≡kmodp. Input The first line contains integers n,p,…
Codeforces 题面传送门 & 洛谷题面传送门 首先注意到 \(\sum\limits_{i=1}^{2n}i=\dfrac{2n(2n+1)}{2}=n(2n+1)\equiv n\pmod{2n}\),也就是说,如果我们能够在每个 pair 找到一个数,使取出的 \(n\) 个数加起来是 \(n\)​ 的倍数,那么后手就有必胜策略,因为如果取出的数之和 \(\bmod 2n=0\) 那么显然符合要求,否则我们这 \(n\) 个数之和 \(\bmod 2n\) 必然等于 \(n\),因此…
upd on 2021.7.7:修了个 typo Codeforces 题目传送门 & 洛谷题目传送门 首先考虑怎样处理"字典序小"这个问题,按照字典序比大小的套路,我们可以枚举第一位 \(p_x\ne q_x\) 的位置 \(x\),那么必然有 \(p_x<q_x\),为了避免后面计算中出现太多形如 \(n-x\) 之类的东西,我们不枚举 \(x\),instead 我们枚举 \(i=n-x\),那么真正的 \(x\) 等于 \(n\) 减去你枚举的 \(i\). 接下…
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. #include<cstdio> #include<cstdlib> using namespace std; #define MAXN 2222*2000 ],from[MAXN],to[MAXN]; ],S[]; ],rec[]; void pnt(int x){ ) retur…
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for hi…
B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove alon…
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y…