求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(x),(y,z),x > y,且x出现的p_x < p_y。

x可直接枚举O(n),此时需要往后查询二元组的个数,二元组可由两个一元组生成,实际上到这里就转换成了求两次逆序对而已。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;
typedef long long ll;
#define T int t_;Read(t_);while(t_--)
#define dight(chr) (chr>='0'&&chr<='9')
#define alpha(chr) (chr>='a'&&chr<='z')
#define INF (0x3f3f3f3f)
#define maxn (1000005)
#define hashmod 100000007
#define ull unsigned long long
#define repne(x,y,i) for(i=(x);i<(y);++i)
#define repe(x,y,i) for(i=(x);i<=(y);++i)
#define repde(x,y,i) for(i=(x);i>=(y);--i)
#define repdne(x,y,i) for(i=(x);i>(y);--i)
#define ri register int
void Read(int &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
void Read(ll &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if
(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
int n,a[maxn],b[maxn];
ll c[maxn],s[maxn];
void hasharray(){
memcpy(b,a,n*sizeof(a[]));
sort(b,b+n);
for(int i = ;i < n;++i) a[i] = (int)(lower_bound(b,b+n,a[i]) - b) + ;
}
int lowbit(int x){return x & (-x);}
void update(int x,ll v){
while(x <= n){
s[x] += v;
x += lowbit(x);
}
}
ll query(int x){
ll ans = ;
while(x){
ans += s[x];
x -= lowbit(x);
}
return ans;
}
int main()
{
freopen("a.in","r",stdin);
freopen("b.out","w",stdout);
Read(n);
ri i;
repne(,n,i) Read(a[i]);
hasharray();
update(a[n-],);
repde(n-,,i) c[i] = query(a[i]-),update(a[i],);
memset(s,,sizeof(s));
update(a[n-],c[n-]);
ll ans = ;
repde(n-,,i) ans += query(a[i]-),update(a[i],c[i]);
cout << ans << endl;
return ;
}

Codeforces Beta Round #57 (Div. 2) E. Enemy is weak的更多相关文章

  1. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

  2. Codeforces Beta Round #57 (Div. 2) A,B,C,D,E

    A. Ultra-Fast Mathematician time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. VPS环境配置预备篇

    VPS买到手了,在配置环境前要做哪些操作呢?老谢说一下自己的习惯,希望对和老谢一样的菜鸟有帮助更新系统内核和rpm包#安装yum-fastestmirror插件yum -y install yum-f ...

  2. 洛谷 P1011 车站

    题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...

  3. SEO 第一章

    SEO  第一章 第一章:SEO基础知识 第二章:搜索引擎基础 第三章:关键词分析 第四章:TDK优化 第五章:网站的URL优化 第六章:网站的内链优化 第七章:代码优化 第八章:网站的内容优化 第九 ...

  4. (转)SpringMVC学习(十)——SpringMVC与前台的json数据交互

    http://blog.csdn.net/yerenyuan_pku/article/details/72514022 json数据格式在接口调用中.html页面中比较常用,json格式比较简单,解析 ...

  5. 命令终端执行python

    windows进入cmd 1.进入cmd窗口,找到存放py文件的地址(如E:\learn_mock) 2.退出python,输入exit() linux下一样

  6. JavaScript/JQuery radioButton(单选按钮)练习20190409

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. poj2065 SETI

    题目描述: 多组数据,每次给出一个模数$p$和一个表示答案的字符串, 相当于给出一个方程组:$$a_1*1^{1}+a_2*1^{2}+……+a_n*1^{n}=f_1$$ $$a_1*2^{1}+a ...

  8. nginx解决跨域(前后端分离)

    Nginx解决跨域问题 后端接口 请求地址 返回数据(json数据) http://127.0.0.1:8080//app Hello World! 前端代码 通过nginx做静态资源服务器访问端口8 ...

  9. django--基础操作

    Django基础操作 django常用命令 创建django项目 django-admin startproject mysite 创建项目完成以后,文件目录结构为: 修改settings文件内容 A ...

  10. Centos7安装tomcat(wget获取安装包)

    选择要下载的版本去tomcat库查看想要下载的版本 https://mirrors.cnnic.cn/apache/tomcat/ 下载选择tomcat8的一个版本 wget https://mirr ...