結果

問題 No.1234 典型RMQ
ユーザー 37zigen37zigen
提出日時 2020-09-21 04:38:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,339 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 4,083 ms
コンパイル使用メモリ 74,536 KB
実行使用メモリ 109,660 KB
最終ジャッジ日時 2023-08-08 19:06:24
合計ジャッジ時間 32,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
91,744 KB
testcase_01 AC 148 ms
92,152 KB
testcase_02 AC 148 ms
91,688 KB
testcase_03 AC 147 ms
91,892 KB
testcase_04 AC 147 ms
91,596 KB
testcase_05 AC 146 ms
92,016 KB
testcase_06 AC 1,289 ms
108,636 KB
testcase_07 AC 1,170 ms
108,024 KB
testcase_08 AC 1,302 ms
107,868 KB
testcase_09 AC 1,243 ms
108,636 KB
testcase_10 AC 1,275 ms
107,996 KB
testcase_11 AC 1,266 ms
108,580 KB
testcase_12 AC 1,255 ms
108,364 KB
testcase_13 AC 1,160 ms
108,524 KB
testcase_14 AC 1,248 ms
108,412 KB
testcase_15 AC 1,208 ms
108,116 KB
testcase_16 AC 1,256 ms
107,912 KB
testcase_17 AC 1,248 ms
108,380 KB
testcase_18 AC 1,119 ms
108,336 KB
testcase_19 AC 1,324 ms
108,300 KB
testcase_20 AC 1,028 ms
108,552 KB
testcase_21 AC 1,285 ms
108,672 KB
testcase_22 AC 1,304 ms
107,804 KB
testcase_23 AC 1,339 ms
109,660 KB
testcase_24 AC 1,263 ms
107,904 KB
testcase_25 AC 1,246 ms
107,632 KB
testcase_26 AC 1,270 ms
107,928 KB
testcase_27 AC 143 ms
91,796 KB
testcase_28 AC 149 ms
91,636 KB
testcase_29 AC 149 ms
91,724 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;
		
		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) {
			if (b<=l||r<=a) return INF;
			if (a<=l&&r<=b) {
				lazy[k]+=add;
				v[k]+=add;
				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]=lazy[k]+Math.min(v[2*k+1], v[2*k+2]);
			return lazy[k]+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