結果

問題 No.1234 典型RMQ
ユーザー 37zigen37zigen
提出日時 2020-09-21 04:38:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,473 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 77,960 KB
実行使用メモリ 100,932 KB
最終ジャッジ日時 2024-04-26 11:33:39
合計ジャッジ時間 34,615 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
75,304 KB
testcase_01 AC 163 ms
75,932 KB
testcase_02 AC 150 ms
74,784 KB
testcase_03 AC 160 ms
75,700 KB
testcase_04 AC 161 ms
75,324 KB
testcase_05 AC 157 ms
74,484 KB
testcase_06 AC 1,431 ms
99,440 KB
testcase_07 AC 1,226 ms
100,932 KB
testcase_08 AC 1,463 ms
99,116 KB
testcase_09 AC 1,390 ms
98,752 KB
testcase_10 AC 1,450 ms
99,388 KB
testcase_11 AC 1,447 ms
99,356 KB
testcase_12 AC 1,396 ms
99,300 KB
testcase_13 AC 1,267 ms
99,108 KB
testcase_14 AC 1,322 ms
99,208 KB
testcase_15 AC 1,361 ms
99,140 KB
testcase_16 AC 1,466 ms
99,492 KB
testcase_17 AC 1,332 ms
99,160 KB
testcase_18 AC 1,249 ms
99,164 KB
testcase_19 AC 1,406 ms
99,512 KB
testcase_20 AC 1,188 ms
99,276 KB
testcase_21 AC 1,404 ms
99,176 KB
testcase_22 AC 1,322 ms
98,684 KB
testcase_23 AC 1,473 ms
99,336 KB
testcase_24 AC 1,431 ms
98,900 KB
testcase_25 AC 1,401 ms
98,628 KB
testcase_26 AC 1,399 ms
98,720 KB
testcase_27 AC 146 ms
74,648 KB
testcase_28 AC 148 ms
74,788 KB
testcase_29 AC 156 ms
74,796 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