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. emacs命令记录

    C-代表按住Ctrl键 M-代表按住Alt键,也可以用按一下ESC放开代替   最先要记住的 M-x <cmd>      输入指令执行,在输入时用Tab可以自动补全或列出项目 C-g   ...

  2. java创建目录与文件

    java创建目录与文件: package com.led.file; import java.io.File; import java.io.IOException; public class Fil ...

  3. python使用mongodb

    系统环境:Windows 10 ,python3.x 1.安装mongodb mongodb下载官网:https://www.mongodb.com/download-center?jmp=nav#c ...

  4. h5 测试关注点

    原文链接:http://www.blogjava.net/qileilove/archive/2014/07/24/416154.html?utm_source=tuicool&utm_med ...

  5. Informatica学习:1、安装介质的获取与安装

    本文目标: 为方便学习Informatica工具,在个人电脑上部署Informatica Powercenter. 所用系统:win7 64位. Informatica安装包括服务器端.客户端安装两个 ...

  6. C#设计模式(4)-抽象工厂模式

    引言 上一篇介绍了设计模式中的简单工厂模式-C#设计模式(3)-工厂方法模式,本篇将介绍抽象工厂模式: 抽象工厂模式简介 抽象工厂模式(AbstractFactory):提供一个创建一系列相关或相互依 ...

  7. java8 去掉 perm 用 Metaspace 来替代

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt266 正如大家所知,JDK 8 Early Access版已经提供下载.这使 ...

  8. 用JS控制CSS基本样式

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp29 用JS控制CSS基本样式的方法 CSS code .class1 { ...

  9. 【C++小白成长撸】--矩阵乘法程序

    矩阵乘法是大学矩阵课程中,相比矩阵加减法比较困难的部分. 矩阵乘法的原理: 矩阵乘法在代码中实现 得到目标矩阵的一个元素,涉及两个求和符号,一个求和符号一个for循环,两个求和符号两个for循环,再加 ...

  10. idea 给maven项目添加依赖(二)

    这里接着上一篇来 我们观察目录发现有两个pom.xml(project object module) 项目是里面的,所以外面的先不管它. 点击里面的pom.xml 1.在<url>节点下面 ...