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: ...
随机推荐
- The android command is deprecated
新版的SDK tools中的android命令已经不支持 android create project,用起来很不顺手. The "android" command is depr ...
- wcf事务
wcf服务 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serial ...
- Linux - 日志处理一
Linux 日志处理 history # 历时命令默认1000条 HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S " # 让history命令显示具体时间 hi ...
- Zabbix 监控服务
熟悉了解一些 zabbix 基础项目监控 zabbix_get 相关操作 :获取 item 监控数据 基本格式: -s --host: 指定客户端主机名或者IP -p --port:客户端端口,默认 ...
- gulp+webpack构建配置
使用构建工具之前我觉得前端好蠢,css没有变量,不能写循环,为了兼容要写好多前缀,hmtl写多页面中有同一个header,我就粘贴复制,然后修改的时候每个都要改. 我还不会压缩和合并,每次都要按F5刷 ...
- Java 学习札记(二)TomCat安装配置
1.下载TomCat 下载地址:http://tomcat.apache.org/ 2.配置环境变量 CATALINA_HOME:F:\JAVA\apache-tomcat-6.0.18\apache ...
- 前端mock数据的几种方式
方式 备注 本地php服务架设 直接输出json 使用在线mock服务 如easyMock.apizza.Rap1\2 , 可以远程协作 本地node服务:koa+mongodb 本地node ...
- jquery 学习(四) - 标签 添加/删除/修改
HTML代码 <div class="a1"> <div> <span id="a2">aaa</span> & ...
- Activity,Fragment的状态保存
http://blog.csdn.net/hqdoremi/article/details/26376797 https://blog.csdn.net/u013588712/article/deta ...
- 【逆向工具】使用x64dbg+spy去除WinRAR5.40(64位)广告弹框
1 学习目标 WinRAR5.40(64位)的弹框广告去除,由于我的系统为x64版本,所以安装了WinRAR(x64)版本. OD无法调试64位的程序,可以让我熟悉x64dbg进行调试的界面. 其次是 ...