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> ...
随机推荐
- Mac上面不能安装Homebrew
这个stackoverflow的答案解决了我的问题: http://stackoverflow.com/questions/18039029/mac-can-t-install-homebrew 问题 ...
- liunx中安装软件的几种方式
服务器安装包一般有四种方式 1.源代码包安装 自由度高 需要预编译,安装速度慢 2.rpm包手动安装 安装的缺点是文件的关联性太大 3. 二进制tar.gz格式 直接解压即可 如tomca ...
- Model 模型
Model 模型模型是你的数据的唯一的.权威的信息源.它包含你所存储的数据的必要字段和行为.通常,每个模型对应数据库中唯一的一张表. 每个模型都是dhango.db.models.Model 的一个P ...
- Open Cascade:如何从AIS_Shape导出TopoDS_Shape?
Open Cascade:如何从AIS_Shape导出TopoDS_Shape? 实现代码如下: if( !myAISContext->HasOpenedContext()) { wxMessa ...
- centos nginx uwsgi django
doc link uwsgi link video link
- assembly|reads to contig|contig to scaffold|coverage|depth| tandem repeats
(组装方面):SOAPdenovo ,因为采用de Bruijn graph algorithm算法和stepwise strategy ,所以排错能力高,所以我们获得高质量数据. de Bruijn ...
- Maven实战读书笔记(七):Maven常用功能
7.1.资源排除 <resources> <!-- 启动过滤,包含的文件会被过滤掉 --> <resource> <directory>src/main ...
- avalon转成Vue
需求: 旧项目中有部分页面是用avalon写的,avalon存在页面刷新,会出现重复行的问题,数组渲染出现重复行bug, 需要转成vue 总结 记录了一下大概需要改的地方 1. avalon中的ms- ...
- 区间DP入门
所为区间DP,主要是把一个大区间拆分成几个小区间,先求小区间的最优值,然后合并起来求大区间的最优值. 区间DP最关键的就是满足最优子结构以及无后效性!! 例如像是石子合并和括号匹配这两类比较经典的模型 ...
- 如何用纯 CSS 创作炫酷的同心矩形旋转动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/bMvbRp 可交互视频教 ...