This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
void threesolve(int n) {
vector<array<int, 3>> v(n);
for(int i = 0; i < 3; i++) {
vector<int> vals;
vector<int> sorted;
for(int a = 0; a < n; a++) {
int x;
cin >> x;
vals.pb(x);
sorted.pb(x);
}
sort(all(sorted));
for(auto& x: vals) x = lb(all(sorted), x) - sorted.begin();
for(int a = 0; a < n; a++) v[a][i] = vals[a];
}
sort(all(v));
vector<set<pii>> dp(n+1);
int ret = 0;
for(auto out: v) {
pii key = {out[1], out[2]};
int lhs = 0;
int rhs = ret;
while(lhs < rhs) {
int mid = (lhs+rhs+1)/2;
auto it = dp[mid].lb(key);
if(it == dp[mid].begin()) {
rhs = mid-1;
continue;
}
it--;
if(key.s > it->s) lhs = mid;
else rhs = mid - 1;
}
ret = max(ret, lhs+1);
lhs++;
while(true) {
auto it = dp[lhs].lb(key);
if(it == dp[lhs].end()) break;
if(it->s <= key.s) break;
dp[lhs].erase(it);
}
dp[lhs].insert(key);
}
cout << ret << "\n";
}
void twosolve(int n) {
vector<array<int, 2>> v(n);
for(int i = 0; i < 2; i++) {
vector<int> vals;
vector<int> sorted;
for(int a = 0; a < n; a++) {
int x;
cin >> x;
vals.pb(x);
sorted.pb(x);
}
sort(all(sorted));
for(auto& x: vals) x = lb(all(sorted), x) - sorted.begin();
for(int a = 0; a < n; a++) v[a][i] = vals[a];
}
sort(all(v));
vector<int> dp(n+1);
int ret = 0;
for(int i = 0; i < n; i++) {
int lhs = 0;
int rhs = ret;
while(lhs < rhs) {
int mid = (lhs+rhs+1)/2;
if(v[i][1] > v[dp[mid]][1]) lhs = mid;
else rhs = mid-1;
}
ret = max(ret, lhs+1);
dp[++lhs] = i;
}
cout << ret << "\n";
}
void solve() {
int r, c;
cin >> r >> c;
if(r == 2) twosolve(c);
else threesolve(c);
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |