結果

問題 No.2697 Range LIS Query
ユーザー inksamuraiinksamurai
提出日時 2024-03-22 22:56:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 547 ms / 10,000 ms
コード長 2,263 bytes
コンパイル時間 4,695 ms
コンパイル使用メモリ 270,020 KB
実行使用メモリ 29,688 KB
最終ジャッジ日時 2024-03-22 22:56:38
合計ジャッジ時間 11,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 12 ms
6,676 KB
testcase_04 AC 12 ms
6,676 KB
testcase_05 AC 12 ms
6,676 KB
testcase_06 AC 507 ms
29,688 KB
testcase_07 AC 476 ms
29,688 KB
testcase_08 AC 495 ms
29,688 KB
testcase_09 AC 395 ms
29,688 KB
testcase_10 AC 411 ms
29,688 KB
testcase_11 AC 394 ms
29,688 KB
testcase_12 AC 318 ms
28,712 KB
testcase_13 AC 344 ms
27,288 KB
testcase_14 AC 412 ms
27,480 KB
testcase_15 AC 518 ms
29,688 KB
testcase_16 AC 547 ms
29,688 KB
testcase_17 AC 540 ms
29,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _4ab8goq ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

const int inf=1e9;

struct N{
	int len=0,v=-1;
	int dp[4][4]={-inf};
};

N op(N l,N r){
	if(!l.len) return r;
	if(!r.len) return l;
	N ret;
	ret.len=l.len+r.len;
	ret.v=l.v>r.v?l.v:r.v;
	// print("a",ret.len,l.dp[0][0],r.dp[0][0]);
	rep(i,4){
		rng(j,i,4){
			ret.dp[i][j]=max(l.dp[i][j],r.dp[i][j]);
		}
	}
	rep(i,4){
		rng(j,i,4){
			rng(s,j,4){
				rng(e,s,4){
					ret.dp[i][e]=max(ret.dp[i][e],l.dp[i][j]+r.dp[s][e]);
				}
			}
		}
	}
	return ret;
}

N e(){
	return N{};
}

N mapping(int l,N r){
	if(l==-1) return r;
	r.v=l;
	rep(i,4){
		rng(j,i,4){
			r.dp[i][j]=-inf;
		}
	}
	r.dp[l][l]=r.len;
	return r;
}

int composition(int l,int r){
	if(l==-1) return r;
	if(r==-1) return l;
	return l;
}

int id(){
	return -1;
}

void slv(){
	int n;
	cin>>n;

	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		a[i]-=1;
	}

	atcoder::lazy_segtree<N,op,e,int,mapping,composition,id> seg(n);
	rep(i,n){
		N now;
		now.len=1;
		now.dp[a[i]][a[i]]=1;
		seg.set(i,now);
	}

	// N now=seg.prod(0,n);
	// // print(now.dp[0][0]);
	// seg.apply(4,n,0);
	// now=seg.prod(7,10);
	// print(now.v);
	// rep(i,4){
	// 	rng(j,i,4){
	// 		print(i,j,now.dp[i][j]);
	// 	}
	// }
	// print(now.len,now.dp[0][0]);
	// // N now=seg.prod(2,6);
	// // print(now.len);
	// print("bef");
	int q;
	cin>>q;
	rep(iter,q){
		int typ,l,r;
		cin>>typ>>l>>r;
		l-=1,r-=1;
		if(typ==1){
			N now=seg.prod(l,r+1);
			int ans=0;
			rep(i,4){
				rng(j,i,4){
					// print(i,j,now.dp[i][j]);
					ans=max(ans,now.dp[i][j]);
				}
			}
			// print(now.dp[0][0]);
			// print("e",now.len);
			cout<<ans<<"\n";
		}else{
			int x;
			cin>>x;
			x-=1;
			seg.apply(l,r+1,x);
		}
	}
}

signed main(){
_4ab8goq;
	slv();
}
0