# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
462221 |
2021-08-10T08:48:18 Z |
Tenis0206 |
Exam (eJOI20_exam) |
C++11 |
|
108 ms |
10828 KB |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005],b[100005],l[100005],r[100005],fr[100005];
vector<int> poz[200005],v;
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;
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);
}
}
bool subtask2()
{
for(int i=2; i<=n; i++)
{
if(b[i]!=b[i-1])
{
return false;
}
}
return true;
}
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_dp()
{
for(int i=1;i<=n;i++)
{
poz[a[i]].push_back(i);
}
int Max = 0;
for(int i=1;i<=n;i++)
{
for(int j=poz[b[i]].size()-1;j>=0;j--)
{
int p = poz[b[i]][j];
if(p>i && l[p]>=i)
{
continue;
}
if(p<i && r[p]<=i)
{
continue;
}
int dp = 1 + aib.query(p);
aib.update(p,dp);
Max = max(Max,dp);
}
}
return Max;
}
int get_poz(int val)
{
int st = 1;
int dr = v.size();
int poz = 0;
while(st<=dr)
{
int mij = (st+dr)>>1;
if(v[mij-1]<=val)
{
poz = mij;
st = mij+1;
}
else
{
dr = mij-1;
}
}
return poz;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
v.push_back(a[i]);
}
for(int i=1; i<=n; i++)
{
cin>>b[i];
v.push_back(b[i]);
}
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
{
a[i] = get_poz(a[i]);
b[i] = get_poz(b[i]);
}
precalc_stack();
if(subtask2())
{
cout<<solve_subtask2()<<'\n';
return 0;
}
cout<<solve_dp()<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
11 ms |
5712 KB |
Output is correct |
3 |
Correct |
35 ms |
7776 KB |
Output is correct |
4 |
Correct |
38 ms |
8136 KB |
Output is correct |
5 |
Correct |
68 ms |
7808 KB |
Output is correct |
6 |
Correct |
38 ms |
7872 KB |
Output is correct |
7 |
Correct |
44 ms |
7868 KB |
Output is correct |
8 |
Correct |
60 ms |
7864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5052 KB |
Output is correct |
4 |
Correct |
7 ms |
5324 KB |
Output is correct |
5 |
Correct |
8 ms |
5328 KB |
Output is correct |
6 |
Correct |
7 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5324 KB |
Output is correct |
2 |
Correct |
39 ms |
7324 KB |
Output is correct |
3 |
Correct |
94 ms |
10560 KB |
Output is correct |
4 |
Correct |
108 ms |
10736 KB |
Output is correct |
5 |
Correct |
87 ms |
10812 KB |
Output is correct |
6 |
Correct |
83 ms |
10824 KB |
Output is correct |
7 |
Correct |
79 ms |
10768 KB |
Output is correct |
8 |
Correct |
91 ms |
10808 KB |
Output is correct |
9 |
Correct |
98 ms |
10800 KB |
Output is correct |
10 |
Correct |
72 ms |
10828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
5032 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5052 KB |
Output is correct |
10 |
Correct |
7 ms |
5324 KB |
Output is correct |
11 |
Correct |
8 ms |
5328 KB |
Output is correct |
12 |
Correct |
7 ms |
5324 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
4940 KB |
Output is correct |
22 |
Correct |
4 ms |
5068 KB |
Output is correct |
23 |
Correct |
5 ms |
5196 KB |
Output is correct |
24 |
Correct |
17 ms |
5196 KB |
Output is correct |
25 |
Correct |
8 ms |
5196 KB |
Output is correct |
26 |
Correct |
7 ms |
5196 KB |
Output is correct |
27 |
Correct |
10 ms |
5196 KB |
Output is correct |
28 |
Correct |
9 ms |
5196 KB |
Output is correct |
29 |
Correct |
6 ms |
5196 KB |
Output is correct |
30 |
Correct |
7 ms |
5196 KB |
Output is correct |
31 |
Correct |
6 ms |
5344 KB |
Output is correct |
32 |
Correct |
7 ms |
5196 KB |
Output is correct |