这题,因为要统计之前有多少个数比当前的数小,所以我用的树状数组

基本代码就是这样,还是比较好想的,只不过我没想出来罢了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int n,m;
const int maxn = ;
int c[]; //纪录每个值之前有多少个小于她的数
int ans[];
int lowbit(int k);
void add(int pos);
int sum(int pos);
int main()
{
int i,j,k;
while(scanf("%d",&n) != EOF)
{
long long val=; memset(c, , sizeof(c));
memset(ans, , sizeof(ans));
for(i=;i<=n;++i)
{
scanf("%d",ans+i);
add(ans[i]);
val += sum(ans[i]-);
}
scanf("%d",&m);
for(i=;i<m;++i)
{
char c;
getchar();
scanf("%c",&c);
if(c == 'Q')
printf("%lld\n",val);
else
{
int x,y;
scanf("%d%d",&x,&y);
// x++,y++;
int temp = ans[x];
for(j=x;j<y;++j)
{
ans[j]=ans[j+];
if(ans[j]>temp) val --;
if(ans[j]<temp) val ++;
}
ans[y] = temp;
}
}
}
}
void add(int pos)
{
while(pos<maxn)
{
c[pos] ++;
pos += lowbit(pos);
}
}
int sum(int pos)
{
int su=;
while(pos>)
{
su+=c[pos];
pos-=lowbit(pos);
}
return su;
}
int lowbit(int k)
{
return k&(-k);
}

hdu 2688的更多相关文章

  1. [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ

    前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...

  2. HDU 2689Sort it 树状数组 逆序对

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  3. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. oracle sqlplus操作

    步骤: su - oracle 切换到oracle用户 sqlplus /nolog 进入sqlplus命令行 conn cps/cps 连接到cps用户的数据库,cps/cps表示:用户/密码 执行 ...

  2. QT学习之路(1):彩票绝对不中模拟器

    //============================================//绝对不中,彩票开奖模拟器#include "mainwindow.h"#includ ...

  3. Ubuntu 配置双网卡的问题

    一台双网卡电脑拥有两个网关是不可能的,因为默认网关(default gateway)只能是一个.给Ubuntu Linux服务器安装两块网卡,分别设置不同的ip和网关(内网和外网),外网的通过外网网卡 ...

  4. Python之路(第十八篇)shutil 模块、zipfile模块、configparser模块

    一.shutil 模块 1.shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中,需要打开文件 import shutil shutil.co ...

  5. SpringMVC 学习 十 SSM环境搭建(三)springMVC文件配置

    SpringMVC文件配置的详细过程,可以查看springMVC环境搭建的注解配置篇<springMVC学习三 注解开发环境搭建> <?xml version="1.0&q ...

  6. 三连击(NOIP1998)

    题目链接:三连击 典型的打表题,但cgg今天不是教你怎么打表的,而是教你正解. 这题方法多样,比如递归求解也行,反正数据也不大. 在这里我提供另一种思路,我们枚举第一个数,即最小的一个数,然后分解它以 ...

  7. 18 包 ,logging模块使用

    包: 1 什么是包: 包就是一个包含有__init__.py文件的文件夹 宝本质就是一种模块,即包就是用包导入使用的,包内部包含的文件也都是用来被导入使用 2 为什么要用包 包就是文件夹,那文件加就是 ...

  8. kbmmw 5.06.20 发布

    经过1个多月的测试,终于发布正式版. 5.06.20 July 11 2018           Important notes (changes that may break existing c ...

  9. kbmmw 中JSON 操作入门

    现在各种系统中JSON 用的越来越多.delphi 也自身支持JSON 处理. 今天简要说一下kbmmw 内部如何使用和操作JSON. kbmmw 中json的操作是以TkbmMWJSONStream ...

  10. oracle 大量连接导致数据库不能登录

    系统遇到过几次这种问题,一个系统申请的session数过大,导致数据库进程数满,无法连接的问题. pl sql develope 报的错误是:ORA-12170:TNS:链接超时 oracle用户登录 ...