이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 1e18
#define LL long long
#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int mxn = 1e5 +5;
int n;
int A[mxn];
int B[mxn];
int l[mxn];
int r[mxn];
void two_pointers(){
int x = B[0];
int res = 0;
for(int i = 0;i<n;i++) {
if(A[i] == x) {
res++;
int j = i - 1;
while(j >= 0 && A[j] <= x) {
j--;
res++;
}
j = i + 1;
while(j < n && A[j] <= x) {
res++;
j++;
}
i = j - 1;
}
}
cout<<res<<endl;
}
void solve(){
cin>>n;
set<int>s;
int c[n+5];
for(int i = 0;i<n;i++)cin>>A[i];
for(int i = 0;i<n;i++){
cin>>B[i];
s.insert(B[i]);
}
for(int i = 0;i<n;i++)c[i+1] = A[i];
c[0] = inf;
c[n+1] = inf;
stack<int> st;
st.push(0);
for(int i = 1;i<=n;i++){
while(st.size() && (c[st.top()] <= c[i]))st.pop();
l[i-1] = st.top() - 1;
st.push(i);
}
//st = stack<int>();
while(st.size())st.pop();
st.push(n+1);
for(int i = n;i;i--){
while(st.size() && (c[st.top()] <= c[i]))st.pop();
//cout<<"tukaa"<<endl;
r[i-1] = st.top() - 1;
if(r[i-1] >= n)r[i-1] = -1;
st.push(i);
}
bool sub2 = true;
for(int i = 1;i<n;i++){
if(B[i] != B[0]){
sub2 = false;
break;
}
}
if(sub2){
two_pointers();
return;
}
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(0);
#endif
solve();
}
# | 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... |