結果

問題 No.3618 Omega Cat(Making ver.)
コンテスト
ユーザー 👑 kmjp
提出日時 2026-08-09 00:16:41
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 353 ms / 2,000 ms
+ 115µs
コード長 2,580 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,648 ms
コンパイル使用メモリ 226,588 KB
実行使用メモリ 37,904 KB
最終ジャッジ日時 2026-08-09 00:16:51
合計ジャッジ時間 8,956 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
サンプル 0 % AC * 1
小課題1 20 % AC * 5
小課題2 20 % AC * 12
小課題3 40 % AC * 24
小課題4 20 % AC * 38
合計 3.5 * 100% = 350 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 T;
int N,H[202020];

const int def=-1<<20;
template<class V,int NV> class SegTree_ma {
public:
	vector<V> val;
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_ma(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v,int force=0) {
		entry += NV;
		val[entry]=max(v,val[entry]);
		if(force) val[entry]=v;
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_ma<int,1<<20> st[4];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		vector<int> Hs={0,1<<30};
		cin>>N;
		FOR(i,N) {
			cin>>H[i];
			Hs.push_back(H[i]);
		}
		sort(ALL(Hs));
		FOR(i,N) H[i]=lower_bound(ALL(Hs),H[i])-Hs.begin();
		FOR(i,4) FOR(j,N+2) st[i].update(j,-1<<20,1);
		st[0].update(N+1,0);
		st[0].update(H[0],1);
		for(i=1;i<N-1;i++) {
			// 3->3
			x=st[3].getval(0,H[i]+1);
			y=st[3].getval(0,N+2);
			st[3].update(H[i],x+1);
			st[3].update(N+1,y);
			
			// 2->2
			// 2->3
			x=st[2].getval(H[i],N+2);
			y=st[2].getval(0,N+2);
			st[2].update(H[i],x+1);
			st[3].update(H[i],x+1);
			st[2].update(0,y);
			st[3].update(0,y);
			
			// 1->1
			// 1->2
			x=st[1].getval(0,H[i]+1);
			y=st[1].getval(0,N+2);
			st[1].update(H[i],x+1);
			st[2].update(H[i],x+1);
			st[1].update(N+1,y);
			st[2].update(N+1,y);
			
			// 0->0
			// 0->1
			x=st[0].getval(H[i],N+2);
			y=st[0].getval(0,N+2);
			st[0].update(H[i],x+1);
			st[1].update(H[i],x+1);
			st[0].update(0,y);
			st[1].update(0,y);
			
		}
		int ret=0;
		FOR(i,N+2) {
			x=st[3].getval(i,i+1);
			if(i<=H[N-1]) ret=max(ret,x+1);
			else ret=max(ret,x);
		}
		cout<<N-ret<<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