# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
835408 |
2023-08-23T14:12:50 Z |
otarius |
Exam (eJOI20_exam) |
C++17 |
|
2 ms |
500 KB |
#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] = 0;
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 |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |