#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0);
template <typename T>
struct PrefixSum {
int n;
vector<T> sum;
PrefixSum() {}
PrefixSum(vector<int> vec) : n((int)vec.size()) {
sum.resize(n+1);
for (int i = 1; i <= n; i++) {
sum[i] = sum[i-1] + vec[i-1];
}
};
T getSum(int l, int r) {
return sum[r+1] - sum[l];
}
};
struct Solver {
int& n;
vector<int>& a;
void solve() {
vector<int> l(n);
vector<int> lis;
for (int i = 0; i < n; i++) {
auto it = lower_bound(lis.begin(), lis.end(), a[i]);
l[i] = it - lis.begin();
if (it == lis.end()) {
lis.push_back(a[i]);
} else {
*it = a[i];
}
}
vector<vector<int>> indiciesOfLength((int)lis.size());
for (int i = 0; i < n; i++) {
indiciesOfLength[l[i]].push_back(i);
}
vector<int> lst(n, -1);
for (int len = (int)lis.size()-1; len > 0; len--) {
int cur = (int)indiciesOfLength[len-1].size() - 1;
reverse(indiciesOfLength[len].begin(), indiciesOfLength[len].end());
for (auto i : indiciesOfLength[len]) {
while (cur >= 0 and indiciesOfLength[len-1][cur] > i) {
cur--;
}
if (cur < 0) break;
lst[i] = indiciesOfLength[len-1][cur];
cur--;
}
}
// for (int i = 0; i < n; i++) {
// cerr << i << ' ' << a[i] << ' ' << l[i] << ' ' << lst[i] << '\n';
// }
vector<vector<int>> ans;
for (auto ind : indiciesOfLength[(int)lis.size()-1]) {
vector<int> vec{ind};
while (lst[ind] != -1) {
ind = lst[ind];
vec.push_back(ind);
}
if (vec.size() != lis.size()) {
continue;
}
reverse(vec.begin(), vec.end());
ans.push_back(vec);
}
cout << (int)ans.size() << ' ' << (int)lis.size() << '\n';
for (auto vec : ans) {
for (auto x : vec) {
cout << x+1 << ' ';
}
cout << '\n';
}
}
};
signed main() {
Foxyy
int T = 1;
// cin >> T;
while(T--) {
int n;
cin >> n;
vector<int> a(n);
for (auto& x : a) {
cin >> x;
}
Solver solver{n, a};
solver.solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 15] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 15] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=number of subsequences] equals to 0, violates the range [1, 15] |
14 |
Halted |
0 ms |
0 KB |
- |