【BZOJ】【P3192】【JLOI2013】【删除物品】【题解】【BIT】
来源:互联网 发布:wlan直连软件 编辑:程序博客网 时间:2024/05/19 00:14
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3192
感觉最近状态不好啊……一边给bc出题一边打aicraft,刷题也只能刷这种水题……
显然此题就是裸模拟
把两个堆连接起来,BIT模拟即可
Code:
#include<bits/stdc++.h>#define fst first#define sec second#define lowbit(x) (x&-x)using namespace std;const int maxn=1e5+5;typedef pair<int,int> pi;int n1,n2,n;pi a[maxn];int d[maxn];void updata(int x,int f){while(x<=n)d[x]+=f,x+=lowbit(x);}int get(int x){int o=0;while(x)o+=d[x],x-=lowbit(x);return o;}int main(){scanf("%d%d",&n1,&n2);n=n1+n2+1;for(int i=n1;i>=1;i--)scanf("%d",&a[i].fst);for(int i=n1+2;i<=n;i++)scanf("%d",&a[i].fst);int cur=n1+1;a[cur].sec=cur;for(int i=1;i<=n;i++)if(i!=cur)updata(i,1),a[i].sec=i;sort(a+1,a+1+n,greater<pi>());long long ans=0;for(int i=1;i<n;i++){int l=a[i].sec,r=cur;if(l>r)swap(l,r);ans+=get(r)-get(l-1)-1;cur=a[i].sec;updata(cur,-1);}cout<<ans<<endl;return 0;}
0 0
- 【BZOJ】【P3192】【JLOI2013】【删除物品】【题解】【BIT】
- 【BZOJ 3192】 [JLOI2013]删除物品
- bzoj 3192: [JLOI2013]删除物品
- BZOJ 3192 [JLOI2013]删除物品
- bzoj 3192: [JLOI2013]删除物品
- bzoj 3192: [JLOI2013]删除物品
- BZOJ 3192: [JLOI2013]删除物品
- bzoj 3192: [JLOI2013]删除物品 树状数组
- [BZOJ]3192: [JLOI2013]删除物品 树状数组
- bzoj 3192: [JLOI2013]删除物品 树状数组
- [BZOJ3192][JLOI2013]删除物品
- 3192: [JLOI2013]删除物品
- bzoj3192: [JLOI2013]删除物品
- 3192: [JLOI2013]删除物品
- bzoj3192 [JLOI2013]删除物品
- bzoj3192【JLOI2013】删除物品
- 【JLOI2013】bzoj3192 删除物品
- BZOJ3192 [JLOI2013]删除物品
- java学习day15
- OC使用引用计数的内存管理
- docx4j学习笔记(3)
- Python Exception的一个妙用
- #define新用法
- 【BZOJ】【P3192】【JLOI2013】【删除物品】【题解】【BIT】
- Javascript 的addEventListener()及attachEvent()区别分析
- windows下Django框架的搭建及测试教程
- 实习总结
- Eigrp md5认证
- ROS 教程之 navigation : 用 move_base 控制自己的机器人(2)
- Can't Find Theme.AppCompat.Light for New Android ActionBar Support
- 动态规划、最短路径、Floyd算法
- 重生, 燃烧的生命