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<…
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 219B Description Polycarpus is an amateur businessman. Recently he was surprised to find out that…
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…
题目链接: 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…