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

    function formateDate(fmt, date) { let _this = new Date(date) let o = { "M+": _this.getMont ...

  2. H5_0027:Layer使用

    1,提示     document.getElementById("cloWd").onclick = function(){       layer.confirm('您确定要关 ...

  3. java 快速生成树的方式

    public class XzqhDto { @ApiModelProperty("另加数据") private String label; @ApiModelProperty(& ...

  4. c++多线程编程——初探

    c++多线程并发可以帮助我们挖掘CPU的性能,在我们的思想中,似乎程序都是顺序执行的.这样的结论是建立在:程序是单线程程序.(比如我们平时写的hello world程序). 但是如果程序是多线程的.那 ...

  5. Java开学测试-学生成绩管理系统

    题目: 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishiscore,networkscore ...

  6. Python标准库之re模块

    re模块用于正则表达式. 正则表达式在线测试:http://c.runoob.com/front-end/854 正则表达式元字符可以参考:https://www.w3cschool.cn/zheng ...

  7. 自定义Redux

    实现mini版redux 1. 理解redux模块 1). redux模块整体是一个对象模块 2). 内部包含几个函数 createStore(reducers) // reducers: funct ...

  8. bookdown学习笔记

    主要参考大佬谢益辉的bookdown学习笔记 https://bookdown.org/yihui/bookdown/pandoc.html 灰常之详细 然后clone了他写好的小demo,准备自己试 ...

  9. vjudge A^B Mod C 然后,10.6最。。。的 快速幂!!!

    链接:https://vjudge.net/contest/331993#problem/D 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. Inpu ...

  10. django Warning: (3135, "'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes

    django连接数据库配置设置如下 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'test2', ...