hdu2688树状数组
来源:互联网 发布:手机 ipv6网络电视 编辑:程序博客网 时间:2024/05/16 23:36
#include<cstdio>#include<cstring>#include<cstdlib>const int maxn=30000005;typedef __int64 ll;int n,a[maxn];ll c[10005];int lowbit(int x){ return x & (-x);}void Update(int x){ while(x<=10000) { c[x]++; x+=lowbit(x); }}ll Query(int x){ ll ans=0; while(x>0) { ans+=c[x]; x-=lowbit(x); } return ans;}int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); memset(c,0,sizeof(c)); int m,x,y; char ch[2]; ll ans=0; for(int i=1;i<=n;i++) { ans+=Query(a[i]-1); Update(a[i]); } scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%s",ch); if(ch[0]=='Q') { printf("%I64d\n",ans); } else { scanf("%d %d",&x,&y); x++,y++; int t=a[x]; for(int j=x;j<y;j++) { a[j]=a[j+1]; if(t>a[j]) ans++; if(t<a[j]) ans--; } a[y]=t; } } } return 0;}
0 0
- hdu2688 Rotate (树状数组)
- hdu2688树状数组
- hdu2688 Rotate(树状数组)
- hdu2688 Rotate(树状数组)
- 树状数组_Rotate HDU2688
- 树状数组专题(十一)之hdu2688
- 09-09 HDU_Steps5.3 树状数组,LCA HDU1166 HDU2492 HDU3584 HDU2586 HDU2874 HDU3486 HDU2688
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 得到window区域位置
- python random
- 自适应多级Iframe高度
- HDU-1348 Wall 凸包
- android跨语言之数据共享
- hdu2688树状数组
- 面向集团客户云计算运营平台的运营开通技术方案及应用架构——之云计算运营平台方案(三)
- 【USACO 2013 March Gold】奶牛逃跑
- 源码安装php5.5.7 php-fpm和xcache,以及xcache管理后台
- ServerSocket和Socket建立通信(服务器和客户端循环接收发送)
- Qt中请string,int, char , QBattyArray的转换
- Flex与Flash的关系
- 总结过去10年的程序员生涯
- 利用正则表达式匹配标点问题