답안 #330319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330319 2020-11-24T19:07:14 Z errorgorn 조화행렬 (KOI18_matrix) C++17
29 / 100
2928 ms 304148 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#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,1e9))).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(y,0,m) arr[y][2]=0;
	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=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 Correct 107 ms 68204 KB Output is correct
2 Correct 92 ms 67820 KB Output is correct
3 Correct 95 ms 67948 KB Output is correct
4 Correct 93 ms 68204 KB Output is correct
5 Correct 109 ms 68332 KB Output is correct
6 Correct 105 ms 74988 KB Output is correct
7 Correct 96 ms 69612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 65536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 68204 KB Output is correct
2 Correct 92 ms 67820 KB Output is correct
3 Correct 95 ms 67948 KB Output is correct
4 Correct 93 ms 68204 KB Output is correct
5 Correct 109 ms 68332 KB Output is correct
6 Correct 105 ms 74988 KB Output is correct
7 Correct 96 ms 69612 KB Output is correct
8 Correct 2782 ms 193236 KB Output is correct
9 Correct 1952 ms 183484 KB Output is correct
10 Correct 981 ms 166092 KB Output is correct
11 Correct 465 ms 95052 KB Output is correct
12 Correct 1262 ms 172264 KB Output is correct
13 Correct 1273 ms 297924 KB Output is correct
14 Correct 1022 ms 162944 KB Output is correct
15 Correct 486 ms 95052 KB Output is correct
16 Correct 1271 ms 304148 KB Output is correct
17 Correct 1266 ms 297932 KB Output is correct
18 Correct 1042 ms 192844 KB Output is correct
19 Correct 952 ms 158924 KB Output is correct
20 Correct 2928 ms 195784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 65536 KB Output isn't correct
2 Halted 0 ms 0 KB -