Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求将索引为l,r的两个数交换位置,并给出交换后数组中的逆序对数. 思路:此题用到了分块的思想,即将这组数分为bsz块,在每一块上建Fenwick树,对于每次查询,只需要处理l,r中间的块和l,r所在块受影响的部分.具体实现见代码及注释. #include<iostream> #include<…
[Hello 2020] C. New Year and Permutation (组合数学) C. New Year and Permutation time limit per test 1 second memory limit per test 1024 megabytes input standard input output standard output Recall that the permutation is an array consisting of nn distinc…
题意: 给你 n 长全排列的一种情况,将其分为 k 份,取每份中的最大值相加,输出和的最大值和有多少种分法等于最大值. 思路: 取前 k 大值,储存下标,每两个 k 大值间有 vi+1 - vi 种分法,相乘即可. #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=998244353; int main() { int n,k;cin>>n>>k; int p…
http://codeforces.com/contest/691/problem/D D. Swaps in Permutation You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a pair from the given positions and swap the numbers in that…
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a…
题目链接: 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…
E. Square Root of Permutation 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] = …