提出 #53628964
ソースコード 拡げる
/*
I'm Once Again Asking For a Tree Problem.
*/
#include "bits/stdc++.h"
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ld long double
#define nl cout << '\n'
#define pri(n) cout<<fixed<<setprecision(n)
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
void m4_htgeb_tle_kda_ya3ny() {
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
cout.sync_with_stdio(0);
}
const int N = 2e5 + 10;
const ll infl = 1e18 + 10, MOD = 1e9 + 7, inf = 1e9 + 10;
int segTree[4 * N];
void update_tree(int node, int l, int r, int pos, int val) {
if (l > pos || r <= pos)return;
if (r - l <= 1) {
segTree[node] = max(val, segTree[node]);
return;
}
int mid = (l + r) >> 1;
if (pos < mid)
update_tree(2 * node + 1, l, mid, pos, val);
else
update_tree(2 * node + 2, mid, r, pos, val);
segTree[node] = max(segTree[2 * node + 2], segTree[2 * node + 1]);
}
/*
* query_tree:
* Given ql and qr, it will return the maximum value in the range [ql,qr)
*/
int query_tree(int node, int l, int r, int ql, int qr) {
if (l >= qr || r <= ql)return -1;
if (l >= ql && r <= qr)return segTree[node];
int mid = (l + r) >> 1;
return max(query_tree(2 * node + 1, l, mid, ql, qr), query_tree(2 * node + 2, mid, r, ql, qr));
}
void solveCase() {
int n;
cin >> n;
map<int, int> mp;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
mp[a[i]] = 1;
}
int id = 0;
for (auto &it: mp)it.second = id++;
vector<int> dp1(n), dp2(n);
for (int i = 0; i < 4 * id; ++i) segTree[i] = 0;
for (int i = 0; i < n; ++i) {
int mx = query_tree(0, 0, id, 0, mp[a[i]]);
dp1[i] = max(0, mx) + 1;
update_tree(0, 0, id, mp[a[i]], dp1[i]);
}
for (int i = 0; i < 4 * id; ++i)segTree[i] = 0;
for (int i = n - 1; i >= 0; i--) {
int mx = query_tree(0, 0, id, mp[a[i]] + 1, id);
dp2[i] = max(0, mx) + 1;
update_tree(0, 0, id, mp[a[i]], dp2[i]);
}
int lis = *max_element(dp1.begin(), dp1.end());
vector<int> ans;
for (int i = 0; i < n; i++) {
if (dp1[i] + dp2[i] - 1 == lis)ans.push_back(i);
}
cout << ans.size() << '\n';
for (int x: ans)cout << x + 1 << " ";
}
signed main() {
m4_htgeb_tle_kda_ya3ny();
int test = 1;
cin >> test;
for (int i = 1; i <= test; ++i) {
solveCase();
nl;
}
return 0;
}
提出情報
提出日時 |
|
問題 |
F - Useless for LIS |
ユーザ |
Mongy |
言語 |
C++ 20 (gcc 12.2) |
得点 |
525 |
コード長 |
2814 Byte |
結果 |
AC |
実行時間 |
497 ms |
メモリ |
19128 KiB |
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
525 / 525 |
結果 |
|
|
セット名 |
テストケース |
Sample |
00_sample_00.txt, 00_sample_01.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
00_sample_00.txt |
AC |
1 ms |
3412 KiB |
00_sample_01.txt |
AC |
1 ms |
3516 KiB |
01_random_00.txt |
AC |
60 ms |
3504 KiB |
01_random_01.txt |
AC |
45 ms |
3460 KiB |
01_random_02.txt |
AC |
46 ms |
3460 KiB |
01_random_03.txt |
AC |
62 ms |
3532 KiB |
01_random_04.txt |
AC |
72 ms |
3512 KiB |
01_random_05.txt |
AC |
497 ms |
17896 KiB |
01_random_06.txt |
AC |
474 ms |
17868 KiB |
01_random_07.txt |
AC |
459 ms |
17836 KiB |
01_random_08.txt |
AC |
452 ms |
17820 KiB |
01_random_09.txt |
AC |
451 ms |
17832 KiB |
01_random_10.txt |
AC |
52 ms |
3524 KiB |
01_random_11.txt |
AC |
34 ms |
3528 KiB |
01_random_12.txt |
AC |
36 ms |
3528 KiB |
01_random_13.txt |
AC |
44 ms |
3600 KiB |
01_random_14.txt |
AC |
53 ms |
3604 KiB |
01_random_15.txt |
AC |
304 ms |
13324 KiB |
01_random_16.txt |
AC |
301 ms |
12832 KiB |
01_random_17.txt |
AC |
307 ms |
13304 KiB |
01_random_18.txt |
AC |
184 ms |
7008 KiB |
01_random_19.txt |
AC |
101 ms |
5460 KiB |
01_random_20.txt |
AC |
52 ms |
3524 KiB |
01_random_21.txt |
AC |
33 ms |
3520 KiB |
01_random_22.txt |
AC |
38 ms |
3596 KiB |
01_random_23.txt |
AC |
33 ms |
3520 KiB |
01_random_24.txt |
AC |
26 ms |
3452 KiB |
01_random_25.txt |
AC |
37 ms |
6424 KiB |
01_random_26.txt |
AC |
37 ms |
6380 KiB |
01_random_27.txt |
AC |
38 ms |
6428 KiB |
01_random_28.txt |
AC |
38 ms |
6508 KiB |
01_random_29.txt |
AC |
25 ms |
6472 KiB |
01_random_30.txt |
AC |
212 ms |
18964 KiB |
01_random_31.txt |
AC |
201 ms |
19124 KiB |
01_random_32.txt |
AC |
191 ms |
18996 KiB |
01_random_33.txt |
AC |
196 ms |
18968 KiB |
01_random_34.txt |
AC |
202 ms |
19012 KiB |
01_random_35.txt |
AC |
198 ms |
18940 KiB |
01_random_36.txt |
AC |
177 ms |
18928 KiB |
01_random_37.txt |
AC |
209 ms |
18976 KiB |
01_random_38.txt |
AC |
213 ms |
19128 KiB |
01_random_39.txt |
AC |
180 ms |
19032 KiB |
02_hand_00.txt |
AC |
1 ms |
3516 KiB |
02_hand_01.txt |
AC |
19 ms |
6512 KiB |
02_hand_02.txt |
AC |
200 ms |
18924 KiB |
02_hand_03.txt |
AC |
195 ms |
18916 KiB |