답안 #875486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875486 2023-11-19T21:49:58 Z Youssif_Elkadi Volontiranje (COCI21_volontiranje) C++17
10 / 110
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
pair<int, int> tree[N];
int arr[N];
int vis[N];
int p[N];
int n;
void build(int node = 1, int l = 1, int r = n)
{
    if (l == r)
    {
        tree[node] = {0, 0};
        return;
    }
    int mid = (l + r) / 2;
    build(node * 2, l, mid), build(node * 2 + 1, mid + 1, r);
    tree[node] = {0, 0};
}
pair<int, int> comb(pair<int, int> x, pair<int, int> y)
{
    if (x.first == y.first)
        return (x.second > y.second ? y : x);
    return (x.first < y.first ? y : x);
}
void update(int idx, int val, int node = 1, int l = 1, int r = n)
{
    if (l == r)
    {
        tree[node] = {val, idx};
        return;
    }
    int mid = (l + r) / 2;
    if (idx <= mid)
        update(idx, val, node * 2, l, mid);
    else
        update(idx, val, node * 2 + 1, mid + 1, r);
    tree[node] = comb(tree[node * 2], tree[node * 2 + 1]);
}
pair<int, int> query(int ql, int qr, int node = 1, int l = 1, int r = n)
{
    if (ql <= l && r <= qr)
        return tree[node];
    if (qr < l || r < ql)
        return {0, 0};
    int mid = (l + r) / 2;
    return comb(query(ql, qr, node * 2, l, mid), query(ql, qr, node * 2 + 1, mid + 1, r));
}
vector<int> lis()
{
    build();
    vector<int> ret;
    for (int i = n; i >= 1; i--)
    {
        if (vis[arr[i]])
            continue;
        pair<int, int> hi = query(arr[i], n);
        if (hi.first == 0)
            update(arr[i], 1), p[arr[i]] = arr[i];
        else
            update(arr[i], hi.first + 1), p[arr[i]] = hi.second;
    }
    pair<int, int> hi = query(1, n);
    if (hi.first == 0)
        return {};
    else
    {
        while (true)
        {
            ret.push_back(hi.second);
            vis[hi.second] = 1;
            if (hi.second == p[hi.second])
                break;
            hi.second = p[hi.second];
        }
        return ret;
    }
}
int main()
{
    cin >> n;
    vector<int> loc(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> arr[i], loc[arr[i]] = i;
    int mx = 0;
    vector<vector<int>> ans;
    while (true)
    {
        vector<int> hi = lis();
        if ((int)hi.size() < mx)
            break;
        mx = hi.size();
        ans.push_back(hi);
    }
    cout << ans.size() << " " << mx << "\n";
    for (auto v : ans)
    {
        for (auto s : v)
            cout << loc[s] << " ";
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Runtime error 1 ms 604 KB Execution killed with signal 11
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Runtime error 1 ms 604 KB Execution killed with signal 11
27 Halted 0 ms 0 KB -