HDU2688-Rotate
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的更多相关文章
- hdu2688 Rotate(树状数组)
题目链接:pid=2688">点击打开链接 题意描写叙述:对一个长度为2<=n<=3000000的数组,求数组中有序对(i<j而且F[i]<F[j])的数量?其 ...
- Canvas绘图之平移translate、旋转rotate、缩放scale
画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transform()来改变,它们会对画布的变换矩阵产生影响. 函数 方法 描 ...
- [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 ...
- [LeetCode] Rotate List 旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- [LeetCode] Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- jQuery.rotate.js参数
CSS3 提供了多种变形效果,比如矩阵变形.位移.缩放.旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动.然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(fil ...
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)
CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate) 在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾 ...
- 偏移:translate ,旋转:rotate,缩放 scale,不知道什么东东:lineCap 实例
<!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</ ...
- 记一道有意思的算法题Rotate Image(旋转图像)
题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an ...
- iOS 2D绘图 (Quartz2D)之Transform(CTM,Translate,Rotate,scale)
前言:Quartz默认采用设备无关的user space来进行绘图,当context(画板)建立之后,默认的坐标系原点以及方向也就确认了,可以通过CTM(current transformation ...
随机推荐
- Git初学二(SSH免密)
在管理Git项目上,初学者使用HTTPS直接克隆项目到本地是最方便的.但是之后的fetch和push代码需要输入账号和密码也是比较烦的. 这章在上一章的基础上,将HTTPS切换成SSH.SSH的优点就 ...
- PHP 字符串替换
这是2017上半年的第一篇学习笔记,也是最后一篇,捂脸- 在前几天的工作中,关于"银行卡"页面原型如下,其中,不同银行卡的卡号只保留了最后四位数字可以显示,其他数字均用*字符隐藏了 ...
- jquery的2.0.3版本源码系列(2):21行-94行定义了一些变量和函数 jQuery=function(){}
2.1.bug通过索引查询 这里的#13335是bug的索引,如何查询呢? 第一步,浏览器地址栏输入"https://bugs.jquery.com/". 第二步,在网页的搜索框里 ...
- Java对象的创建
学了很久的java,是时候来一波深入思考了.比如:对象是如何在JVM中创建,并且被使用的.本文主要讲解下new对象的创建过程.要想更深入的了解建议去认认真真的看几遍<深入理解Java虚拟机> ...
- linux下操作mysql
有关mysql数据库方面的操作,必须首先登录到mysql中. 开启MySQL服务后,使用MySQL命令可以登录.一般使用mysql -uroot -p即可.如果数据库不是本机,则需要加参数,常用参数如 ...
- 后端路由项目由 gulp 改为 webpack 的踩坑实录
前言 公司有个后端路由的项目是用 gulp 作为前端自动化构建工具,最近学习了一下 webpack,深感其强大,一狠心将其改成了 webpack 构建,以下是踩坑实录. gulp 先来说说原来的架构. ...
- ios 初体验<窗口的创建>
1. 创建工程,这步很简单,百度下即可,在info.plist 里面 去掉 Main 的 ,便于新手练习ios,创建ios工程后,在AppDelegate.m,里面的方法application 加上几 ...
- window.onerror 应用实例
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp75 window.onerror = function(sMessa ...
- java-多个数的和
目的:实现多个整数相加. 思路:1.首先要确定用户所需整数的个数n,此部分由用户在键盘上输入. 2.创建一个长度为n的数组. 3.用户从键盘上输入n个整数并判断是否输入正确,正确则存入数组,否则重新输 ...
- python __name__ 变量的含义
python __name__ 变量的含义 if __name__ == '__main__': tf.app.run() 当python读入程序时,会初始化一些系统变量.如果当前程序是主程序,__n ...