結果

問題 No.1234 典型RMQ
ユーザー 37zigen37zigen
提出日時 2020-09-21 04:16:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,325 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 109,280 KB
最終ジャッジ日時 2023-08-08 19:05:19
合計ジャッジ時間 32,032 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
91,856 KB
testcase_01 AC 140 ms
91,844 KB
testcase_02 AC 145 ms
91,956 KB
testcase_03 AC 143 ms
91,944 KB
testcase_04 AC 144 ms
91,684 KB
testcase_05 AC 143 ms
91,356 KB
testcase_06 AC 1,280 ms
108,780 KB
testcase_07 AC 1,146 ms
108,376 KB
testcase_08 AC 1,316 ms
107,968 KB
testcase_09 AC 1,241 ms
108,568 KB
testcase_10 AC 1,301 ms
108,520 KB
testcase_11 AC 1,295 ms
108,672 KB
testcase_12 AC 1,252 ms
108,392 KB
testcase_13 AC 1,158 ms
108,452 KB
testcase_14 AC 1,274 ms
108,844 KB
testcase_15 AC 1,208 ms
108,100 KB
testcase_16 AC 1,295 ms
108,400 KB
testcase_17 AC 1,291 ms
108,596 KB
testcase_18 AC 1,116 ms
108,444 KB
testcase_19 AC 1,325 ms
107,920 KB
testcase_20 AC 1,048 ms
108,132 KB
testcase_21 AC 1,280 ms
108,416 KB
testcase_22 AC 1,280 ms
109,280 KB
testcase_23 AC 1,294 ms
108,356 KB
testcase_24 AC 1,277 ms
108,400 KB
testcase_25 AC 1,253 ms
108,480 KB
testcase_26 AC 1,274 ms
107,292 KB
testcase_27 AC 141 ms
91,708 KB
testcase_28 AC 144 ms
91,712 KB
testcase_29 AC 146 ms
91,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

class Main {
	public static void main(String[] $) {
		new Main().run();
	}
	
	class Seg {
		int n=1<<20;
		long[] v=new long[2*n-1];
		long[] lazy=new long[2*n-1];
		final long INF=Long.MAX_VALUE/3;
		
		void push(int k) {
			v[k]+=lazy[k];
			if (2*k+1<v.length) {
				lazy[2*k+1]+=lazy[k];
				lazy[2*k+2]+=lazy[k];
			}
			lazy[k]=0;
		}
		
		long query(int a,int b,long add) {
			return query(0,n,a,b,0,add);
		}
		
		long query(int l,int r,int a,int b,int k,long add) {
			push(k);
			if (b<=l||r<=a) return INF;
			if (a<=l&&r<=b) {
				lazy[k]+=add;
				push(k);
				return v[k];
			}
			long vl=query(l,(l+r)/2,a,b,2*k+1,add);
			long vr=query((l+r)/2,r,a,b,2*k+2,add);
			v[k]=Math.min(v[2*k+1], v[2*k+2]);
			return Math.min(vl, vr);
		}
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		Seg seg=new Seg();
		for (int i=0;i<N;++i) {
			long a=sc.nextLong();
			seg.query(i, i+1, a);
		}
		int Q=sc.nextInt();
		for (int q=0;q<Q;++q) {
			int k=sc.nextInt();
			int l=sc.nextInt()-1;
			int r=sc.nextInt()-1;
			int c=sc.nextInt();
			if (k==1) {
				seg.query(l, r+1, c);
			} else {
				pw.println(seg.query(l, r+1, 0));
			}
		}
		pw.flush();
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
0