# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730471 | josanneo22 | Exam (eJOI20_exam) | C++17 | 38 ms | 6860 KiB |
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 <bits/stdc++.h>
using namespace std;
inline int rd(){
int x=0,w=1;
char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1) +(x<<3) +ch-'0';
return x*w;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int N=rd();
vector<int> A(N); for (auto& a : A)a=rd();
vector<int> B(N); for (auto& b : B)b=rd();
vector<array<int, 2>> match(N, array<int, 2>{-1, -1});
for (int z = 0; z < 2; z++) {
unordered_map<int, int> in_stack;
vector<int> stk; stk.reserve(N);
for (int j = 0; j < N; j++) {
int i = z ? N-1-j : j;
while (!stk.empty() && stk.back() <= A[i]) {
in_stack.erase(stk.back());
stk.pop_back();
}
stk.push_back(A[i]);
in_stack[A[i]] = i;
if (in_stack.count(B[i])) {
match[i][z] = in_stack[B[i]];
}
}
}
vector<int> V; V.reserve(2*N);
for (int i = 0; i < N; i++) {
if (match[i][1] != -1) {
V.push_back(match[i][1]);
}
if (match[i][0] != -1 && match[i][0] != match[i][1]) {
V.push_back(match[i][0]);
}
}
vector<int> best; best.reserve(V.size());
for (int v : V) {
int mi = -1;
int ma = int(best.size());
while (ma - mi > 1) {
int md = (mi + ma) / 2;
if (v >= best[md]) mi = md;
else ma = md;
}
if (ma == int(best.size())) best.push_back(v);
else best[ma] = v;
}
printf("%d\n",best.size());
return 0;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |