-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathb.cpp
48 lines (46 loc) · 1.18 KB
/
b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N, ret = 0, nascent = 0;
cin >> N;
vector<int> s[N];
ll minV[N], maxV[N];
bool hasAscent[N];
for(int i = 0; i < N; i++){
ll a, small = INT_MAX, big = INT_MIN;
bool ascent = false;
cin >> a;
for(int j = 0; j < a; j++){
ll x;
cin >> x;
s[i].push_back(x);
small = min(small, x);
big = max(big, x);
if(x > small){
ascent = true;
}
}
if(ascent){
nascent++;
maxV[i] = INT_MIN;
}else{
minV[i] = small;
maxV[i] = big;
}
hasAscent[i] = ascent;
}
sort(maxV, maxV + N);
for(int i = 0; i < N; i++){
if(hasAscent[i]){
ret += N;
}else{
//cout << "i: " << i << "ret " << ret << endl;
ret += (maxV + N) - upper_bound(maxV, maxV + N, minV[i]) + nascent;
//cout << "i: " << i << "ret " << ret << endl;
}
}
//cout << *upper_bound(maxV, maxV + N, minV[1]) << endl;
cout << ret << endl;
return 0;
}