当时考试时间剩下太短了然后就挂掉了。。其实是个简单的数据结构。

话说一看最小还以为是动规呢。。
将两堆头对头排。比如样例就是 541|273
因为是必须有优先级次序,依次拿的话,看优先级大小相邻的两个物品位置,中间隔着多少其他物品就行了。因为你要移动相邻的两个,你肯定得把它们中间的所有物品移动一遍(因为两个都得先后在最上边)。
标好号,用前缀和,拿树状数组维护,拿走之后变为0。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 200000
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
int n1,n2;
int n;
inline int read()
{
    int su=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
       ch=getchar();
    while(ch<='9'&&ch>='0')
    {
       su=su*10+ch-'0';
       ch=getchar();
    }

    return su;
}
struct haha
{
       int num;
       int pos;
}cun[N];
int c[N];
inline int lowbit(int x)
{
    return x&(-x);
}
inline void add(int i,int x)
{
     while(i<=n)
     {
        c[i]+=x;
        i+=lowbit(i);
     }
}
int temp;
inline int cmp(const haha &a,const haha &b)
{
    return a.num>b.num;
}
int ans;
inline int tot(int x)
{
    int sum=0;
    while(x>0)
    {
       sum+=c[x];
       x-=lowbit(x);
    }
    return sum;
}
inline int Sum(int i,int j)
{
    if(tot(j)>tot(i-1))
      return tot(j)-tot(i-1);
    else
      return tot(i)-tot(j-1);
}
inline int haha()
{
    n1=read();
    n2=read();
    n=n1+n2;
    pos(i,1,n1)
    {
         cun[i].num=read();
         if(cun[i].num>temp)
         {
           temp=cun[i].num;
           ans=i;
         }
         cun[i].pos=n1-i+1;
    }
    pos(i,1,n2)
    {
          cun[n1+i].num=read();
          if(cun[n1+i].num>temp)
          {
            temp=cun[n1+i].num;
            ans=i;
          }
          cun[n1+i].pos=n1+i;
    }
    sort(cun+1,cun+n1+n2+1,cmp);
    ans--;
    pos(i,1,n)
      add(i,1);

    add(cun[1].pos,-1);
    //cout<<tot(n);
    pos(i,2,n)
    {
       ans+=Sum(cun[i].pos,cun[i-1].pos);
       ans--;
       add(cun[i].pos,-1);
    }
    printf("%d",ans);
}
int sb=haha();
int main()
{;;}

  

[JLOI2013]删除物品 树状数组的更多相关文章

  1. [bzoj3192][JLOI2013]删除物品(树状数组)

    3192: [JLOI2013]删除物品 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 872  Solved: 508[Submit][Status ...

  2. 1057. Stack (30) - 树状数组

    题目如下: Stack is one of the most fundamental data structures, which is based on the principle of Last ...

  3. [bzoj3192][JLOI2013]删除物品_树状数组_栈

    删除物品 bzoj-3192 JLOI-2013 题目大意:给你n个物品,分成2堆.所有的物品有不同的优先级.我只可以将一堆中的堆顶移动到另一个堆的堆顶.而如果当前物品是全局所有物品中优先级最高的,我 ...

  4. BZOJ 3192: [JLOI2013]删除物品(树状数组)

    题面: https://www.lydsy.com/JudgeOnline/problem.php?id=3192 题解: 首先每次一定是来回移动直到最大的到顶上. 所以我们可以将第两个堆的堆顶接起来 ...

  5. BZOJ 3192: [JLOI2013]删除物品 奇淫技巧&树状数组

    点我看题 这题十分奇淫技巧...QAQ因为知道是树状数组的题QAQ刚开始以为维护两个数组的树状数组然后模拟从大到小,然后发现不会打QAQ 于是悄悄咪咪翻开题解了. 实际上两个数组可以看做一个数组 如 ...

  6. bzoj3192: [JLOI2013]删除物品(树状数组)

    既然要从一个堆的堆顶按顺序拿出来放到第二个堆的堆顶,那么我们就可以把两个堆顶怼在一起,这样从一个堆拿到另一个堆只需要移动指针就好了. 换句话说,把1~n倒着,n+1到n+m正着,用一个指针把两个序列分 ...

  7. HDU-3436 Queue-jumpers 树状数组 | Splay tree删除,移动

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3436 树状数组做法<猛戳> Splay tree的经典题目,有删除和移动操作.首先要离散化 ...

  8. Educational Codeforces Round 87 (Rated for Div. 2) D树状数组加二分删除的值

    Sample Input 5 4 1 2 3 4 5 -5 -1 -3 -1 Sample Output 3 思路,首先发现a[i]的值的范围是在1~n之间,每次插入我们可以直接把cnt[a[i]]+ ...

  9. 3192: [JLOI2013]删除物品

    3192: [JLOI2013]删除物品 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1366 Solved: 794 [Submit][Statu ...

随机推荐

  1. 【LeetCode】171. Excel Sheet Column Number

    题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...

  2. Example004自动关闭的广告窗口

    <!-- 实例004自动关闭的广告窗口--> <!-- 3秒后关闭 --> <body onload="window.setTimeout('window.cl ...

  3. 7.modifier插件的自定义和使用

    1.在plugins下面创建一个文件 modifier.changeDate.php 编写: <?php function smarty_modifier_changeDate($utime,$ ...

  4. android源码 分享1

    技术博客       "碎片化"严重,安卓走向封闭?[Bus Weekly]48期   阅读数:286   2017-05-08   按照NetMarketShare统计数据显示, ...

  5. TCP 连接重置漏洞 - CVE-2004-0230讲解

    TCP 连接重置漏洞 - CVE-2004-0230: IPv6 实施中存在一个拒绝服务漏洞,该漏洞可能允许攻击者向受影响系统发送特制的 TCP 消息. 成功利用此漏洞的攻击者可能会导致受影响系统重置 ...

  6. Spark Standalone Mode Configuration

    For currently popular distributed framework Spark, here is the intro and step to configure the spark ...

  7. [NOIP2013/Codevs3287]货车运输-最小[大]生成树-树上倍增

    Problem 树上倍增 题目大意 给出一个图,给出若干个点对u,v,求u,v的一条路径,该路径上最小的边权值最大. Solution 看到这个题第一反应是图论.. 然而,任意路径最小的边权值最大,如 ...

  8. python基础(2):python的变量和常量

    今天看看python的变量和常量:python3 C:\test.py 首先先说一下解释器执行Python的过程: 1. 启动python解释器(内存中) 2. 将C:\test.py内容从硬盘读入内 ...

  9. shiro整合oauth

    一.基本思路脑图 二.客户端shiro配置 shiro配置文件 <?xml version="1.0" encoding="UTF-8"?> < ...

  10. 使用boost/property_tree进行XML操作

    之前一直用tinyxml来进行XML文件操作,刚刚接触的一个测试项目是使用boost操作的,虽然不清楚这两者的差异,但boost使用起来还挺方便的,所以简单整理一些关于boost解析和创建XML文件的 ...