結果

問題 No.2861 Slime Party
ユーザー 👑 kmjpkmjp
提出日時 2024-08-27 23:34:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,268 ms / 4,000 ms
コード長 4,722 bytes
コンパイル時間 3,547 ms
コンパイル使用メモリ 234,008 KB
実行使用メモリ 151,204 KB
最終ジャッジ日時 2024-08-27 23:35:31
合計ジャッジ時間 73,543 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 831 ms
150,884 KB
testcase_01 AC 14 ms
37,996 KB
testcase_02 AC 14 ms
38,120 KB
testcase_03 AC 11 ms
35,960 KB
testcase_04 AC 10 ms
38,124 KB
testcase_05 AC 11 ms
38,120 KB
testcase_06 AC 10 ms
36,060 KB
testcase_07 AC 13 ms
38,252 KB
testcase_08 AC 17 ms
38,120 KB
testcase_09 AC 14 ms
37,996 KB
testcase_10 AC 14 ms
35,984 KB
testcase_11 AC 16 ms
36,188 KB
testcase_12 AC 13 ms
36,260 KB
testcase_13 AC 16 ms
38,496 KB
testcase_14 AC 17 ms
36,208 KB
testcase_15 AC 27 ms
36,552 KB
testcase_16 AC 14 ms
36,264 KB
testcase_17 AC 15 ms
36,188 KB
testcase_18 AC 15 ms
36,284 KB
testcase_19 AC 15 ms
38,004 KB
testcase_20 AC 16 ms
36,028 KB
testcase_21 AC 1,041 ms
91,868 KB
testcase_22 AC 1,017 ms
92,300 KB
testcase_23 AC 1,028 ms
91,656 KB
testcase_24 AC 1,021 ms
91,628 KB
testcase_25 AC 1,070 ms
91,616 KB
testcase_26 AC 978 ms
91,648 KB
testcase_27 AC 898 ms
91,664 KB
testcase_28 AC 896 ms
91,944 KB
testcase_29 AC 904 ms
91,752 KB
testcase_30 AC 933 ms
91,672 KB
testcase_31 AC 1,005 ms
91,728 KB
testcase_32 AC 1,042 ms
91,656 KB
testcase_33 AC 1,045 ms
91,644 KB
testcase_34 AC 1,096 ms
91,756 KB
testcase_35 AC 1,049 ms
91,536 KB
testcase_36 AC 1,082 ms
91,812 KB
testcase_37 AC 1,095 ms
92,040 KB
testcase_38 AC 1,110 ms
91,588 KB
testcase_39 AC 1,115 ms
91,680 KB
testcase_40 AC 1,110 ms
91,628 KB
testcase_41 AC 928 ms
92,140 KB
testcase_42 AC 931 ms
92,464 KB
testcase_43 AC 944 ms
91,600 KB
testcase_44 AC 995 ms
91,724 KB
testcase_45 AC 928 ms
91,664 KB
testcase_46 AC 1,076 ms
91,572 KB
testcase_47 AC 1,093 ms
91,476 KB
testcase_48 AC 1,108 ms
91,680 KB
testcase_49 AC 1,106 ms
92,264 KB
testcase_50 AC 1,150 ms
91,664 KB
testcase_51 AC 1,054 ms
150,244 KB
testcase_52 AC 1,124 ms
150,472 KB
testcase_53 AC 1,154 ms
150,396 KB
testcase_54 AC 1,157 ms
150,316 KB
testcase_55 AC 1,148 ms
150,456 KB
testcase_56 AC 1,130 ms
150,444 KB
testcase_57 AC 1,123 ms
150,564 KB
testcase_58 AC 1,126 ms
150,628 KB
testcase_59 AC 1,268 ms
150,396 KB
testcase_60 AC 1,138 ms
150,448 KB
testcase_61 AC 1,197 ms
150,480 KB
testcase_62 AC 1,018 ms
150,232 KB
testcase_63 AC 1,029 ms
150,260 KB
testcase_64 AC 1,172 ms
150,500 KB
testcase_65 AC 988 ms
150,452 KB
testcase_66 AC 1,189 ms
150,372 KB
testcase_67 AC 680 ms
150,456 KB
testcase_68 AC 1,000 ms
150,468 KB
testcase_69 AC 810 ms
150,252 KB
testcase_70 AC 746 ms
151,204 KB
testcase_71 AC 579 ms
150,404 KB
testcase_72 AC 1,002 ms
151,004 KB
testcase_73 AC 844 ms
150,324 KB
testcase_74 AC 936 ms
150,368 KB
testcase_75 AC 598 ms
151,124 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,Q,root;
ll L;
ll A[202020];
ll X[202020];

struct HLdecomp {
	static const int MD=20;
	int N,NE,id;
	vector<vector<int>> E;
	vector<int> D,S,B,C; // depth, size, base,heavy child
	
