답안 #759928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759928 2023-06-17T05:16:29 Z The_Samurai LIS (INOI20_lis) C++17
20 / 100
4000 ms 1100 KB
#include "bits/stdc++.h"

using namespace std;

struct SegTree {
    int len, neutral_element = 0;
    vector<int> tree;

    void init(int n) {
        len = 1;
        while (len < n) len *= 2;
        tree.assign(2 * len, 0);
    }

    SegTree(int n) {
        init(n);
    }

    SegTree() {}

    inline int type(int a, int b) {
        return max(a, b);
    }

    void set(int i, int v) {
        i += len;
        tree[i] = type(tree[i], v);
        while (i > 1) {
            i >>= 1;
            tree[i] = type(tree[i << 1], tree[i << 1 | 1]);
        }
    }

    int get(int l, int r, int lx, int rx, int x) {
        if (l >= rx or lx >= r) {
            return neutral_element;
        }
        if (l <= lx and rx <= r) {
            return tree[x];
        }
        int m = (lx + rx) >> 1;
        return type(get(l, r, lx, m, x << 1), get(l, r, m, rx, x << 1 | 1));
    }

    int get(int l, int r) {
        // [l, r]
        if (r < 0) {
            return neutral_element;
        }
        return get(l, r + 1, 0, len, 1);
    }
};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    vector<int> a, ans;
    SegTree sg;
    auto calc = [&]() {
        int n = a.size();
        ans.resize(n, 0);
        map<int, int> mp;
        for (int x: a) {
            mp[x];
        }
        int z = 0;
        for (auto &it: mp) {
            it.second = z++;
        }
        sg.init((int) mp.size());
        for (int i = 0; i < n; i++) {
            int x = mp[a[i]];
//            cout << x << ' ';
            ans[i] = sg.get(0, x - 1) + 1;
            sg.set(x, ans[i]);
        }
//        cout << endl;
    };
    int q;
    cin >> q;
    while (q--) {
        int i, x;
        cin >> i >> x;
        i--;
        a.insert(a.begin() + i, x);
        calc();
        cout << sg.tree[1] << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 84 ms 336 KB Output is correct
4 Correct 161 ms 348 KB Output is correct
5 Correct 95 ms 344 KB Output is correct
6 Correct 153 ms 348 KB Output is correct
7 Correct 106 ms 340 KB Output is correct
8 Correct 115 ms 476 KB Output is correct
9 Correct 119 ms 364 KB Output is correct
10 Correct 105 ms 356 KB Output is correct
11 Correct 115 ms 368 KB Output is correct
12 Correct 134 ms 356 KB Output is correct
13 Correct 172 ms 348 KB Output is correct
14 Correct 170 ms 340 KB Output is correct
15 Correct 127 ms 344 KB Output is correct
16 Correct 192 ms 348 KB Output is correct
17 Correct 190 ms 360 KB Output is correct
18 Correct 187 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 84 ms 336 KB Output is correct
4 Correct 161 ms 348 KB Output is correct
5 Correct 95 ms 344 KB Output is correct
6 Correct 153 ms 348 KB Output is correct
7 Correct 106 ms 340 KB Output is correct
8 Correct 115 ms 476 KB Output is correct
9 Correct 119 ms 364 KB Output is correct
10 Correct 105 ms 356 KB Output is correct
11 Correct 115 ms 368 KB Output is correct
12 Correct 134 ms 356 KB Output is correct
13 Correct 172 ms 348 KB Output is correct
14 Correct 170 ms 340 KB Output is correct
15 Correct 127 ms 344 KB Output is correct
16 Correct 192 ms 348 KB Output is correct
17 Correct 190 ms 360 KB Output is correct
18 Correct 187 ms 344 KB Output is correct
19 Execution timed out 4050 ms 1100 KB Time limit exceeded
20 Halted 0 ms 0 KB -