hdu 2688_Rotate(树状数组,求顺序对数)
来源:互联网 发布:淘宝晒单怎么晒 编辑:程序博客网 时间:2024/05/21 08:38
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2688
题目大意:求一序列的顺序数对有几个,对应着不同的操作,有查询和更改;
题目思路:用A[i]存序列,注意从0开始存的,然后C[i]存小于和等于i的数有几个
题目:
Rotate
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1463 Accepted Submission(s): 380
Problem Description
Recently yifenfei face such a problem that give you millions of positive integers,tell how many pairs i and j that satisfy F[i] smaller than F[j] strictly when i is smaller than j strictly. i and j is the serial number in the interger sequence. Of course, the problem is not over, the initial interger sequence will change all the time. Changing format is like this [S E] (abs(E-S)<=1000) that mean between the S and E of the sequece will Rotate one times.
For example initial sequence is 1 2 3 4 5.
If changing format is [1 3], than the sequence will be 1 3 4 2 5 because the first sequence is base from 0.
For example initial sequence is 1 2 3 4 5.
If changing format is [1 3], than the sequence will be 1 3 4 2 5 because the first sequence is base from 0.
Input
The input contains multiple test cases.
Each case first given a integer n standing the length of integer sequence (2<=n<=3000000)
Second a line with n integers standing F[i](0<F[i]<=10000)
Third a line with one integer m (m < 10000)
Than m lines quiry, first give the type of quiry. A character C, if C is ‘R’ than give the changing format, if C equal to ‘Q’, just put the numbers of satisfy pairs.
Each case first given a integer n standing the length of integer sequence (2<=n<=3000000)
Second a line with n integers standing F[i](0<F[i]<=10000)
Third a line with one integer m (m < 10000)
Than m lines quiry, first give the type of quiry. A character C, if C is ‘R’ than give the changing format, if C equal to ‘Q’, just put the numbers of satisfy pairs.
Output
Output just according to said.
Sample Input
51 2 3 4 53QR 1 3Q
Sample Output
108
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int size=10005;int A[3000000],C[size];int lowbit(int x){ //return x&(x^(x-1)); return x&-x;}__int64 sum(int end){ __int64 ans=0; while(end>0) { ans+=C[end]; end-=lowbit(end); } return ans;}void updata(int pos,int num){ while(pos<size) { C[pos]+=num; pos+=lowbit(pos); }}int main(){ int N,M; while(scanf("%d",&N)!=EOF) { __int64 ans=0; memset(C,0,sizeof(C)); for(int i=0; i<N; i++) { scanf("%d",&A[i]); ans+=sum(A[i]-1); updata(A[i],1); } scanf("%d",&M); char op[10]; int ss,ee; while(M--) { scanf("%s",op); if(op[0]=='Q') { printf("%I64d\n",ans); } else { scanf("%d%d",&ss,&ee); int v=A[ss]; for(int i=ss; i<ee; i++) { A[i]=A[i+1]; if(v<A[i]) { ans--; } if(v>A[i]) { ans++; } } A[ee]=v; } } } return 0;}
- hdu 2688_Rotate(树状数组,求顺序对数)
- hdu 4911 求逆序对数+树状数组
- 树状数组_Rotate HDU2688
- 树状数组求逆序对数
- 《树状数组求逆序对数》
- 树状数组求Thair对数
- HDU 4911 Inversion(树状数组求逆序对数 + 数据离散化)
- 离散化+树状数组 求逆序对数
- 树状数组求逆序对数板子
- HDU 2688 Rotate(树状数组---求正序数)
- hdu 2688 树状数组求 序列对
- HDU 2689.求逆序(树状数组)
- POJ 2299 Ultra-QuickSort 求逆序对数(归并排序,树状数组)
- 蓝桥杯 历届试题 小朋友排队(归并,树状数组求逆序对数)
- (POJ 2299)Ultra-QuickSort 树状数组求逆序对数 + 离散化
- SGU 180-Inversions(树状数组离散化求逆序对数)
- POJ 2299 利用树状数组求逆序对数
- POJ-2299 Ultra-QuickSort (树状数组 离散 求逆序对数)
- cocos2d-x游戏开发(三)游戏主循环
- 老罗Android开发视频教程( android解析json数据 )4集集合
- ibatis中输入/输出各种类型的参数分析及#与$区别
- Android获取SD卡上的APK文件,并且判断是否安装过、是否可以更新到新版本的工具类
- Linux下生成和使用/静态和动态库
- hdu 2688_Rotate(树状数组,求顺序对数)
- 百度搜索结果页面的参数_反馈搜索结果用时(rsv_sug4)
- Android广播机制
- CreateGraphics().Draw...绘图消失的解决办法
- ContentProvider相关
- write调用的原子性
- 寒假集训作业(8)——数学问题
- 用SQL语句添加删除修改字段
- Upatepanel的基本使用