Codeforces Beta Round #57 (Div. 2) E. Enemy is weak
求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(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的更多相关文章
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
- 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 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- 关于php的问题
$polling_items = db_fetch_assoc("SELECT * FROM poller_item WHERE rrd_next_step<=0 ORDER by h ...
- vue跨域解决及打包
打包之前需要修改如下配置文件: 配置文件一:build>>>utils.js (修改publicPath:"../../" , 这样写是处理打包后找不到静态文件( ...
- find、filter、map的区别
1.find 查询数组中符合条件的第一个元素,如果没有符合条件的元素则返回空数组 ,,,,,,] ) var men=[ {name:',sex:'女'}, {name:',sex:'nan'}, { ...
- Chrome浏览器安装React developer tools
1. 到 https://github.com/facebook/react-devtools 下载 react-devtools 2. 进入 react-devtools 目录 运行命令 npm ...
- unnamed not found for the web module
intellij idea tomcat 启动报错not found for the web module 使用intellij idea 创建tomcat项目的时候会出现该错误: 启动tomcat的 ...
- Moebius for SQLServer负载均衡
搞数据库的都知道:在Oracle上有RAC集群,MySQL也有对应的方案,而SQL Server上直到SQL Server 2012版本的AlwaysOn到来,微软都没有提供一个负载均衡方案,在网上看 ...
- 牛客OI赛制测试赛2 A 无序组数
链接:https://www.nowcoder.com/acm/contest/185/A来源:牛客网 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序 ...
- [题解] codevs 1486 愚蠢的矿工
http://codevs.cn/problem/1486/ 我们比较熟悉二叉树,题目中给出的是一棵多叉树,我们需要将这可二叉树改造成二叉树. 二叉树可以为这样的: 父亲结点左边储存儿子,右边储存兄弟 ...
- MySQL本地登录及数据库导入导出
注意:本地MySQL服务要开启 更新整个数据库 1.将正式服务器上的数据库做备份 登录到正式服务器,执行如下命令:(注意空格) mysqldump -uroot –p密码 数据库名 -P 接口 --d ...
- 1. 调整InnoDB系统表空间的大小
1. 调整InnoDB系统表空间的大小 介绍如何增大或减小InnoDB系统表空间的大小 . 1.1 增加InnoDB系统表空间大小 增加InnoDB系统空间最简单的方法就是,在配置文件中配置autoe ...