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 ...
随机推荐
- MSF初体验 - kali linux 入侵XP系统
最近做某安全竞赛平台的比赛,真正开始接触Metasploit这一渗透神器,同时也是装逼神器(2333-.),下面记录一下初步使用Metasploit的过程.首先在百度百科摘录了一段关于Metasplo ...
- 残差网络resnet学习
Deep Residual Learning for Image Recognition 微软亚洲研究院的何凯明等人 论文地址 https://arxiv.org/pdf/1512.03385v1.p ...
- 浏览器F12进行Web程序调试
转自http://www.cnblogs.com/yougewe/p/5152700.html 引语:如今的整个Web开发行业甚至说整个软件开发行业,已经相当成熟,基本上已经很少找不到没有前人做过的东 ...
- python使用mongodb
系统环境:Windows 10 ,python3.x 1.安装mongodb mongodb下载官网:https://www.mongodb.com/download-center?jmp=nav#c ...
- Pyhton 学习笔记1
格式化 最后一个常见的问题是如何输出格式化的字符串.我们经常会输出类似'亲爱的xxx你好!你xx月的话费是xx,余额是xx'之类的字符串,而xxx的内容都是根据变量变化的,所以,需要一种简便的格式化字 ...
- SQL Server内存
背景 最近一个客户找到我说是所有的SQL Server 服务器的内存都被用光了,然后截图给我看了一台服务器的任务管理器.如图 这里要说明一下任务管理器不会完整的告诉真的内存或者CPU的使用情况,也就是 ...
- MongoDb 入门教程
MongoDb 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. 它是可扩展的高性能数据存储解决方案,经常被用于非关系型数据的存储,能存储海量的数据. 常 ...
- Git学习总结(一)
.常用Git命令清单 一.新建代码库 #在当前目录创建一个Git代码库 $ git init #新建一个目录,将其初始化为Git代码库 $ git init [project name] #下载一个项 ...
- Python 异常处理
Python 异常处理 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理: 本站Python教程会具体介绍. 断言 ...
- JAVA基础第四组(5道题)
16.[程序16] 题目:输出9*9口诀. 1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列. package com. ...