-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path1284-B.cpp
44 lines (39 loc) · 1007 Bytes
/
1284-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
/*
miscellaneous > binary search
difficulty: medium
date: 05/Jan/2020
by: @brpapa
*/
#include <algorithm>
#include <iostream>
#include <vector>
#define MAX 1000010
#define MIN -1
#define ll long long
using namespace std;
int main() {
int N; cin >> N;
vector<int> mn(N), mx(N); // mn[i] e mx[i] = valores min e max da seq i
for (int i = 0; i < N; i++) {
mn[i] = MAX;
mx[i] = MIN;
int li; cin >> li;
while (li--) {
int s; cin >> s;
if (s > mn[i]) { // já tem pelo menos 1 ascent
mn[i] = MIN;
mx[i] = MAX;
}
mn[i] = min(mn[i], s);
mx[i] = max(mx[i], s);
}
}
sort(mx.begin(), mx.end());
ll ans = (ll) N * N;
for (int i = 0; i < N; i++) {
// decrementa qte de casos onde mn[i] >= mx[j], para 0 <= j <= N (ou seja, quando {mn[i], mn[j]} não forma ascent)
ans -= upper_bound(mx.begin(), mx.end(), mn[i]) - mx.begin();
}
cout << ans << endl;
return 0;
}