結果

問題 No.631 Noelちゃんと電車旅行
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-05 22:45:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,140 ms / 2,000 ms
コード長 3,248 bytes
コンパイル時間 4,085 ms
コンパイル使用メモリ 74,544 KB
実行使用メモリ 97,304 KB
最終ジャッジ日時 2023-07-25 15:43:06
合計ジャッジ時間 20,836 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 698 ms
73,312 KB
testcase_01 AC 1,108 ms
94,712 KB
testcase_02 AC 1,140 ms
97,304 KB
testcase_03 AC 1,122 ms
96,568 KB
testcase_04 AC 1,100 ms
96,664 KB
testcase_05 AC 1,067 ms
96,876 KB
testcase_06 AC 634 ms
83,704 KB
testcase_07 AC 545 ms
77,232 KB
testcase_08 AC 908 ms
90,612 KB
testcase_09 AC 915 ms
90,644 KB
testcase_10 AC 759 ms
88,524 KB
testcase_11 AC 787 ms
89,764 KB
testcase_12 AC 888 ms
92,896 KB
testcase_13 AC 747 ms
79,736 KB
testcase_14 AC 465 ms
71,452 KB
testcase_15 AC 712 ms
83,272 KB
testcase_16 AC 123 ms
61,600 KB
testcase_17 AC 123 ms
54,264 KB
testcase_18 AC 124 ms
54,116 KB
testcase_19 AC 123 ms
54,172 KB
testcase_20 AC 124 ms
54,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static SegmentTree seg;
    static void update(int x,long d){
        seg.update(x,new long[]{Math.max(d,0),d});
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int[]t=sc.nextIntArray(n-1);
        long[]ct=new long[n],dt=new long[n-1];
        for(int i=0;i<n-1;++i)ct[i+1]=t[i]+3*(n-i-1);
        for(int i=0;i<n-1;++i)dt[i]=ct[i+1]-ct[i];
        int m=sc.nextInt();
        seg=new SegmentTree();
        for(int i=0;i<n-1;++i)update(i,dt[i]);
        for(int i=0;i<m;++i){
            int l=sc.nextInt();
            int r=sc.nextInt();
            long d=sc.nextInt();
            dt[l-1]+=d;
            update(l-1,dt[l-1]);
            if(r<n-1){
                dt[r]-=d;
                update(r,dt[r]);
            }
            long[]res=seg.query(0,n-1);
            out.println(res[0]);
        }
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
class SegmentTree {
    static final int SIZE = 1 << 18;
    long[][] seg;
    SegmentTree() {
	this.seg = new long[2 * SIZE][2];
    }
    static long[]comb(long[] a,long[] b){
        long dif=a[1]+b[1];
        long max=Math.max(a[0],a[1]+b[0]);
        return new long[]{max,dif};
    }
    void update(int x, long[] value) {
	x += SIZE - 1;
        for(int i=0;i<2;++i)
            seg[x][i]=value[i];
	while (x > 0) {
	    x = (x - 1) / 2;
	    this.seg[x] = comb(this.seg[2 * x + 1], this.seg[2 * x + 2]);
	}
    }
    long[] query(int a,int b,int l,int r,int k){
        if(a<=l&&r<=b)return seg[k];
        if(b<=l||r<=a)
            return new long[]{0,0};
        return comb(query(a,b,l,(l+r)/2,2*k+1),query(a,b,(l+r)/2,r,2*k+2));
    }
    long[] query(int l, int r) {
        return query(l,r,0,SIZE,0);
    }
}
0