이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, int> letak;
int st[N*2 + 5];
void modify(int pos, int val){
for(pos += N, st[pos] = val; pos > 1; pos >>= 1){
st[pos >> 1] = max(st[pos], st[pos^1]);
}
}
int query(int l, int r){
int mx = 0;
for(l += N, r += N; l < r; l >>= 1, r >>= 1){
if(l&1){
mx = max(mx, st[l++]);
}
if(r & 1){
mx = max(mx, st[--r]);
}
}
return mx;
}
void solve(){
int n;
cin >> n;
int t[n + 1], h[n + 1];
for(int i = n; i >= 1; i--){
cin >> h[i];
}
for(int i = n; i >= 1; i--){
cin >> t[i];
}
memset(st, 0, sizeof(st));
set<int> sets;
for(int i = 1; i <= n; i++){
while(!sets.empty() && *sets.begin() < h[i]){
sets.erase(sets.begin());
}
int mx = query(0, i);
modify(i, mx);
sets.insert(h[i]);
letak[h[i]] = i;
if(sets.find(t[i]) != sets.end()){
modify(letak[t[i]], st[N + letak[t[i]]] + 1);
}
}
cout << query(0, n + 1) << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while(t--){
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |