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的更多相关文章

  1. cf B George and Cards

    题意:给你一个只有‘.’和'#'的n*n的格子,问所有的'#'是不是只属于一个十字叉,如果不是输出NO,否则输出YES. #include <cstdio> #include <cs ...

  2. 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 ...

  3. 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 问题描述 ...

  4. Codeforces 387E George and Cards

    George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...

  5. cf 546C Soldier and Cards

    题目链接:C. Soldier and Cards Two bored soldiers are playing card war. Their card deck consists of exact ...

  6. George and Cards

    Codeforces Round #227 (Div. 2) E:http://codeforces.com/contest/387/problem/E 题意:给你一个n个数的序列,然后给你一个标准序 ...

  7. cf D George and Interesting Graph

    题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边. 思路:枚举根 ...

  8. cf C. George and Number

    http://codeforces.com/problemset/problem/387/C 题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数 ...

  9. cf B George and Round

    题意:输入n,m,下一行为n个数a1<a2<a3......<an:然后再输入m个数b1<=b2<=b3<.....<=bm: 每个ai都必须在b中找到相等的 ...

随机推荐

  1. C#邮件接收系统核心代码(接收POP3邮件IMAP邮件)

    /* * Created by SharpDevelop. * User: Administrator * Date: 2013/11/18 * Time: 20:55 * * To change t ...

  2. MySql The service could not be started

    MySql安装 由于需要用mySql数据库今天就把它安上了,每次安装软件,数据库总是够我们折腾的,有时出现错误甚至比重装系统还要让人头疼. 今天在安的过程中就不出了很多错误,在重启与重装的反复捣鼓中终 ...

  3. iOS 使用Charts框架 折线,柱状,K线,饼状,雷达全攻略

    我是前言: 大约几个月前我在某平台写了一篇文章, 文中简单地介绍了Charts两种图表的样式的使用, 不过有种意犹未尽的感觉, 利用周末的空闲时间再次看了看, 有了新的收获, 今天发出来,分享给大家, ...

  4. Java基础知识强化11:多态的两道基础题

    1.第1题 class Base { public void method() { System.out.print("Base method"); } } class Child ...

  5. 'Service' object has no attribute 'process'

    在使用selenium+phantomjs时,运行总是出现错误信息: 'Service' object has no attribute 'process' 出现该错误的原因是未能找到可执行程序&qu ...

  6. Python开发【第十三篇】:jQuery(二)

    http://www.bubuko.com/infodetail-1438296.html 处理完毕需要整理贴进来 Python之路[第十三篇]jQuery案例-Form表单&插件及扩展   ...

  7. Stream流的读取使用

    这个是在现在的项目里,用到的知识点,一般用不到这些..所以想着还是记下来以后用. 针对文本流 //StreamReader sr = new StreamReader(mystream,Encodin ...

  8. js时间字符串转Date对象

    var DATE_REGEXP = new RegExp("(\\d{4})-(\\d{2})-(\\d{2})([T\\s](\\d{2}):(\\d{2}):(\\d{2})(\\.(\ ...

  9. JAVA除去制定字符的方法

    只需调用replaceAll()方法: public class Test { public static void main(String[] args) { String s= "abc ...

  10. Oracle分区表学习

    (1) 表空间及分区表的概念表空间: 是一个或多个数据文件的集合,所有的数据对象都存放在指定的表空间中,但主要存放的是表, 所以称作表空间.分区表: 当表中的数据量不断增大,查询数据的速度就会变慢,应 ...