# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
460914 |
2021-08-09T11:00:30 Z |
Tenis0206 |
Exam (eJOI20_exam) |
C++11 |
|
132 ms |
7748 KB |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005],b[100005],aux[100005],l[100005],r[100005],fr[100005];
int dp[100005],dp2[5005][5005];
class arbore_indexat_binar
{
int aib[100005];
private:
int ub(int x)
{
return (x&(-x));
}
public:
void update(int poz, int val)
{
for(int i=poz;i<=n;i+=ub(i))
{
aib[i] = max(aib[i],val);
}
}
int query(int poz)
{
int rez = 0;
for(int i=poz;i>=1;i-=ub(i))
{
rez = max(rez,aib[i]);
}
return rez;
}
} aib;
bool subtask2()
{
for(int i=2; i<=n; i++)
{
if(b[i]!=b[i-1])
{
return false;
}
}
return true;
}
bool subtask4()
{
for(int i=1; i<=n; i++)
{
aux[i] = a[i];
}
sort(aux+1,aux+n+1);
for(int i=2; i<=n; i++)
{
if(aux[i]==aux[i-1])
{
return false;
}
}
return true;
}
void precalc_stack()
{
stack<int> st;
for(int i=1; i<=n; i++)
{
while(!st.empty() && a[i]>a[st.top()])
{
st.pop();
}
if(st.empty())
{
l[i] = 0;
}
else
{
l[i] = st.top();
}
st.push(i);
}
while(!st.empty())
{
st.pop();
}
for(int i=n; i>=1; i--)
{
while(!st.empty() && a[i]>a[st.top()])
{
st.pop();
}
if(st.empty())
{
r[i] = n+1;
}
else
{
r[i] = st.top();
}
st.push(i);
}
}
int solve_subtask2()
{
for(int i=1; i<=n; i++)
{
if(a[i]==b[1])
{
++fr[l[i]+1];
--fr[r[i]];
}
}
int rez = 0;
for(int i=1; i<=n; i++)
{
fr[i]+=fr[i-1];
if(fr[i])
{
++rez;
}
}
return rez;
}
int solve_subtask4()
{
map<int,int> poz;
for(int i=1;i<=n;i++)
{
poz[a[i]] = i;
}
int Max = 0;
for(int i=1;i<=n;i++)
{
if(poz[b[i]]>i && l[poz[b[i]]]>=i)
{
continue;
}
if(poz[b[i]]<i && r[poz[b[i]]]<=i)
{
continue;
}
dp[i] = 1 + aib.query(poz[b[i]]);
aib.update(poz[b[i]],dp[i]);
Max = max(Max,dp[i]);
}
return Max;
}
int solve_general()
{
int Max = 0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[j]!=b[i])
{
continue;
}
if(j>i && l[j]>=i)
{
continue;
}
if(j<i && r[j]<=i)
{
continue;
}
dp2[i][j] = 1 + aib.query(j-1);
aib.update(j,dp2[i][j]);
Max = max(Max,dp2[i][j]);
}
}
return Max;
}
int main()
{
// freopen("nr.in","r",stdin);
// freopen("nr.out","w",stdout);
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];
}
precalc_stack();
if(subtask2())
{
cout<<solve_subtask2()<<'\n';
return 0;
}
if(subtask4())
{
cout<<solve_subtask4()<<'\n';
return 0;
}
cout<<solve_general()<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
720 KB |
Output is correct |
3 |
Correct |
20 ms |
2448 KB |
Output is correct |
4 |
Correct |
17 ms |
2572 KB |
Output is correct |
5 |
Correct |
42 ms |
2256 KB |
Output is correct |
6 |
Correct |
18 ms |
2344 KB |
Output is correct |
7 |
Correct |
20 ms |
2252 KB |
Output is correct |
8 |
Correct |
29 ms |
2180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
5 ms |
588 KB |
Output is correct |
5 |
Correct |
4 ms |
716 KB |
Output is correct |
6 |
Correct |
5 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
716 KB |
Output is correct |
2 |
Correct |
52 ms |
3140 KB |
Output is correct |
3 |
Correct |
132 ms |
7192 KB |
Output is correct |
4 |
Correct |
129 ms |
7236 KB |
Output is correct |
5 |
Correct |
128 ms |
7740 KB |
Output is correct |
6 |
Correct |
130 ms |
7708 KB |
Output is correct |
7 |
Correct |
120 ms |
7720 KB |
Output is correct |
8 |
Correct |
107 ms |
7552 KB |
Output is correct |
9 |
Correct |
123 ms |
7748 KB |
Output is correct |
10 |
Correct |
85 ms |
7656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
588 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |