codeforces 1284B. New Year and Ascent Sequence(二分)

B. New Year and Ascent Sequence

The meaning of problems: the definition of the Ascent rising sequence, a set of sequence A, there is 1 <i <j <n, such that Ai <Aj. Now given a sequence of n, n find combinations of two sequences of n ^ 2 sequence combinations, the number of combinations is Ascent sequence. .

Thinking: two MAX, MIN array are recorded the maximum and minimum of each sequence, the maximum value and sorting. Again every time two minutes, the minimum value to a maximum value of each array in the array to find the number of all the number is larger than it, a new sequence of such combinations is satisfied Ascent properties. If this sequence has satisfied itself Ascent nature, then the maximum value is set directly 9999999, deposit into the minimum value is set to -1.

AC Code:

 1 #include<iostream>
 2 #include<vector>
 3 #include<cstring>
 4 #include<map>
 5 #include<algorithm>
 6 using namespace std;
 7 vector<int> MAX;
 8 vector<int> MIN;
 9 int main(){
10     int t;
11     cin>>t;
12     for(int i = 0;i<t;i++){
13         int Length;
14         cin>>Length;
15         long long Min = 999999999;
16         long long Max = -1;
17         int ok = 0;
18         for(int j = 0;j<Length;j++){
19             long long cur;
20             cin>>cur;
21             if(cur> Min && ok == 0){
22                 ok = 1;
23             }
24             Min = min(Min,cur);
25             Max = max(Max,cur);
26         }
27         if(ok == 0){
28             MAX.push_back(Max);
29             MIN.push_back(Min);  
30         }
31         else{
32             MAX.push_back(9999999);
33             MIN.push_back(-1);  
34         }
35     }
36     sort(MAX.begin() ,MAX.end() );
37     long long ans = 0;
38     for(int i = 0;i<t;i++){
39         ans+=(MAX.end() -upper_bound(MAX.begin() ,MAX.end() ,MIN[i]));
40         //cout<<ans<<endl;
41     }
42     cout<<ans;
43     return 0;
44 }

Guess you like

Origin www.cnblogs.com/AaronChang/p/12185453.html