-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathque3.cpp
More file actions
68 lines (60 loc) · 801 Bytes
/
que3.cpp
File metadata and controls
68 lines (60 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
#define forp(i,a,n) for(int i=(a);i<(n);i++)
int loope(int dp[],int r,int k)
{
int mid,l=-1;
while(r-l>1)
{
mid=(l+r)/2;
if(dp[mid]>=k)
{
r=mid;
}
else
l=mid;
}
return r;
}
int loop(int a[],int n)
{
int dp[n];
int d=1;
dp[0]=a[0];
for(int i=1;i<(n);i++)
{
if(a[i]<dp[0])
{
dp[0]=a[i];
}
else if(a[i]>dp[d-1])
{
dp[d]=a[i];
d++;
}
else
{
dp[loope(dp,d-1,a[i])]=a[i];
}
}
return d;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[2*n+5];
forp(i,0,n){
cin>>a[i];
a[i+n]=a[i];
}
int maximum=0;
forp(i,0,n)
maximum=max(maximum,loop(a+i,n));
cout<<maximum<<endl;
}
}