hdu 2688
这题,因为要统计之前有多少个数比当前的数小,所以我用的树状数组
基本代码就是这样,还是比较好想的,只不过我没想出来罢了
#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的更多相关文章
- [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ
前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...
- HDU 2689Sort it 树状数组 逆序对
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- oracle 直接复制表内容到新表
不知道为什么,刚建的oracle数据库删除数据很慢,表里面有120多万数据,非常地慢 于是采用的复制的方法,命令如下: create table students_backup as select * ...
- 28335XINTF的简单使用
28335 XINTF基本特点 一共有三个外部存储区域:区域0(Zone 0),区域6(Zone 6)和区域7(Zone 7).对应的 访问地址为:Zone 0:0x0000_4000-0x0000_ ...
- 肤色检测一例-使用rgb颜色模型
代码: /* 输入:rgb图像 输出:与输入图像尺寸相同的灰度图,若rgb图中某像素检测为肤色,则灰度图中对应像素为255,否则为0 */ void SkinRGB( Mat &rgb,Mat ...
- RabbitMQ消息队列(一):详细介绍
1. 历史 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息通讯的世界里有 ...
- wmi uuid
[转]https://www.cnblogs.com/-sylar/p/8376621.html 1. 开始-运行-输入:wbemtest 回车2. 单击"连接", 输入:root ...
- MySQL自带的4个数据库
安装完 MySQL 后会发现有四个自带的数据库: information_schema -- 该数据库保存了 MySQL 服务器所有数据库的信息.比如数据库的名称.数据库中的表名称.访问权限.数据库中 ...
- Writing modular applications with laravel-modules
01-07-2016 Let me start by saying Laravel is an amazing framework. However when it comes to writing ...
- Oracle12c的卸载
之前电脑装了Oracle12c 现在希望删除重新安装: 参照教程: http://jingyan.baidu.com/article/642c9d34e1cbdd644a46f7de.html E:\ ...
- 从hash算法到java hashcode()
转载 https://blog.csdn.net/Walk_er/article/details/74976146 hash算法是一个摘要算法(yy:描述性算法:可以给一个物体确切的描述,但是不能通过 ...
- mybatis学习 十二 多表查询
Mybatis 实现多表查询方式: (1)业务装配.对两个表编写单表查询语句,在业务(Service)把查询的两个结果进行关联. (2)使用Auto Mapping特性,在实现两表联合查询时通过别名完 ...