Submission #835419

#TimeUsernameProblemLanguageResultExecution timeMemory
835419otariusExam (eJOI20_exam)C++17
100 / 100
70 ms8836 KiB
#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(lis.begin(), lis.end(), v); if (it == lis.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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...