Codeforces Round #424 E. Cards Sorting
题目大意:给你一堆n张牌(数字可以相同),你只能从上面取牌,如果是当前牌堆里面最小的值则拿走,
否则放到底部,问你一共要操作多少次。
思路:讲不清楚,具体看代码。。
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N=1e5+;
ll n,mxi[N],a[N];//a[i]保存原始数据,mxi[i]保存大小为i的牌最下面一张的编号
vector<ll> p[N];//p[i] 保存值为i的所有牌的编号,从小到大。
ll solve()
{
sort(a+,a+n+);//先从小到大排序
ll now_n=n;//now_n表示到目前为止还剩多少张牌
ll ans=now_n;//第一次操作取全部牌,扔掉大小为a[1]的。
now_n-=p[a[]].size();
p[a[]].clear();
for(int i=;i<=n;i++)//从a[2]开始
{
if(p[a[i]].empty()) continue;//如果这个大小的都取完了跳过。
if(p[a[i]].back()>mxi[a[i-]])//如果当前a[i]的最底下一个的编号大于
{ //a[i-1]最底下的编号,则在mxi[a[i-1]]下面的编号
//在上一次取a[i-1]的时候就取掉了。
vector<ll> ::iterator it;
it=lower_bound(p[a[i]].begin(),p[a[i]].end(),mxi[a[i-]]);
ll num=p[a[i]].end()-it;
p[a[i]].erase(it,p[a[i]].end());
if(!p[a[i]].empty()) mxi[a[i]]=p[a[i]].back();
now_n-=num;//减掉num为当前的牌数。
}
else//取出全部牌将a[i]大小的牌扔掉。
{
ans+=now_n;
now_n-=p[a[i]].size();
p[a[i]].clear();
}
}
return ans;
}
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
p[a[i]].pb(i);
mxi[a[i]]=i;
}
ll ans=solve();
cout<<ans<<endl;
return ;
}
Codeforces Round #424 E. Cards Sorting的更多相关文章
- Educational Codeforces Round 67 D. Subarray Sorting
Educational Codeforces Round 67 D. Subarray Sorting 传送门 题意: 给出两个数组\(a,b\),现在可以对\(a\)数组进行任意次排序,问最后能否得 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) E. Cards Sorting 树状数组
E. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)
Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #424 Div2 E. Cards Sorting
我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...
- 【Splay】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) B. Cards Sorting
Splay要支持找最左侧的最小值所在的位置.类似线段树一样处理一下,如果左子树最小值等于全局最小值,就查左子树:否则如果当前节点等于全局最小值,就查当前节点:否则查右子树. 为了统计答案,当然还得维护 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C
A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...
随机推荐
- 20155335俞昆 《java程序设计》第八周总结
2016-2017-2 <Java程序设计>第X周学习总结 ##认识NIO 在java中,输入与输出,基本上是以字节为单位进行的低层次处理,实际上多半是对字节数组中整个区块进行处理,对于d ...
- entity framework 时间操作
).FirstOrDefault(); if (useractiveentity == null) { UserActive userActive = new UserActive(); userAc ...
- luogu P3978 [TJOI2015]概率论
看着就是要打表找规律 使用以下代码 for(int i=3;i<=20;i++) { int a1=0,a2=0; for(int j=1;j<i;j++) { for(int k=0;k ...
- POJ1251 Jungle Roads【最小生成树】
题意: 首先给你一个图,需要你求出最小生成树,首先输入n个节点,用大写字母表示各节点,接着说有几个点和它相连,然后给出节点与节点之间的权值.拿第二个样例举例:比如有3个节点,然后接下来有3-1行表示了 ...
- POJ 2407 Relatives (欧拉函数)
题目链接 Description Given n, a positive integer, how many positive integers less than n are relatively ...
- python - 数据描述符(class 内置 get/set/delete方法 )
数据描述符(class 内置 get/set/del方法 ): # 什么是描述符 # 官方的定义:描述符是一种具有“捆绑行为”的对象属性.访问(获取.设置和删除)它的属性时,实际是调用特殊的方法(_g ...
- RunLoop 原理和核心机制
搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研究了RunLoop的原理和特性. RunLoop的 ...
- SVM实例及Matlab代码
******************************************************** ***数据集下载地址 :http://pan.baidu.com/s/1geb8CQf ...
- SIFT feature
转载:http://www.cnblogs.com/wangguchangqing/p/4853263.html 1.SIFT概述 SIFT的全称是Scale Invariant Feature Tr ...
- vsftpd控制用户禁止访问上级目录 只能访问自己目录
涉及文件: vsftpd.conf chroot_list_file=/etc/vsftpd.chroot_list 如果设置为 chroot_local_user=YES chroot_list_e ...