#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
vector<vector<int> > v(n, vector<int>(2, -1));
for (int it = 0; it < 2; it++)
{
map<int, int> m;
vector<pair<int, int>> stk; // {hodnota, index}
for (int i = 0; i < n; i++)
{
while (!stk.empty() && a[i] > stk.back().first)
m[stk.back().first] = -1, stk.pop_back();
stk.push_back({a[i], i}); m[a[i]] = i;
if (m.count(b[i]) && m[b[i]] != -1)
v[i][it] = m[b[i]];
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
}
for (int i = 0; i < n / 2; i++) swap(v[i][1], v[n-i-1][1]);
vector<int> u;
for (int i = 0; i < n; i++)
{
if (v[i][1] != -1) u.push_back(v[i][1]);
if (v[i][0] != -1 && v[i][0] != v[i][1]) u.push_back(v[i][0]);
}
vector<int> l;
for (int i : u)
{
int id = upper_bound(l.begin(), l.end(), i) - l.begin();
if (id == l.size()) l.push_back(i);
else l[id] = i;
}
cout << l.size() << "\n";
return 0;
}
Compilation message
exam.cpp: In function 'int main()':
exam.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if (id == l.size()) l.push_back(i);
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |