codeforces 1284B. New Year and Ascent Sequence(二分)
B. New Year and Ascent Sequence
题意:定义上升序列Ascent,在一组序列A中,存在1<i<j<n,使得Ai<Aj。现在给定n个序列,求n个序列两两组合的n^2个组合序列中,有多少个组合是Ascent序列。。
思路: 用两个MAX,MIN数组分别记录下每个序列的最大值和最小值,然后把最大值进行排序。每次做一遍二分,取每个数组中的最小值到所有数组中的最大值中找有多少个数比它大,这样组合的新序列便是满足Ascent性质。如果本身这个序列就已经满足Ascent的性质,那么直接把最大值设置为9999999,最小值设置为-1存进去。
AC代码:
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
vector<int> MAX;
vector<int> MIN;
int main(){
int t;
cin>>t;
for(int i = ;i<t;i++){
int Length;
cin>>Length;
long long Min = ;
long long Max = -;
int ok = ;
for(int j = ;j<Length;j++){
long long cur;
cin>>cur;
if(cur> Min && ok == ){
ok = ;
}
Min = min(Min,cur);
Max = max(Max,cur);
}
if(ok == ){
MAX.push_back(Max);
MIN.push_back(Min);
}
else{
MAX.push_back();
MIN.push_back(-);
}
}
sort(MAX.begin() ,MAX.end() );
long long ans = ;
for(int i = ;i<t;i++){
ans+=(MAX.end() -upper_bound(MAX.begin() ,MAX.end() ,MIN[i]));
//cout<<ans<<endl;
}
cout<<ans;
return ;
}
codeforces 1284B. New Year and Ascent Sequence(二分)的更多相关文章
- (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes in ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces 749D:Leaving Auction(set+二分)
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- CodeForces 689D Friends and Subsequences (RMQ+二分)
Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description Mi ...
随机推荐
- vim 配置 jedi-vim( ubuntu:15.10 )
确保 vim 支持 python3 或者 python 如果你已经安装了 vim, 可以通过vim --version, 在输出中找到 +python3 或者 +python 字样的话, 就可以跳过该 ...
- MySQL 8 服务器插件
安装插件 内置插件时服务器能够自动识别的,通常在服务器启动时加载内置插件. 在mysql.plugin表中注册的插件,这种插件不同于内置插件(内置插件不需要注册),通常在服务器启动时会加载mysql. ...
- 04_TypeScript类
1.类的定义 //ts定义类和ES6相似,不同的是属性需要修饰符并定义数据类型 class Person{ public name:string; constructor(n:string){ thi ...
- python之三目运算符的替代品?
# 不知曾几何时,你是否也觉得Python的三目运算写起来很麻烦呢?(没有过) # 比如: a, b = 3, 4 c = a if a > b else b d = a if a < b ...
- awk数组学习2
以下数据取自redis数据库中client list的结果, id= addr= fd= name= age= idle= flags=N db= sub= psub= multi=- qbuf= q ...
- 纪中集训2020.02.05【NOIP提高组】模拟B 组总结反思——【佛山市选2010】组合数计算,生成字符串 PPMM
目录 JZOJ2290. [佛山市选2010]组合数计算 比赛时 之后 JZOJ2291. [佛山市选2010]生成字符串 比赛时 之后 JZOJ2292. PPMM 比赛时 之后 JZOJ2290. ...
- IIS7配置asp程序
Windows 中IIS7.IIS7.5是默认不安装的,所以在安装完Windows Vista/windows 7/windows 2008之后如果需要安装IIS7/iis7.5的话,就要自己动手了. ...
- springMVC项目配置文件
一.springMVC项目配置文件 1.web.xml文件全局配置 <servlet> <servlet-name> dispatcher </servlet-name& ...
- H5_0009:关于HTML5中Canvas的宽、高设置问题
关于HTML5中Canvas的宽.高设置问题 Canvas元素默认宽 300px, 高 150px, 设置其宽高可以使用如下方法(不会被拉伸): 方法一: <canvas widt ...
- 【并发那些事】线程有序化神器CompletionService
前言 话说有一天,产品经理突然找到正在摸鱼的你. 产品:『我们要加一个聚合搜索功能,当用户在我们网站查询一件商品时,我们分别从 A.B.C 三个网站上查询这个信息,然后再把得到的结果返回给用户』 你: ...