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> ...
随机推荐
- 读取Chrome书签文件
使用C#读取Chrome浏览器的本地书签文件,当前文件在C盘下用户文件夹\AppData\Local\Google\Chrome\User Data\Default\下的Bookmarks 打开这个文 ...
- iOS猜拳游戏源码
利用核心动画和Quartz2D做的一个小游戏.逻辑十分简单. 源码下载:http://code.662p.com/<ignore_js_op> 详细说明:http://ios.662p.c ...
- PYTHON PIP和kivy安装教程
我们安装pip.我们同样需要在Python的官网上去下载 下载地址:https://pypi.python.org/pypi/pip 下载完成之后,解压到一个文件夹,用CMD控制台进入解压目录,输入: ...
- Hessian矩阵与牛顿法
Hessian矩阵与牛顿法 牛顿法 主要有两方面的应用: 1. 求方程的根: 2. 求解最优化方法: 一. 为什么要用牛顿法求方程的根? 问题很多,牛顿法 是什么?目前还没有讲清楚,没关系,先直观理解 ...
- 【Conclusion】MySQL的安装和使用
MySQL使用 因为数据库实验用到了MySQL,这里对现在已经涉及到的MySQL部分操作做一个简单的小结. 1.安装MySQL 上MySQL的官网下载对应自己OS平台的MySQL安装文件,有在线安装和 ...
- example - 在这里插入一句话的简介
总览 (SYNOPSIS) example [options] arguments 描述 (DESCRIPTION) 在这里插入描述 man9 应当是 “内核文档” 但是由于内核文档一般不以 man ...
- python基础一 day9 函数升阶(1)
函数 可读性强 复用性强def 函数名(): 函数体 return 返回值所有的函数 只定义不调用就一定不执行 先定义后调用 函数名() #不接收返回值返回值 = 函数名() #接收返回值 返回值 没 ...
- Android项目源码分享
http://blog.csdn.net/gao_chun/article/details/47263063 Android项目源码分享 给大家分享几个Android开发项目源码,大部分功能相信可以在 ...
- executeFind(XXX) is undefined for the type hibernateTemplate(大概是这个错误吧)
两句话,jar包版本不一样,类中包含的方法可能有改变. 出错时用的是spring5.x版本,但是没有找到我的api.(不记得放在那里了),所以换了spring的版本(换成了spring3.x).问题解 ...
- python调用aapt工具直接获取包名和tagertSdkversion
背景: 每次海外游戏上架都需要符合google的上架规则,其中适配方面tagetSdkversion有硬性要求,比如需要适配安卓q就需要tagetSdkversion达到28,水平太渣的我每次调用aa ...