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. hdoj 3157 Crazy Circuits 【有下界最小流】

    题目:hdoj 3157 Crazy Circuits 题意:如今要制造一个电路板.电路板上有 n 个电子元件,各个元件之间有单向的电流流向.然后有一个 + .电流进入, -- 电流汇入,然后推断能不 ...

  2. C# 保存窗口为图片(保存纵断面图)

    源代码例如以下: #region 保存纵断面截图 private void button_save_Click(object sender , EventArgs e) { SaveFileDialo ...

  3. 免费WiFi,仅仅为好久没联系的你们

    昨日,认识五年的朋友搬来与我一起住了,说不上来,没有激动,仅仅是突然感觉生活又多了一点生机.兴致上来,晚上立马联系了已经近四个月没有联系的好友,才知道他们的生活也因这几个月发生了翻天覆地的变化.究竟什 ...

  4. Qt绘图之QGraphicsScene QGraphicsView QGraphicsItem详解

    Graphics View提供了一个界面,它既可以管理大数量的定制2D graphical items,又可与它们交互,有一个view widget可以把这些项绘制出来,并支持旋转与缩放.这个柜架也包 ...

  5. html、body、document、window的区别

    html是一门超文本标记语言: document对象代表整个html文档,可用来访问页面中的所有元素: body代表document的主体子对象,除浏览器头部,页面中能够看到的内容都属于body中的内 ...

  6. error: device not found - waiting for device -

    执行 cocos run -p android 时报的这个错误 连接上 android 手机, 手机开启开发者模式.  设置--其他高级设置--开发者选项--USB 调试

  7. PHP错误类型及屏蔽方法

    1. 注意(Notices)这些都是比较小而且不严重的错误,比如去访问一个未被定义的变量.通常,这类的错误是不提示给用户的,但有时这些错误会影响到运行的结果. 2. 警告(Warnings)这就是稍微 ...

  8. inner join

    select Person.LastName,Person.FirstName,Orders.OrderNo from Persons INNER JOIN Orders ON Person.Id_P ...

  9. OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

    1.安装Homebrew,执行命令 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  10. python sklearn模型的保存

    使用python的机器学习包sklearn的时候,如果训练集是固定的,我们往往想要将一次训练的模型结果保存起来,以便下一次使用,这样能够避免每次运行时都要重新训练模型时的麻烦. 在python里面,有 ...