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 ...
随机推荐
- 斯坦福发布2019全球AI报告:中国论文数量超美国,自动驾驶汽车领域获投资最多
近日,斯坦福联合MIT.哈佛.OpenAI等院校和机构发布了一份291页的<2019年度AI指数报告>. 这份长达291页的报告从AI的研究&发展.会议.技术性能.经济.教育.自动 ...
- [Python]PyCharm在创建py文件时自动添加头部注释
在Pycharm主界面找到 File ----->> Setting ----->> Editor ----->> File and Code Templates ...
- LED Candle Light Factory-LED Candle Light: Full Of Romance
LED candle lights are beautiful and can add elegance and romance to any space. These candles make th ...
- 1级搭建类111-Oracle 19c SI FS(Windows Server 2019)公开
Oracle 19c 单实例文件系统在Windows Server 2019上的安装 在线查看
- 2020牛客寒假算法基础集训营6 E.立方数(唯一分解定理 素数筛)
https://ac.nowcoder.com/acm/contest/3007/E 放下题解 #include<bits/stdc++.h> using namespace std; t ...
- ASP.NET MVC模块化开发——动态挂载外部项目
最近在开发一个MVC框架,开发过程中考虑到以后开发依托于框架的项目,为了框架的维护更新升级,代码肯定要和具体的业务工程分割开来,所以需要解决业务工程挂载在框架工程的问题,MVC与传统的ASP.NET不 ...
- ECMAScript基本语法——⑤运算符 三元运算符
?: 简化ifelse的操作
- Mac上利用VScode配置c/c++开发环境
Mac上利用VScode配置c/c++开发环境 哭辽,Typora里面最好不要插入表情,不然保存会闪退 首先你要有一个vscode 在扩展里面下载c/c++ 第一步 ⬆+com+p 打开命令模式:选择 ...
- IDAE打包WEB项目 WAR Eclipse转IDEA项目
接下来这里只说WEB项目打包,相信大多数都是用的WEB项目吧,关于打包WAR,真的很头痛,网上说的试了好好次都不行. 后来懂了之后,真的很简单好么,分享给大家 不要多走弯路了. 注意: 如果你 ...
- Max Sum Plus Plus HDU - 1024 基础dp 二维变一维的过程,有点难想
/* dp[i][j]=max(dp[i][j-1]+a[j],max(dp[i-1][k])+a[j]) (0<k<j) dp[i][j-1]+a[j]表示的是前j-1分成i组,第j个必 ...