結果

問題 No.1234 典型RMQ
ユーザー 37zigen37zigen
提出日時 2020-09-21 04:34:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 3,410 ms
コンパイル使用メモリ 74,372 KB
実行使用メモリ 110,420 KB
最終ジャッジ日時 2023-09-27 06:56:02
合計ジャッジ時間 33,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 147 ms
92,192 KB
testcase_02 AC 148 ms
91,724 KB
testcase_03 AC 143 ms
92,132 KB
testcase_04 AC 145 ms
91,964 KB
testcase_05 AC 141 ms
92,280 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 140 ms
91,592 KB
testcase_28 AC 148 ms
91,696 KB
testcase_29 AC 148 ms
92,512 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]=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