Codeforces 785E. Anton and Permutation】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多少个就可以了. 考虑分块,每段区间之内有排序或者二分查询比一个数大的树的个数的操作. 复杂度${O(qn \sqrt n log_{2}^{\sqrt n})}$ #include<iostream> #include<cstdio> #include<algorithm>…
[题目链接] http://codeforces.com/contest/785/problem/E [题目大意] 一个1到n顺序排列的数列,每次选择两个位置的数进行交换,求交换后的数列的逆序对数 [题解] 我们将序列进行分块.每块维护一个权值树状数组表示各个数字的情况, 每次交换两个数之后我们计算前后贡献值进行加减,计算答案. [代码] #include <cstdio> #include <algorithm> using namespace std; const int N=…
题意: 有一个\(1 \sim n\)的排列\(A\),有\(q\)个询问: 交换任意两个元素的位置,求交换之后排列的逆序数 分析: 像这种不太容易用线段树,树状数组维护的可以考虑分块 每\(\sqrt{n}\)个元素划分为一块,然后两端的块可以直接扫出逆序数的变化,中间的块可以用二分计算逆序数 在更新块的时候,可以二分查找要插入或删除的位置 每次询问的复杂度为\(O(\sqrt{n}log\sqrt{n})=O(\sqrt{n}logn)\) #include <cstdio> #inclu…
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<…
E. Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a…
Portal Description 对一个长度为\(n(n\leq2\times10^5)\)的数列\(a\)进行\(m(m\leq5\times10^4)\)次操作,数列初始时为\(\{1,2,...,n\}\).每次操作交换数列中的两个数\(a_L\)和\(a_R\),并询问此时数列\(a\)中的逆序对数. Solution 交换\(a_L\)和\(a_R\)时,会影响逆序对数的只有下标在\((L,R)\)之间,数值在\(a_L\)和\(a_R\)之间的数(钦定\(L<R\)).设这样的数…
Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a se…
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输出q个操作,每个操作过后整个序列逆序对的个数; [题解] 分块法; 分成根号n个块. 每个块按照数字升序排; 然后再用一个a数组具体记录每个位置上的数字; 找逆序对的方式如下: 对于交换l,r 查找l+1..r-1当中比a[l]小的数字,比a[l]大的数字; 查找l+1..r-1当中比a[r]小-比…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In…