이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <stack>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
void solve() {
int n;
cin >> n;
int seg[n + 1][2];
for (int i = 0; i <= n; i++)
seg[i][0] = seg[i][1] = -1;
vector<int> a(n);
vector<int> b(n);
for (int &v : a) cin >> v;
for (int &v : b) cin >> v;
map<int, int> cont; stack<int> st;
for (int i = 0; i < n; i++) {
while (!st.empty() && st.top() <= a[i]) {
cont.erase(st.top()); st.pop();
} cont[a[i]] = i; st.push(a[i]);
if (cont.find(b[i]) != cont.end())
seg[i][0] = cont[b[i]];
} cont.clear(); while (!st.empty()) st.pop();
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && st.top() <= a[i]) {
cont.erase(st.top()); st.pop();
} cont[a[i]] = i; st.push(a[i]);
if (cont.find(b[i]) != cont.end())
seg[i][1] = cont[b[i]];
} vector<int> vec, lis;
for (int i = 0; i < n; i++) {
if (seg[i][1] != -1) vec.pb(seg[i][1]);
if (seg[i][0] != -1 && seg[i][0] != seg[i][1]) vec.pb(seg[i][0]);
} for (int v : vec) {
auto it = upper_bound(vec.begin(), vec.end(), v);
if (it == vec.end()) lis.pb(v);
else *it = v;
} cout << lis.size();
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# | 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... |