//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m;
int arr[200005][3];
int proc[200005];
struct node{
int s,e,m;
set<ii> st;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
st.insert(ii(-1,0));
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,ii val){
auto it=st.insert(val).fi;
if ((*prev(it)).se>=val.se){
st.erase(it);
return;
}
while (next(it)!=st.end() && (*next(it)).se<=val.se){
st.erase(next(it));
}
if (s==e) return;
if (i<=m) l->update(i,val);
else r->update(i,val);
}
int query(int i,int j,int k){
if (s==i && e==j){
return (*--st.upper_bound(ii(k,-1))).se;
}
else if (j<=m) return l->query(i,j,k);
else if (m<i) return r->query(i,j,k);
else return max(l->query(i,m,k),r->query(m+1,j,k));
}
} *root=new node(0,200005);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>m;
rep(x,0,n){
rep(y,0,m){
cin>>arr[y][x];
}
}
rep(y,0,m) proc[y]=y;
sort(proc,proc+m,[](int i,int j){
return arr[i][0]<arr[j][0];
});
rep(x,1,3){
vector<int> temp;
rep(y,0,m) temp.push_back(arr[y][x]);
sort(all(temp));
map<int,int> id;
rep(y,0,m) id[temp[y]]=y;
rep(y,0,m) arr[y][x]=id[arr[y][x]];
}
rep(x,0,m){
int a=arr[proc[x]][1],b=(n==2?x:arr[proc[x]][2]);
root->update(a,ii(b,root->query(0,a,b)+1));
}
cout<<root->query(0,200005,1e9);
}
Compilation message
matrix.cpp: In constructor 'node::node(int, int)':
matrix.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
63724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
65516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
63724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
65516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |