Submission #782992

# Submission time Handle Problem Language Result Execution time Memory
782992 2023-07-14T13:48:18 Z RushB LIS (INOI20_lis) C++17
20 / 100
4000 ms 6872 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
const int64_t INF = 1ll << 60;
const int N = 1e6 + 6;
const int SQ = 1000;
const int SQQ = 2000 + 5;

int n, x[N], p[N], a[N], S, q, ans[N], mx;
vector<int> V[SQQ];
pair<int, int> M[SQQ];

void rebuild() {
        vector<int> x;
        for (int i = 0; V[i].size(); i++) {
                for (auto u: V[i]) x.push_back(u);
                V[i].clear();
        }
        mx = 0;
        FOR(i, 0, x.size()) {
                V[i / SQ].push_back(x[i]);
                mx = max(mx, (int) V[i / SQ].size());
        }
}
inline void add(vector<int> &v, int pos, int x) {
        if (pos == v.size()) {
                v.push_back(x);
                return;
        }
        v.insert(v.begin() + pos, x);
        mx = max(mx, (int) v.size());
}

void seq() {
        FOR(i, 0, q) {
                if (mx >= SQ) rebuild();
                int cur = p[i] - 1;
                for (int j = 0; j <= i; j++) {
                        if (cur > V[j].size()) cur -= V[j].size();
                        else {
                                add(V[j], cur, i);
                                cur = 0;
                                break;
                        }
                }
        }
        int ptr = 0;
        for (int i = 0; V[i].size(); i++) for (auto u: V[i]) a[ptr++] = u;
}

void solve() {
        while (true) {
                pair<int, int> lis = {0, INF};
                fill(M, M + SQQ, lis);
                FOR(i, 0, q) {
                        pair<int, int> p = {0, INF};
                        FOR(j, 0, x[a[i]]) p = max(p, M[j]);
                        p.first++;
                        p.second = min(p.second, -a[i]);
                        M[x[a[i]]] = max(M[x[a[i]]], p);
                }
                lis = *max_element(M, M + SQQ);
                for (int i = q - 1; i >= -lis.second; i--) ans[i] = lis.first;
                if (lis.second == 0) return;
                vector<int> v;
                FOR(i, 0, q) if (a[i] < -lis.second) v.push_back(a[i]);
                q = v.size();
                copy(v.begin(), v.end(), a);
        }
}

signed main() {
        ios::sync_with_stdio(0), cin.tie(0);
        cin >> q;
        int tq = q;
        vector<int> X;
        FOR(i, 0, q) {
                cin >> p[i] >> x[i];
                X.push_back(x[i]);
        }
        sort(X.begin(), X.end());
        X.resize(unique(X.begin(), X.end()) - X.begin());
        FOR(i, 0, q) {
                x[i] = lower_bound(X.begin(), X.end(), x[i]) - X.begin() + 1;
        }
        assert(X.size() <= SQQ);
        seq();
        solve();
        FOR(i, 0, tq) cout << ans[i] << '\n';
}
//12:54:46

Compilation message

Main.cpp: In function 'void rebuild()':
Main.cpp:3:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
      |                                          ^
Main.cpp:20:9: note: in expansion of macro 'FOR'
   20 |         FOR(i, 0, x.size()) {
      |         ^~~
Main.cpp: In function 'void add(std::vector<int>&, int, int)':
Main.cpp:26:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (pos == v.size()) {
      |             ~~~~^~~~~~~~~~~
Main.cpp: In function 'void seq()':
Main.cpp:39:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                         if (cur > V[j].size()) cur -= V[j].size();
      |                             ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 13 ms 484 KB Output is correct
6 Correct 9 ms 452 KB Output is correct
7 Correct 10 ms 468 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 11 ms 468 KB Output is correct
10 Correct 9 ms 452 KB Output is correct
11 Correct 11 ms 468 KB Output is correct
12 Correct 10 ms 468 KB Output is correct
13 Correct 12 ms 472 KB Output is correct
14 Correct 13 ms 484 KB Output is correct
15 Correct 9 ms 468 KB Output is correct
16 Correct 12 ms 480 KB Output is correct
17 Correct 14 ms 448 KB Output is correct
18 Correct 13 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 13 ms 484 KB Output is correct
6 Correct 9 ms 452 KB Output is correct
7 Correct 10 ms 468 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 11 ms 468 KB Output is correct
10 Correct 9 ms 452 KB Output is correct
11 Correct 11 ms 468 KB Output is correct
12 Correct 10 ms 468 KB Output is correct
13 Correct 12 ms 472 KB Output is correct
14 Correct 13 ms 484 KB Output is correct
15 Correct 9 ms 468 KB Output is correct
16 Correct 12 ms 480 KB Output is correct
17 Correct 14 ms 448 KB Output is correct
18 Correct 13 ms 468 KB Output is correct
19 Correct 36 ms 5892 KB Output is correct
20 Correct 40 ms 6872 KB Output is correct
21 Execution timed out 4046 ms 3972 KB Time limit exceeded
22 Halted 0 ms 0 KB -