結果

問題 No.2697 Range LIS Query
ユーザー 👑 kmjpkmjp
提出日時 2024-03-23 02:15:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,246 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 210,396 KB
実行使用メモリ 38,108 KB
最終ジャッジ日時 2024-03-23 02:15:31
合計ジャッジ時間 21,835 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 13 ms
38,108 KB
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
権限があれば一括ダウンロードができます

ソースコード

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;}
//-------------------------------------------------------


template<class V,int NV> class SegTree_3 {
public:
	vector<V> ma;
	vector<int> S;
	V comp(V l,V r){ 
		V z;
		int a,b,c,d;
		FOR(a,4) FOR(b,4) z[a][b]=0;
		for(a=0;a<=3;a++) for(b=a;b<=3;b++) for(c=b;c<=3;c++) for(d=c;d<=3;d++) {
			z[a][d]=max(z[a][d],l[a][b]+r[c][d]);
		}
		
		return z;
	};
	SegTree_3(){
		ma.resize(NV*2);
		S.resize(NV*2,-1);
	};
	
	V getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l || y<=x) {
			V z;
			FOR(x,4) FOR(y,4) z[x][y]=0;
			
			return z;
		}
		if(S[k]>=0) {
			auto v=V();
			x=max(x,l);
			y=min(y,r);
			v[S[k]][S[k]]=y-x;
			return v;
		}
		if(x<=l && r<=y) return ma[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 x,int y, int v,int l=0,int r=NV,int k=1) {
		if(l>=r||y<=x) return;
		if(x<=l && r<=y) {
			S[k]=v;
		}
		else if(l < y && x < r) {
			if(S[k]>=0) {
				S[2*k]=S[2*k+1]=S[k];
				S[k]=-1;
			}
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
			ma[k]=comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
		}
	}
};

SegTree_3<array<array<int,4>,4>,1<<18> st;

int N,Q;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		st.update(i+1,i+2,x);
	}
	cin>>Q;
	while(Q--) {
		int L,R;
		cin>>i>>L>>R;
		if(i==1) {
			auto v=st.getval(L,R+1);
			int ma=0;
			FOR(x,4) FOR(y,4) ma=max(ma,v[x][y]);
			cout<<ma<<endl;
		}
		else {
			cin>>x;
			st.update(L,R+1,x);
		}
	}
			
		
}


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