[set]Codeforces 830B-Cards Sorting】的更多相关文章

B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…
将每个数字的位置存进该数字的vector中 原数组排个序从小到大处理,每次在vector里二分找到距离当前位置“最远”的位置(相差最大),更新答案 树状数组维护每个数字现在的位置和原位置之差 #include <bits/stdc++.h> using namespace std; #define LL long long ; int n; int a[N], b[N]; vector<int> v[N]; int c[N]; void modify(int x, int num)…
Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 #define INF 0x3f3f3f3f #define maxtree maxn<<2 int n,ai[maxn],val[maxtree],L[ma…
B. Cards Sorting  http://codeforces.com/problemset/problem/830/B Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the sam…
E. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…
Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 0…
题目链接:http://codeforces.com/contest/830/problem/B 题解:其实这题就是求当前大小的数到下一个大小的数直接有多少个数,这时候可以利用数据结构来查询它们之间有几个数优先往后面找如果后面没了再轮到前面找.可以开始将每个数的下表定为1然后拿掉之后就为0然后两值之间有几个数就用区间求和来求. #include <iostream> #include <cstring> #include <cstdio> #include <al…
我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改的数的在初始卡片的位置 #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <algorithm> #include <iostre…
题目大意:给你一堆n张牌(数字可以相同),你只能从上面取牌,如果是当前牌堆里面最小的值则拿走, 否则放到底部,问你一共要操作多少次. 思路:讲不清楚,具体看代码.. #include<bits/stdc++.h> #define pb push_back #define ll long long using namespace std; ; ll n,mxi[N],a[N];//a[i]保存原始数据,mxi[i]保存大小为i的牌最下面一张的编号 vector<ll> p[N];//…
Splay要支持找最左侧的最小值所在的位置.类似线段树一样处理一下,如果左子树最小值等于全局最小值,就查左子树:否则如果当前节点等于全局最小值,就查当前节点:否则查右子树. 为了统计答案,当然还得维护子树大小的函数. 找到位置以后,直接将左右子树交换即可.不需要打标记. 删除节点时,直接将其前驱(是指序列下标的前驱,就是将待删除节点Splay到根后,左子树的最右节点)Splay到根,将其后继(类似)Splay到根的儿子. 然后将后继的左儿子删除即可. 别忘了及时Maintain(); 这份代码的…