# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
813534 |
2023-08-07T19:49:04 Z |
ZeroCool |
Exam (eJOI20_exam) |
C++14 |
|
60 ms |
4524 KB |
#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 |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
1068 KB |
Output is correct |
3 |
Correct |
38 ms |
4524 KB |
Output is correct |
4 |
Correct |
24 ms |
4136 KB |
Output is correct |
5 |
Correct |
60 ms |
4096 KB |
Output is correct |
6 |
Correct |
25 ms |
4184 KB |
Output is correct |
7 |
Correct |
29 ms |
4180 KB |
Output is correct |
8 |
Correct |
58 ms |
4124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |