#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct el{
el(ll _x,ll _y,ll _z):x(_x),y(_y),z(_z) { }
ll x,y,z;
};
bool cmp(el a,el b)
{
return a.x<b.x;
}
ll m,n,ar[4][200005],pw[3][200014],anw;
vector<ll> arr[4];
vector<el> q;
ll sum(ll a,ll b)
{
ll ret=-1;
while(a)
{
ret=max(pw[b][a],ret);
a-=(a&-a);
}
return ret;
}
void upd(ll a,ll b,ll x)
{
while(a<=n)
{
pw[b][a]=max(x,pw[b][a]);
a+=(a&-a);
}
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(NULL);
cin>>m>>n;
for(int j=0;j<m;j++)
for(int i=1;i<=n;i++)
{
cin>>ar[j+1][i];
arr[j].push_back(ar[j+1][i]);
}
if(m==2)
for(int i=0;i<n;i++)
arr[2].push_back(arr[1][i]);
for(int j=0;j<3;j++)
sort(arr[j].begin(),arr[j].end());
for(int j=0;j<3;j++)
for(int i=0;i<n;i++)
ar[j+1][i+1]=lower_bound(arr[j].begin(),arr[j].end(),ar[j+1][i+1])-arr[j].begin()+1;
for(int i=1;i<=n;i++)
q.push_back(el(ar[1][i],ar[2][i],ar[3][i]));
sort(q.begin(),q.end(),cmp);
for(int i=0;i<n;i++)
{
ll a=min(sum(q[i].y,0),sum(q[i].z,1))+1;
anw=max(anw,a);
upd(q[i].y,0,a),upd(q[i].z,1,a);
}
cout<<anw;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1728 KB |
Output is correct |
2 |
Correct |
18 ms |
1600 KB |
Output is correct |
3 |
Correct |
21 ms |
1524 KB |
Output is correct |
4 |
Correct |
18 ms |
1532 KB |
Output is correct |
5 |
Correct |
19 ms |
1592 KB |
Output is correct |
6 |
Correct |
18 ms |
1600 KB |
Output is correct |
7 |
Correct |
24 ms |
1592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
1672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1728 KB |
Output is correct |
2 |
Correct |
18 ms |
1600 KB |
Output is correct |
3 |
Correct |
21 ms |
1524 KB |
Output is correct |
4 |
Correct |
18 ms |
1532 KB |
Output is correct |
5 |
Correct |
19 ms |
1592 KB |
Output is correct |
6 |
Correct |
18 ms |
1600 KB |
Output is correct |
7 |
Correct |
24 ms |
1592 KB |
Output is correct |
8 |
Correct |
449 ms |
21616 KB |
Output is correct |
9 |
Correct |
368 ms |
21584 KB |
Output is correct |
10 |
Correct |
377 ms |
21580 KB |
Output is correct |
11 |
Correct |
379 ms |
21612 KB |
Output is correct |
12 |
Correct |
499 ms |
21720 KB |
Output is correct |
13 |
Correct |
394 ms |
21556 KB |
Output is correct |
14 |
Correct |
382 ms |
21484 KB |
Output is correct |
15 |
Correct |
367 ms |
21452 KB |
Output is correct |
16 |
Correct |
396 ms |
21528 KB |
Output is correct |
17 |
Correct |
334 ms |
21452 KB |
Output is correct |
18 |
Correct |
356 ms |
21452 KB |
Output is correct |
19 |
Correct |
363 ms |
21456 KB |
Output is correct |
20 |
Correct |
371 ms |
21584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
1672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |