hdu 2688
来源:互联网 发布:java集合框架总结 编辑:程序博客网 时间:2024/05/17 22:20
OJ
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <set>#include <string>#include <cstring>#include <list>#include <queue>#include <stack>#include <cmath>using namespace std;#define PF(x) (scanf("%d",&x))#define PT(x,y) (scanf("%d%d",&x,&y))#define PR(x) (printf("%d\n",x))#define PRT(x,y)(printf("%d %d\n",x,y))#define M 3000005#define N 10005int n;int a[M];typedef __int64 LL;LL ar[N];int minx(int a,int b){return a>b?b:a;}int lowbit(int x){return x&(-x);}void add(int x,LL c){for(;x<N;x+=lowbit(x)){ar[x] += c;}}LL sum(int x){LL s = 0;for(;x;x-=lowbit(x))s += ar[x];return s;}void init(){while(scanf("%d",&n)!=EOF){LL ans = 0;memset(ar,0,sizeof(ar));for(int i=0;i<n;i++){int x;PF(x);a[i] = x;ans += sum(x-1);add(x,1LL);}int q;PF(q); while(q--) { char str[10]; scanf("%s", str); if(str[0] == 'Q') { printf("%I64d\n", ans); }else { int s, e; scanf("%d %d", &s, &e); if(s > e) { int tmp = s; s = e; e = tmp; }int i; if(s != e) { int v = a[s]; int lt = 0, bt = 0; for(i = s; i < e; i++) { a[i] = a[i+1]; if(v < a[i+1]) { lt ++; } if(v > a[i+1]) { bt ++; } } a[e] = v; ans = ans - lt + bt; } }}}return ;}int main(){init();return 0;}
- HDU 2688
- hdu 2688
- hdu 2688
- hdu 2688
- HDU 2688
- HDU 2688
- HDU-2688 线段树
- hdu 2688 Rotate
- hdu 2688 Rotate
- hdu 2688 Rotate
- HDU - 2688 Rotate
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HubbleDotNet开源全文搜索数据库项目--技术详解
- Flash开发iOS应用全攻略(五)——如何上传应用到iTunes Connect
- mvc学习总结
- 对STM32系统时钟和分频的一点理解
- 怎样在Android中解析doc、docx、xls、xlsx格式文件?
- hdu 2688
- NSAssert()的用法
- java日期转字符串 字符串转日期 日期转日历 日历转日期
- Android开发中ConnectivityManager应用
- Hbase shell 常用命令
- sfo查询条件,具体到查询字段
- EditText计数的实现
- java在oracle数据库中如何插入读取CLOB值
- 取出字符串strName前4个汉字