【BZOJ】【P2789】【Poi2012】【Letters】【题解】【逆序对】
来源:互联网 发布:桂永清知乎 编辑:程序博客网 时间:2024/06/05 15:24
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2789
逆序对,不多说
Code:
#include<bits/stdc++.h>using namespace std;const int maxn=1e6+5;int d[maxn];int p[maxn];deque<int>v[233];char s1[maxn],s2[maxn];int n;#define lowbit(x) (x&-x)int get(int x){int ans=0;while(x)ans+=d[x],x-=lowbit(x);return ans;}void updata(int x,int f){while(x<=n)d[x]+=f,x+=lowbit(x);}int main(){scanf("%d",&n);scanf("%s",s1+1);scanf("%s",s2+1); for(int i=1;i<=n;i++) v[s1[i]-'A'].push_back(i); for(int i=1;i<=n;i++){ p[i]=v[s2[i]-'A'].front(); v[s2[i]-'A'].pop_front(); }long long ans=0; for(int i=1;i<=n;i++){ ans+=i-get(p[i])-1; updata(p[i],1); }cout<<ans<<endl;return 0;}
0 0
- 【BZOJ】【P2789】【Poi2012】【Letters】【题解】【逆序对】
- bzoj 2789 [Poi2012]Letters 求逆序对
- bzoj 2789: [Poi2012]Letters 树状数组求逆序对
- BZOJ 2789: [Poi2012]Letters
- [BZOJ 2789]POI2012 Letters
- bzoj 2789: [Poi2012]Letters
- BZOJ 2789: [Poi2012]Letters
- [BZOJ2789][Poi2012]Letters(树状数组求逆序对)
- 树状数组求逆序对-洛谷P3531 [POI2012]LIT-Letters
- 【BZOJ2789】【树状数组】[Poi2012]Letters 题解
- BZOJ 2789 Poi2012 Letters 树状数组
- bzoj 2789 [Poi2012]Letters 树状数组
- BZOJ 2789 Poi 2012 Letters 树状数组 逆序对
- BZOJ 2789 Letters题解&代码
- bzoj 2802: [Poi2012]Warehouse Store 题解
- 【BZOJ】【P2793】【Poi2012】【Vouchers】【题解】【乱搞】
- 【BZOJ】【P2802】【POI2012】【Warehouse Store】【题解】【贪心】
- 【BZOJ】【P3295】【CQOI2011】【动态逆序对】【题解】【树套树】
- CString 转换成string ---涉及UNICODDE
- iOS开发json解析之天气预报
- C/C++声明
- View
- hdu3001Travelling 状态压缩dp
- 【BZOJ】【P2789】【Poi2012】【Letters】【题解】【逆序对】
- C++学习笔记(三)string类
- CODEVS_1033 蚯蚓的游戏问题 网络流 最小费用流 拆点
- Codeigniter+PHPExcel中导出数据到Excel文件
- 改变vim注释的颜色
- vector
- 【bzoj 1093】: [ZJOI2007]最大半连通子图
- NIM(3)两堆石头的游戏
- 【线段树】 HDOJ 3627 Giant For