	vector<int> L,R,rev; // EulerTour
	vector<vector<int>> P,Cs; // parent for LCA,children
	void init(int N) { this->N=N, NE=0, E.clear(),E.resize(N); Cs.clear(),Cs.resize(N);
		D=S=B=C=L=R=rev=vector<int>(N,0); id=0; int i; P.clear(); FOR(i,MD+1) P.push_back(vector<int>(N,0));}
	void add_edge(int a,int b){ E[a].push_back(b),E[b].push_back(a); NE++;} // undir
	void dfs(int cur,int pre) { // get depth, parent, size, largest subtree
		int i;
		P[0][cur]=pre;S[cur]=1;C[cur]=-1;B[cur]=cur;
		D[cur]=(pre==cur)?0:(D[pre]+1);
		FOR(i,E[cur].size()) if(E[cur][i]!=pre) {
			int r=E[cur][i]; dfs(r,cur); S[cur]+=S[r];
			if(C[cur]==-1 || S[r]>S[C[cur]]) C[cur]=r;
		}
	}
	void dfs2(int cur,int pre) { // set base and list
		if(pre!=cur && C[pre]==cur) B[cur]=B[pre];
		else B[cur]=cur;
		Cs[B[cur]].push_back(cur);
		L[cur]=id++;
		rev[L[cur]]=cur;
		// DFS順を先行
		if(C[cur]!=-1) dfs2(C[cur],cur);
		FORR(r,E[cur]) if(r!=pre && r!=C[cur]) dfs2(r,cur);
		R[cur]=id;
	}
	pair<int,int> lca(int a,int b) {
		int ret=0,i,aa=a,bb=b;
		if(D[aa]>D[bb]) swap(aa,bb);
		for(i=19;i>=0;i--) if(D[bb]-D[aa]>=1<<i) bb=P[i][bb];
		for(i=19;i>=0;i--) if(P[i][aa]!=P[i][bb]) aa=P[i][aa], bb=P[i][bb];
		return make_pair((aa==bb)?aa:P[0][aa], D[a]+D[b]-2*D[(aa==bb)?aa:P[0][aa]]);
	}
	int getpar(int cur,int up) {
		int i;
		FOR(i,20) if(up&(1<<i)) cur=P[i][cur];
		return cur;
	}
	void decomp(int root=0){
		assert(NE==N-1);
		dfs(root,root); dfs2(root,root);
		int i,x; FOR(i,MD) FOR(x,N) P[i+1][x]=P[i][P[i][x]];
	}
};

HLdecomp hl;
static ll const def=0;
template<class V,int NV> class SegTree_3 {
public:
	vector<V> val, ma;
	SegTree_3(){
		int i;
		val.resize(NV*2,0); ma.resize(NV*2,0);
	};
	
	V getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l || y<=x) return 1LL<<60;
		if(x<=l && r<=y) return ma[k];
		return val[k]+min(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, V v,int l=0,int r=NV,int k=1) {
		if(l>=r||y<=x) return;
		if(x<=l && r<=y) {
			val[k]+=v;
			ma[k]+=v;
		}
		else if(l < y && x < r) {
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
			ma[k]=val[k]+min(ma[k*2],ma[k*2+1]);
		}
	}
};
SegTree_3<ll,1<<20> st;

void add(int f,ll v) {
	while(hl.B[f]!=root) {
		st.update(hl.L[hl.B[f]],hl.L[f]+1,v);
		f=hl.P[0][hl.B[f]];
	}
	st.update(hl.L[root],hl.L[f]+1,v);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q>>L;
	hl.init(N);
	vector<pair<ll,int>> V;
	set<int> S;
	FOR(i,N) {
		cin>>A[i];
		V.push_back({-A[i],i});
	}
	
	sort(ALL(V));
	FORR2(a,i,V) {
		auto it=S.insert(i).first;
		x=y=-1;
		if(it!=S.begin()) x=*prev(it);
		if(next(it)!=S.end()) y=*next(it);
		if(x==-1&&y==-1) {
			continue;
		}
		else if(x==-1) {
			hl.add_edge(i,y);
		}
		else if(y==-1) {
			hl.add_edge(i,x);
		}
		else if(A[x]<A[y]) {
			hl.add_edge(i,x);
		}
		else {
			hl.add_edge(i,y);
		}
	}
	root=V[0].second;
	hl.decomp(root);
	FOR(i,N) {
		cin>>X[i];
		if(i!=root) {
			st.update(hl.L[i],hl.L[i]+1,L-A[hl.P[0][i]]);
		}
		else {
			st.update(hl.L[i],hl.L[i]+1,L-(1LL<<60));
		}
		add(i,X[i]);
	}
	while(Q--) {
		cin>>i;
		if(i==1) {
			cin>>x>>y;
			x--;
			add(x,y-X[x]);
			X[x]=y;
		}
		else {
			cin>>x;
			x--;
			if(L>A[x]) {
				;
			}
			else if(x+1<N&&L>A[x+1]) {
				x++;
			}
			else {
				cout<<L<<endl;
				continue;
			}
			
			while(x!=root) {
				if(st.getval(hl.L[hl.B[x]],hl.L[x]+1)>0) {
					x=hl.P[0][hl.B[x]];
				}
				else {
					for(i=20;i>=0;i--) if(hl.D[x]>=(1<<i)) {
						if(st.getval(hl.L[x]+1-(1<<i),hl.L[x]+1)>0) x=hl.rev[hl.L[x]-(1<<i)];
					}
					break;
				}
			}
			ll v;
			if(x==root) {
				v=st.getval(0,1)+(1LL<<60);
			}
			else {
				v=st.getval(hl.L[x],hl.L[x]+1)+A[hl.P[0][x]];
			}
			cout<<v<<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