-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1284B.cpp
More file actions
executable file
·42 lines (37 loc) · 829 Bytes
/
1284B.cpp
File metadata and controls
executable file
·42 lines (37 loc) · 829 Bytes
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
// Problem Code: 1284B
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool is_ascent(vector<int>& s) {
for (int i = 1; i < s.size(); i++)
if (s[i - 1] < s[i])
return true;
return false;
}
long long ascent_sequences(int n, vector< vector<int> >& s) {
long long seq = (long long) n * n;
vector<int> f, l;
for (int i = 0; i < n; i++)
if (!is_ascent(s[i])) {
f.push_back(s[i].front());
l.push_back(s[i].back());
}
sort(f.begin(), f.end());
for (int last: l)
seq -= distance(f.begin(), upper_bound(f.begin(), f.end(), last));
return seq;
}
int main() {
int n, l;
cin >> n;
vector< vector<int> > s(n);
for (int i = 0; i < n; i++) {
cin >> l;
s[i] = vector<int>(l);
for (int j = 0; j < l; j++)
cin >> s[i][j];
}
cout << ascent_sequences(n, s);
return 0;
}