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. 

InputThe 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. 
OutputOutput just according to said.Sample Input

5
1 2 3 4 5
3
Q
R 1 3
Q

Sample Output

10
8

题解

这道题我们可以用树状数组求出原数组的答案

因为abs(E-S)<=1000,m<10000,所以我们可以枚举每次的区间,因为翻转每次是S+1~E往前移一位,第S个到E

所以我们先把第S位存下来,每次和后面的判断一下大小就可以了

当输入是Q的时候就直接输出就可以了

 #include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define M 10005
#define N 3000005
using namespace std;
int n,m,x,y;
ll ans;
int a[N];
ll tr[M];
char s[];
int lowbit(int x){ return x&(-x); }
void add(int x){
while (x<=M){
tr[x]++;
x+=lowbit(x);
}
}
int query(int x){
int s=;
while (x>){
s+=tr[x];
x-=lowbit(x);
}
return s;
}
int main(){
while (~scanf("%d",&n)){
memset(tr,,sizeof(tr)); ans=;
for (int i=;i<n;i++){
scanf("%d",&a[i]);
add(a[i]);
ans+=query(a[i]-);
}
scanf("%d",&m);
for (int i=;i<=m;i++){
scanf("%s",s);
if (s[]=='Q') printf("%lld\n",ans);
else{
scanf("%d%d",&x,&y);
int s=a[x];
for (int i=x;i<y;i++){
a[i]=a[i+];
if (s<a[i]) ans--; else
if (s>a[i]) ans++;
}
a[y]=s;
}
}
}
return ;
}

HDU2688-Rotate的更多相关文章

  1. hdu2688 Rotate(树状数组)

    题目链接:pid=2688">点击打开链接 题意描写叙述:对一个长度为2<=n<=3000000的数组,求数组中有序对(i<j而且F[i]<F[j])的数量?其 ...

  2. Canvas绘图之平移translate、旋转rotate、缩放scale

    画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transform()来改变,它们会对画布的变换矩阵产生影响. 函数 方法 描 ...

  3. [LeetCode] Rotate Array 旋转数组

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  4. [LeetCode] Rotate List 旋转链表

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  5. [LeetCode] Rotate Image 旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  6. jQuery.rotate.js参数

    CSS3 提供了多种变形效果,比如矩阵变形.位移.缩放.旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动.然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(fil ...

  7. CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)

    CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)   在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾 ...

  8. 偏移:translate ,旋转:rotate,缩放 scale,不知道什么东东:lineCap 实例

    <!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</ ...

  9. 记一道有意思的算法题Rotate Image(旋转图像)

    题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an ...

  10. iOS 2D绘图 (Quartz2D)之Transform(CTM,Translate,Rotate,scale)

    前言:Quartz默认采用设备无关的user space来进行绘图,当context(画板)建立之后,默认的坐标系原点以及方向也就确认了,可以通过CTM(current transformation ...

随机推荐

  1. 聚币网API[Python2版]

    聚币 现货 API [Python2版] 一.utils.py,基础类,包括HTTP 请求.签名等 # -*- coding: utf-8 -*- import hashlib import hmac ...

  2. Extjs6获取Grid里的数据(数据源)

    { xtype: 'grid', sortableColumns: false, reference: 'grid', flex: 1, store: 'panoram.Panoram', colum ...

  3. zoj 3659 Conquer a New Region The 2012 ACM-ICPC Asia Changchun Regional Contest

    Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history roll ...

  4. JavaScrpt笔记之第二天

    JavaScript正则表达式regex 1.郑则表达式是有一个字符序列形成的搜索模式. *语法:/正则表达式主题/修饰符(可选) *正则表达式修饰符:i部分大小写:g全局搜索:m多行匹配 *[abc ...

  5. switch处理多分支结构

    import java.util.Scanner; /** * Created by liwenj on 2017/7/17. */ public class test9 { public stati ...

  6. 浅析多线程 对象锁和Class锁

    一.前言 本来想在另外一篇文章说的,发现可能篇幅有点大,所以还是另开一篇博文来说好了.知识参考<Java多线程编程核心技术>,评价下这本书吧——大量的代码,简单的说明,真像在看博客.不过这 ...

  7. 编译安装LAMP并实现wordpress

    author:JevonWei 版权声明:原创作品 软件环境 centos7.3 apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 httpd-2.4.27.tar.b ...

  8. ASP.NET Core的身份认证框架IdentityServer4(7)- 使用客户端证书控制API访问

    前言 今天(2017-9-8,写于9.8,今天才发布)一口气连续把最后几篇IdentityServer4相关理论全部翻译完了,终于可以进入写代码的过程了,比较累.目前官方的文档和Demo以及一些相关组 ...

  9. 8.中断按键驱动程序之poll机制

    本节继续在上一节中断按键程序里改进,添加poll机制. 那么我们为什么还需要poll机制呢.之前的测试程序是这样: ) { read(fd, &key_val, ); printf(" ...

  10. MySQL中char与varchar区别,varchar最大长度是多少?

    一.首先来说下字符与字节的区别: 字符与字节它们完全不是一个位面的概念,所以两者之间没有"区别"这一说法.在不同编码里,字符和字节的对应关系是不同的.一般来说,半角英文状态下一个字 ...