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 ...
随机推荐
- win7系统 无线上网卡 共享网络,设置成wifi热点
给家人买了一个新的智能手机,用的移动神州行套餐,没有开通3G,想更新一些应用软件,于是想到能不能用电脑上的无线上网卡. 在网上找到了一方法,试了一下,还真是可以. 步骤如下: 用无线上网卡拨号上网,并 ...
- PHP 弹窗 源代码 css Jquery.js
// 每个弹窗的标识 var x =0; var idzt = new Array(); var Window = function(config){ //ID不重复 idzt[x] = " ...
- Win10传递优化设置技巧
什么是“传递优化缓存” “传递优化”是微软为了加快Windows更新和Microsoft Store应用更新的下载速度,而在Windows10中引入的一种“自组织分布式本地化缓存”设计,可以在用户电脑 ...
- JoyOI1035 棋盘覆盖
原题链接 对棋盘染色,坐标和为奇数的染黑,偶数为白.这时会发现对于相同颜色的格子,是无法放置骨牌的,这样我们就将所有格子分成两类,然后根据能否放置骨牌连边,最后就是求二分图最大匹配了. 这里我是用的匈 ...
- python爬虫 urllib库基本使用
以下内容均为python3.6.*代码 学习爬虫,首先有学会使用urllib库,这个库可以方便的使我们解析网页的内容,本篇讲一下它的基本用法 解析网页 #导入urllib from urllib im ...
- Ubuntu下安装VS code
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo apt-get install ubun ...
- Delphi--最强大的开发工具(欢迎转载)
最强大的开发工具 Delphi 目录 --------------------------------------------------------------------------- 前言 De ...
- jmeter多用户并发
1.需要参数化 2.单用户需要在请求头里面传入cookie
- Git使用基础篇(zz)
Git使用基础篇 您的评价: 收藏该经验 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体 ...
- CMDB 配置管理数据库