[JLOI2013]删除物品 树状数组
当时考试时间剩下太短了然后就挂掉了。。其实是个简单的数据结构。
#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]删除物品 树状数组的更多相关文章
- [bzoj3192][JLOI2013]删除物品(树状数组)
3192: [JLOI2013]删除物品 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 872 Solved: 508[Submit][Status ...
- 1057. Stack (30) - 树状数组
题目如下: Stack is one of the most fundamental data structures, which is based on the principle of Last ...
- [bzoj3192][JLOI2013]删除物品_树状数组_栈
删除物品 bzoj-3192 JLOI-2013 题目大意:给你n个物品,分成2堆.所有的物品有不同的优先级.我只可以将一堆中的堆顶移动到另一个堆的堆顶.而如果当前物品是全局所有物品中优先级最高的,我 ...
- BZOJ 3192: [JLOI2013]删除物品(树状数组)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=3192 题解: 首先每次一定是来回移动直到最大的到顶上. 所以我们可以将第两个堆的堆顶接起来 ...
- BZOJ 3192: [JLOI2013]删除物品 奇淫技巧&树状数组
点我看题 这题十分奇淫技巧...QAQ因为知道是树状数组的题QAQ刚开始以为维护两个数组的树状数组然后模拟从大到小,然后发现不会打QAQ 于是悄悄咪咪翻开题解了. 实际上两个数组可以看做一个数组 如 ...
- bzoj3192: [JLOI2013]删除物品(树状数组)
既然要从一个堆的堆顶按顺序拿出来放到第二个堆的堆顶,那么我们就可以把两个堆顶怼在一起,这样从一个堆拿到另一个堆只需要移动指针就好了. 换句话说,把1~n倒着,n+1到n+m正着,用一个指针把两个序列分 ...
- HDU-3436 Queue-jumpers 树状数组 | Splay tree删除,移动
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3436 树状数组做法<猛戳> Splay tree的经典题目,有删除和移动操作.首先要离散化 ...
- 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]]+ ...
- 3192: [JLOI2013]删除物品
3192: [JLOI2013]删除物品 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1366 Solved: 794 [Submit][Statu ...
随机推荐
- css之选择器总结
首先我们来看下有哪些选择器??? 一.基础选择器: html标签选择器:通过html标签来选择元素. ①所有的html标签都可以当做选择器. ②无论标签藏多深都会被选中. ③选择的是所有的标签而不是某 ...
- 遇到attemp to invoke virtual method
这个很大原因是没有预先初始化sdk,检查application的配置是否配置了application:name
- c++有关构造函数和析构函数中调用虚函数问题
今天看了一道迅雷的笔试题目,然后引起一段思考,题目如下: 下列关于虚函数的说法正确的是()A.在构造函数中调用类自己的虚函数,虚函数的动态绑定机制还会生效.B.在析构函数中调用类自己的虚函数,虚函数的 ...
- android权限(permission)大全
权限添加位置: 权限代码: 1.android.permission.WRITE_USER_DICTIONARY允许应用程序向用户词典中写入新词 2.android.permission.WRITE_ ...
- spring +springmvc+mybatis组合总结
springmvc+spring+mybatis整合:1. 拷贝所需jar2. 创建spring配置文件(beans.xml)3. 配置数据源 <bean id="dataSource ...
- Postgresql快速写入/读取大量数据(.net)
环境及测试 使用.net驱动npgsql连接post数据库.配置:win10 x64, i5-4590, 16G DDR3, SSD 850EVO. postgresql 9.6.3,数据库与数据都安 ...
- javascript 实现 对XML文件 2级/3级联动操作
js代码 //实现对xml文档的读取:function loadXMLDoc(dname) { try // Internet Explorer { xmlDoc = new ActiveXObjec ...
- Invert a binary tree 翻转一棵二叉树
Invert a binary tree 翻转一棵二叉树 假设有如下一棵二叉树: 4 / \ 2 7 / \ / \ 1 3 6 9翻转后: 4 / \ 7 ...
- Linux 显示文本指定行内容
主要采用sed.head和tail命令 如果文本中使用了 \n 这类符号,cat命令会把它当成换行符,结果会出错 $ sed -n "10p" move.sh # 显示第10行 ...
- AddDigitsTotal - 把数字中单个数相加
给定一个int数字,把数字中的单个数相加起来:得到的结果如果不是个位数,继续相加 如给定 19,执行1+9 = 10 --> 1 + 0 = 1 返回1 给定22,返回4 思路很简单,把各个位 ...