답안 #465571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465571 2021-08-16T11:31:58 Z Sench2006 Exam (eJOI20_exam) C++14
36 / 100
134 ms 7620 KB
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;

#define ll long long
#define ar array

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

// --------------- SOLUTION --------------- //

const int N = 1e5+5;
int n;
int a[N], b[N];
int nm[N], pm[N];

void pre() {
    stack<int> s;
    for (int i = 1; i <= n; ++i) {
        while (!s.empty() && a[s.top()] <= a[i])
            s.pop();
        if (s.empty())
            pm[i] = 0;
        else
            pm[i] = s.top();
        s.push(i);
    }
    while (!s.empty())
        s.pop();
    for (int i = n; i >= 1; --i) {
        while (!s.empty() && a[s.top()] <= a[i])
            s.pop();
        if (s.empty())
            nm[i] = n + 1;
        else
            nm[i] = s.top();
        s.push(i);
    }
}

int t[N * 4];
void ubd(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        t[pos] = y;
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
    t[pos] = max(t[pos * 2], t[pos * 2 + 1]);
}
 
int qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[pos];
    int m = (tl + tr) / 2;
    return max(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}
 
map <int, int> mp;
int segTreeSolve() {
    for (int i = 1; i <= n; ++i)
        mp[a[i]] = i;
 
    for (int i = 1; i <= n; ++i) {
        if (mp.find(b[i]) == mp.end())
            continue;
        int x = mp[b[i]];
        if (pm[x] < i && i < nm[x]) {
            ubd(1, n, x, qry(1, n, 1, x, 1) + 1, 1);
        }
    }
    return t[1];
}

void solve() { 
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        cin >> b[i];
 
    pre();
    cout << segTreeSolve() << "\n";
}

int main() {
    fastio;
    // fileio;
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 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 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 4 ms 708 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 664 KB Output is correct
2 Correct 35 ms 2972 KB Output is correct
3 Correct 132 ms 6848 KB Output is correct
4 Correct 106 ms 6868 KB Output is correct
5 Correct 134 ms 7600 KB Output is correct
6 Correct 130 ms 7560 KB Output is correct
7 Correct 111 ms 7620 KB Output is correct
8 Correct 98 ms 7212 KB Output is correct
9 Correct 124 ms 7552 KB Output is correct
10 Correct 93 ms 7492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -