#include <bits/stdc++.h>
using namespace std;
int m,n;
const int MX=2e5+5;
struct A{
int x,y,z;
bool operator <(const A&r){
return x<r.x;
}
}a[MX];
struct Node{
int l,r,v;
}seg[MX*20];
int tree[MX];
int dp[MX];
map<int,int> mp1;
map<int,int> mp2;
int nn;
int f(int lef,int rig,int k,int lev){
if(lef>k || lev==0)return 2e9;
if(rig<=k)return seg[lev].v;
int mid=(lef+rig)/2;
return min(f(lef,mid,k,seg[lev].l),f(mid+1,rig,k,seg[lev].r));
}
void upd(int lef,int rig,int x,int y,int lev){
seg[lev].v=min(seg[lev].v,y);
if(lef==rig)return;
int mid=(lef+rig)/2;
if(x<=mid){
if(!seg[lev].l)seg[seg[lev].l=++nn].v=2e9;
upd(lef,mid,x,y,seg[lev].l);
}
else{
if(!seg[lev].r)seg[seg[lev].r=++nn].v=2e9;
upd(mid+1,rig,x,y,seg[lev].r);
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>m>>n;
int i,j;
for(i=1 ; i<=n ; i++)cin>>a[i].x;
for(i=1 ; i<=n ; i++)cin>>a[i].y;
for(i=1 ; i<=n ; i++)cin>>a[i].z;
for(i=1 ; i<=n ; i++)seg[tree[i]=i].v=2e9;
nn=n;
set<int> S1;
set<int> S2;
sort(a+1,a+n+1);
for(i=1 ; i<=n ; i++){
S1.insert(a[i].y);
S2.insert(a[i].z);
}
int cnt=0;
for(auto k: S1)mp1[k]=++cnt;cnt=0;
for(auto k: S2)mp2[k]=++cnt;
int ans=0;
for(i=1 ; i<=n ; i++){
int lef=1;
int rig=n;
int k=0;
while(rig>=lef){
int mid=(lef+rig)/2;
if(f(1,n,mp1[a[i].y],tree[mid])<=mp2[a[i].z]){
k=mid;
lef=mid+1;
}
else
rig=mid-1;
}
ans=max(ans,k+1);
upd(1,n,mp1[a[i].y],mp2[a[i].z],tree[k+1]);
}
cout<<ans;
return 0;
}
Compilation message
matrix.cpp: In function 'int main()':
matrix.cpp:57:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto k: S1)mp1[k]=++cnt;cnt=0;
^~~
matrix.cpp:57:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto k: S1)mp1[k]=++cnt;cnt=0;
^~~
matrix.cpp:43:11: warning: unused variable 'j' [-Wunused-variable]
int i,j;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2808 KB |
Output is correct |
2 |
Correct |
27 ms |
2552 KB |
Output is correct |
3 |
Correct |
28 ms |
2532 KB |
Output is correct |
4 |
Correct |
26 ms |
2552 KB |
Output is correct |
5 |
Correct |
39 ms |
2680 KB |
Output is correct |
6 |
Correct |
25 ms |
3368 KB |
Output is correct |
7 |
Correct |
26 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3420 KB |
Output is correct |
2 |
Correct |
34 ms |
3580 KB |
Output is correct |
3 |
Correct |
44 ms |
3532 KB |
Output is correct |
4 |
Correct |
45 ms |
3704 KB |
Output is correct |
5 |
Correct |
38 ms |
3576 KB |
Output is correct |
6 |
Correct |
33 ms |
4360 KB |
Output is correct |
7 |
Correct |
46 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2808 KB |
Output is correct |
2 |
Correct |
27 ms |
2552 KB |
Output is correct |
3 |
Correct |
28 ms |
2532 KB |
Output is correct |
4 |
Correct |
26 ms |
2552 KB |
Output is correct |
5 |
Correct |
39 ms |
2680 KB |
Output is correct |
6 |
Correct |
25 ms |
3368 KB |
Output is correct |
7 |
Correct |
26 ms |
2680 KB |
Output is correct |
8 |
Correct |
1299 ms |
51744 KB |
Output is correct |
9 |
Correct |
1139 ms |
49748 KB |
Output is correct |
10 |
Correct |
998 ms |
46072 KB |
Output is correct |
11 |
Correct |
675 ms |
33248 KB |
Output is correct |
12 |
Correct |
1048 ms |
47620 KB |
Output is correct |
13 |
Correct |
906 ms |
70036 KB |
Output is correct |
14 |
Correct |
1028 ms |
45808 KB |
Output is correct |
15 |
Correct |
723 ms |
33160 KB |
Output is correct |
16 |
Correct |
910 ms |
70248 KB |
Output is correct |
17 |
Correct |
965 ms |
70112 KB |
Output is correct |
18 |
Correct |
911 ms |
50780 KB |
Output is correct |
19 |
Correct |
947 ms |
44952 KB |
Output is correct |
20 |
Correct |
1310 ms |
52068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3420 KB |
Output is correct |
2 |
Correct |
34 ms |
3580 KB |
Output is correct |
3 |
Correct |
44 ms |
3532 KB |
Output is correct |
4 |
Correct |
45 ms |
3704 KB |
Output is correct |
5 |
Correct |
38 ms |
3576 KB |
Output is correct |
6 |
Correct |
33 ms |
4360 KB |
Output is correct |
7 |
Correct |
46 ms |
3704 KB |
Output is correct |
8 |
Correct |
1441 ms |
63204 KB |
Output is correct |
9 |
Correct |
1396 ms |
54100 KB |
Output is correct |
10 |
Correct |
1385 ms |
67416 KB |
Output is correct |
11 |
Correct |
1443 ms |
90820 KB |
Output is correct |
12 |
Correct |
1409 ms |
53996 KB |
Output is correct |
13 |
Correct |
1462 ms |
63640 KB |
Output is correct |
14 |
Correct |
1696 ms |
65756 KB |
Output is correct |
15 |
Correct |
1423 ms |
90028 KB |
Output is correct |
16 |
Correct |
1411 ms |
90104 KB |
Output is correct |
17 |
Correct |
1616 ms |
53904 KB |
Output is correct |
18 |
Correct |
2303 ms |
67140 KB |
Output is correct |
19 |
Correct |
1573 ms |
53956 KB |
Output is correct |
20 |
Correct |
1593 ms |
64240 KB |
Output is correct |
21 |
Correct |
1408 ms |
90152 KB |
Output is correct |
22 |
Correct |
2188 ms |
68088 KB |
Output is correct |
23 |
Correct |
1387 ms |
54056 KB |
Output is correct |
24 |
Correct |
1501 ms |
54100 KB |
Output is correct |
25 |
Correct |
1882 ms |
67316 KB |
Output is correct |
26 |
Correct |
1690 ms |
54152 KB |
Output is correct |
27 |
Correct |
1428 ms |
53980 KB |
Output is correct |
28 |
Correct |
1431 ms |
90036 KB |
Output is correct |
29 |
Correct |
1416 ms |
54012 KB |
Output is correct |
30 |
Correct |
1412 ms |
54000 KB |
Output is correct |
31 |
Correct |
1750 ms |
54276 KB |
Output is correct |
32 |
Correct |
1456 ms |
54024 KB |
Output is correct |