题解:

二分+树状数组

记录以下i在当前拍第几

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=;
int a[N],f1[N],f2[N],n,m,x,y,num[N];
int js(int x)
{
int ans=;
for (;x;x-=x&-x)ans+=num[x];
return ans;
}
void inster(int x,int y)
{
for (;x<=n;x+=x&-x)num[x]+=y;
}
int cmp(int x,int y)
{
return a[x]<a[y];
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)scanf("%d",&a[i]),f1[i]=f2[i]=i;
sort(f1+,f1+n+,cmp);
for (int i=;i<=n;i++)f2[f1[i]]=i;
for (int i=;i<=n;i++)inster(i,a[f1[i]]-a[f1[i-]]);
while (m--)
{
scanf("%d%d",&x,&y);
if (x==)
{
if (js(n)<y){puts("");continue;}
int l=,r=n;
while (l<r)
{
int mid=(l+r)/;
if (y>js(mid))l=mid+;
else r=mid;
}
printf("%d\n",n-l+);
}
if (x==)
{
if (js(n)<y)continue;
int l=,r=n;
while (l<r)
{
int mid=(l+r)/;
if (y>js(mid))l=mid+;
else r=mid;
}
inster(l,-);
}
if (x==)
{
int l=,r=n,k=js(f2[y]);
while (l<r)
{
int mid=(l+r+)/;
if (k<js(mid))r=mid-;
else l=mid;
}
swap(f1[f2[y]],f1[l]);
swap(f2[f1[f2[y]]],f2[f1[l]]);
inster(l,);
inster(l+,-);
}
}
}

spoj8406的更多相关文章

随机推荐

  1. Python3基础 file open+write 对不存在的txt进行创建与写入

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. linux下去掉pdf的密码(前提:知道密码)

    一.背景 Linux jello 4.16.3 SMP Thu Apr 19 07:32:02 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 二.去掉密码 2.1 先 ...

  3. 【SVN】Linux搭建SVN服务

    1.yum安装svn yum install -y subversion 日志打印 Loaded plugins: fastestmirror Determining fastest mirrors ...

  4. [BZOJ4391][Usaco2015 dec]High Card Low Card dp+set+贪心

    Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of ...

  5. 【Coursera】Security Introduction -Eighth Week(1)

    Security Introduction People With Bad Intent 今天,Bob 向 Alice 发送了一条 "Hello,Allice!" 的信息,他们希望 ...

  6. HDU 6073 Matching In Multiplication(拓扑排序+思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=6073 题意:有个二分图,左边和右边的顶点数相同,左边的顶点每个顶点度数为2.现在有个屌丝理解错了最佳完美匹配,它 ...

  7. UVa 11054 Gergovia的酒交易

    https://vjudge.net/problem/UVA-11054 题意:直线上有n个等距的村庄,每个村庄要么买酒,要么卖酒.设第i个村庄对酒的需求为ai,ai>0表示买酒,ai<0 ...

  8. MVC ---- ckeditor 循环遍历并绑定blur事件

    function GetFollowList(page) { , pages: page }; pages = JSON.stringify(pages); var datas = { param: ...

  9. 关于Mybatis 的 Mapped Statements collection does not contain value for 异常 解决方案

    查看堆栈信息: at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:595) at org.apac ...

  10. MongoDB(课时22 过期索引)

    3.6.2 过期索引 在一些程序的站点会出现若干秒之后信息被删除的情况,例如:手机信息验证码,那么在MongoDB里面可以轻松实现过期索引.但这个时间往往不怎么准确. 范例:设置过期索引(实现过期索引 ...