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(二分)的更多相关文章

  1. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  2. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  3. 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 ...

  4. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  6. Codeforces 749D:Leaving Auction(set+二分)

    http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...

  7. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  9. CodeForces 689D Friends and Subsequences (RMQ+二分)

    Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description Mi ...

随机推荐

  1. sbt package报错:a bytes-like object is required, not 'str'

    Traceback (most recent call last): File , in <module> s.sendall(content) TypeError: a bytes-li ...

  2. QFile文件读写

    参考代码 .h文件 #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> #include <QFile> #inc ...

  3. 初识linux&常用命令&目录文件的浏览和管理

    Linux系统的主要用途:主要用于服器务器,特别是网络服务 Linux命令格式 命令   [选项]  [ 参数] 命令:告诉操作系统做什么,执行什么 选项:说明命令的运行方式(可以改变命令的功能).选 ...

  4. matlab bitset的理解

    在阅读别人的matlab程序中,发现了这个bitset函数.于是查阅资料搞明白了大概意思,意思如下: B= bitset(A,pos,V) 将A以二进制来表示,并将第pos个位置, 设置为 V 的值, ...

  5. CF468A | 24 Game 找规律+打表

    (翻译版本来自 Luogu by lonelysir ) 题目描述 小X一直很喜欢一个纸牌游戏:"24点",但最近他发现这个游戏太简单了,所以他发明了一个新游戏. 你有一个整数序列 ...

  6. springboot的yml配置文件里有多个参数的调用方式

    本篇教程适用于配置文件一级下有多个二级或三级时,如何在service层不用通过多个@Value就能获取配置文件的参数 例如yml配置是这样的: 如果service层要引用这些参数,用多个@Value( ...

  7. 305. 岛屿数量 II

    题目: 假设你设计一个游戏,用一个 m 行 n 列的 2D 网格来存储你的游戏地图. 起始的时候,每个格子的地形都被默认标记为「水」.我们可以通过使用 addLand 进行操作,将位置 (row, c ...

  8. mysql之数据初始化update操作

    1.单表的:update user set name = (select name from user where id in (select id from user where name='小苏' ...

  9. laravel中redis数据库的简单使用

    1.简介 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s . 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Set ...

  10. react-native简单使用

    基本组件的使用介绍 View: Text: TextInput: Image: Button: ActivityIndicator: ScrollView:这是一个列表滚动的组件 ListView:也 ...