Submission #782985

#TimeUsernameProblemLanguageResultExecution timeMemory
782985RushBLIS (INOI20_lis)C++17
20 / 100
4065 ms28224 KiB
#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[N]; 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()); } } void add(vector<int> &v, int pos, int x) { vector<int> t; for (int i = 0; i < pos; i++) t.push_back(v[i]); t.push_back(x); for (int i = pos; i < v.size(); i++) t.push_back(v[i]); assert(t.size() == v.size() + 1); v = t; mx = max(mx, (int) v.size()); } void seq() { FOR(i, 0, N) assert(V[i].empty()); 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() { int cnt = 0; while (true) { assert(++cnt <= 2000); 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]); lis = max(lis, p); M[x[a[i]]] = max(M[x[a[i]]], p); } 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 (stderr)

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:29:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = pos; i < v.size(); i++) t.push_back(v[i]);
      |                           ~~^~~~~~~~~~
Main.cpp: In function 'void seq()':
Main.cpp:41:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                         if (cur > V[j].size()) cur -= V[j].size();
      |                             ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...