cf E. George and Cards
http://codeforces.com/contest/387/problem/E
题意:给你n个数,然后在输入k个数,这k个数都在n个数中出现,进行每一次操作就是在n个数中选择长度为w的连续序列,然后删除这w个数中的最小的一个,然后你就会的到w个奖励,如何获得最多奖励?
思路:set+数状数组,数状数组用来记录在每一个连续的区间内数的个数,用来记录删除和添加数的个数,先对a数组中的数记录每一个数在序列中的位置,再对b数组进行标记,然后遍历1-n,被标记数,把它的位置放在set里面,没有被标记的,在set里面二分查找到大于等于它位置的数,可以知道下界和上界,就可以知道这次的w,就可以求出答案。
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#define ll long long
#define maxn 1000010
using namespace std; int n,k;
int p[maxn];
int b[maxn];
int c[maxn];
int pos[maxn];
bool vis[maxn];
struct node
{
int x,id;
bool operator <(const node &a)const
{
return x<a.x;
}
} f[maxn]; int lowbit(int x)
{
return x&-x;
} void insert(int x,int d)
{
while(x<maxn)
{
c[x]+=d;
x+=lowbit(x);
}
} int Getsum(int x)
{
int ans=;
while(x>)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
} int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
set<int>q;
set<int>::iterator it;
for(int i=; i<=n; i++)
{
scanf("%d",&p[i]);
insert(i,);
pos[p[i]]=i;
}
for(int i=; i<=k; i++)
{
scanf("%d",&b[i]);
vis[b[i]]=true;
}
ll ans=;
q.insert(); q.insert(n+);
for(int i=; i<=n; i++)
{
if(vis[i])
{
q.insert(pos[i]);
}
else
{
it=q.lower_bound(pos[i]);
int r=*it-;
int l=*(--it);
ans+=Getsum(r)-Getsum(l);
insert(pos[i],-);
}
}
printf("%lld\n",ans);
}
return ;
}
cf E. George and Cards的更多相关文章
- cf B George and Cards
题意:给你一个只有‘.’和'#'的n*n的格子,问所有的'#'是不是只属于一个十字叉,如果不是输出NO,否则输出YES. #include <cstdio> #include <cs ...
- Codeforces Round #227 (Div. 2) E. George and Cards set内二分+树状数组
E. George and Cards George is a cat, so he loves playing very much. Vitaly put n cards in a row in ...
- Codeforces Round #227 (Div. 2) E. George and Cards 线段树+set
题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 ...
- Codeforces 387E George and Cards
George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...
- cf 546C Soldier and Cards
题目链接:C. Soldier and Cards Two bored soldiers are playing card war. Their card deck consists of exact ...
- George and Cards
Codeforces Round #227 (Div. 2) E:http://codeforces.com/contest/387/problem/E 题意:给你一个n个数的序列,然后给你一个标准序 ...
- cf D George and Interesting Graph
题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边. 思路:枚举根 ...
- cf C. George and Number
http://codeforces.com/problemset/problem/387/C 题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数 ...
- cf B George and Round
题意:输入n,m,下一行为n个数a1<a2<a3......<an:然后再输入m个数b1<=b2<=b3<.....<=bm: 每个ai都必须在b中找到相等的 ...
随机推荐
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- OSChina 的全文搜索设计说明 —— 索引过程
http://www.oschina.net/question/12_71591 言: OSChina 的搜索做得并不好,很久之前一直想在细节方面进行改造,一直也没什么好的思路.但作为整体的结构或许对 ...
- unity3D与网页的交互
由于项目需要,要求用unity来展示三维场景,并在三维中能够方便的查询数据库等.一开始尝试在unity中直接连接数据库,当时连的xml,然而每次发布成网页后都会出现路径找不到等问题,所以迫不得已采用了 ...
- 《REWORK》启示录 招聘笔杆子——程序员为什么值得写博客
Hire Great Writers 仿佛这是写给自己看的,不过这在其中也有着相当有趣的意义 .虽然自己算是一个能写的人,或许这算是一种不算才华的才华,写博文的意义通常不会在于去描述自己怎样,怎样.通 ...
- codevs 访问艺术馆
/* codevs 1163 访问艺术馆 红果果的树形dp*/ #include<iostream> #include<cstdio> #include<cstring& ...
- Winform 程序中dll程序集嵌入exe可执行文件
关于这方面,Google一下有很多方法,参考: http://blog.csdn.net/astonqa/article/details/7300856 但按照以上的方法我并没有成功,于是继续找到了一 ...
- jQuery作用
jquery是前端里面比较总要的,是很强大的一个选择器. 表单: 1.$(":input") 查找所有的input元素 2.$("text") 匹配所有的 ...
- js自定义方法名
自定义方法名: <script language="javascript" type="text/javascript">window.onload ...
- Linux运行C#程序
首先需要安装mono 安装教程http://www.cnblogs.com/aixunsoft/p/3422099.html 然后 用终端执行C#程序就可以了,mono 程序文件名 可以直接执行win ...
- 详细查看数据库SQL执行计划
DBCC DROPCLEANBUFFERS 清除数据缓存DBCC FREEPROCCACHE 清除执行计划缓存 SET SHOWPLAN_XML ON 此语句导致 SQL Server 不执行 Tr ...