結果

問題 No.1804 Intersection of LIS
ユーザー 👑 kmjpkmjp
提出日時 2022-01-07 23:05:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,456 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 205,220 KB
実行使用メモリ 36,580 KB
最終ジャッジ日時 2023-08-09 03:36:58
合計ジャッジ時間 5,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,880 KB
testcase_01 AC 7 ms
19,800 KB
testcase_02 AC 7 ms
19,760 KB
testcase_03 AC 65 ms
22,460 KB
testcase_04 AC 65 ms
22,432 KB
testcase_05 AC 67 ms
22,380 KB
testcase_06 AC 67 ms
22,380 KB
testcase_07 AC 68 ms
22,464 KB
testcase_08 AC 74 ms
22,596 KB
testcase_09 AC 66 ms
22,384 KB
testcase_10 AC 67 ms
22,472 KB
testcase_11 AC 68 ms
22,608 KB
testcase_12 AC 70 ms
22,436 KB
testcase_13 AC 69 ms
22,600 KB
testcase_14 AC 70 ms
22,412 KB
testcase_15 AC 69 ms
22,400 KB
testcase_16 AC 65 ms
22,448 KB
testcase_17 AC 65 ms
22,420 KB
testcase_18 AC 8 ms
19,768 KB
testcase_19 AC 8 ms
19,792 KB
testcase_20 AC 7 ms
19,816 KB
testcase_21 AC 8 ms
19,724 KB
testcase_22 AC 8 ms
19,812 KB
testcase_23 AC 7 ms
19,964 KB
testcase_24 AC 8 ms
19,840 KB
testcase_25 AC 8 ms
19,768 KB
testcase_26 AC 8 ms
19,732 KB
testcase_27 AC 7 ms
19,740 KB
testcase_28 AC 7 ms
19,796 KB
testcase_29 AC 7 ms
19,876 KB
testcase_30 AC 8 ms
19,992 KB
testcase_31 AC 7 ms
19,744 KB
testcase_32 AC 8 ms
19,804 KB
testcase_33 AC 8 ms
19,828 KB
testcase_34 AC 7 ms
19,712 KB
testcase_35 AC 95 ms
36,580 KB
testcase_36 AC 101 ms
36,484 KB
testcase_37 AC 218 ms
36,420 KB
testcase_38 AC 219 ms
36,408 KB
testcase_39 AC 8 ms
19,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int P[302020];
int L[303030],R[303030];
int O[303030];
set<int> cand[303030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	FOR(i,N+2) O[i]=1<<30;
	
	int ma=0;
	FOR(i,N) {
		cin>>P[i];
		L[i]=lower_bound(O,O+N,P[i])-O;
		ma=max(ma,L[i]);
		O[L[i]]=P[i];
	}
	
	for(i=N-1;i>=0;i--) {
		if(L[i]==ma) {
			cand[L[i]].insert(P[i]);
		}
		else {
			if(cand[L[i]+1].lower_bound(P[i])!=cand[L[i]+1].end()) {
				cand[L[i]].insert(P[i]);
			}
		}
	}
	
	
	int inc=0;
	FOR(i,N) if(cand[L[i]].count(P[i])&&cand[L[i]].size()==1) inc++;
	cout<<inc<<endl;
	FOR(i,N) if(cand[L[i]].count(P[i])&&cand[L[i]].size()==1) cout<<P[i]<<" ";
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0