# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
893717 |
2023-12-27T10:16:40 Z |
noiaint |
Exam (eJOI20_exam) |
C++17 |
|
25 ms |
14696 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int N = 1e6 + 5;
bool maxi(int &x, int y) {
if (x < y) {
x = y;
return true;
}
return false;
}
int n;
int a[N], b[N];
int l[N], r[N];
namespace task2 {
bool check() {
for (int i = 1; i + 1 <= n; ++i) {
if (b[i] != b[i + 1]) return false;
}
return true;
}
int d[N];
void solve() {
for (int i = 1; i <= n; ++i) if (a[i] == b[1]) {
int x = l[i] + 1;
int y = r[i] - 1;
d[x]++;
d[y + 1]--;
}
for (int i = 1; i <= n; ++i) d[i] += d[i - 1];
int ans = 0;
for (int i = 1; i <= n; ++i) ans += d[i] != 0;
cout << ans;
}
}
namespace task4 {
bool check() {
set<int> s;
for (int i = 1; i <= n; ++i) s.insert(a[i]);
return (s.size() == n);
}
int bit[N];
void update(int u, int c) {
for (; u < N; u += u & -u) maxi(bit[u], c);
}
int get(int u) {
int res = 0;
for (; u > 0; u -= u & -u) maxi(res, bit[u]);
return res;
}
map<int, int> pos;
void solve() {
for (int i = 1; i <= n; ++i) pos[a[i]] = i;
for (int i = 1; i <= n; ++i) {
auto it = pos.find(b[i]);
if (it == pos.end()) continue;
int x = pos[b[i]];
if (l[x] < i && i < r[x]) {
int cur = get(i - 1) + 1;
update(i, cur);
}
}
cout << get(n);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
stack<int> st;
for (int i = 1; i <= n; ++i) {
while (st.size() && a[i] >= a[st.top()]) st.pop();
l[i] = st.size() ? st.top() : 0;
st.push(i);
}
st = stack<int> {};
for (int i = n; i >= 1; --i) {
while (st.size() && a[i] >= a[st.top()]) st.pop();
r[i] = st.size() ? st.top() : n + 1;
st.push(i);
}
if (task2::check()) return task2::solve(), 0;
if (task4::check()) return task4::solve(), 0;
return 0;
}
Compilation message
exam.cpp: In function 'bool task4::check()':
exam.cpp:55:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | return (s.size() == n);
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
6 ms |
11076 KB |
Output is correct |
3 |
Correct |
13 ms |
11976 KB |
Output is correct |
4 |
Correct |
12 ms |
13148 KB |
Output is correct |
5 |
Correct |
22 ms |
14676 KB |
Output is correct |
6 |
Correct |
16 ms |
13144 KB |
Output is correct |
7 |
Correct |
13 ms |
13148 KB |
Output is correct |
8 |
Correct |
25 ms |
14696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
8536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
9052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |