# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
835419 |
2023-08-23T14:18:44 Z |
otarius |
Exam (eJOI20_exam) |
C++17 |
|
70 ms |
8836 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] = -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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
1380 KB |
Output is correct |
3 |
Correct |
28 ms |
7352 KB |
Output is correct |
4 |
Correct |
23 ms |
3920 KB |
Output is correct |
5 |
Correct |
32 ms |
5068 KB |
Output is correct |
6 |
Correct |
19 ms |
2816 KB |
Output is correct |
7 |
Correct |
25 ms |
4112 KB |
Output is correct |
8 |
Correct |
30 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
388 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
1716 KB |
Output is correct |
3 |
Correct |
29 ms |
3040 KB |
Output is correct |
4 |
Correct |
34 ms |
3788 KB |
Output is correct |
5 |
Correct |
59 ms |
8836 KB |
Output is correct |
6 |
Correct |
70 ms |
5576 KB |
Output is correct |
7 |
Correct |
56 ms |
6760 KB |
Output is correct |
8 |
Correct |
30 ms |
3032 KB |
Output is correct |
9 |
Correct |
30 ms |
3560 KB |
Output is correct |
10 |
Correct |
47 ms |
5580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
388 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
444 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
572 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |