結果

問題 No.618 labo-index
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-11-29 18:19:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,800 bytes
コンパイル時間 3,017 ms
コンパイル使用メモリ 75,056 KB
実行使用メモリ 79,744 KB
最終ジャッジ日時 2023-08-18 13:41:41
合計ジャッジ時間 19,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,944 KB
testcase_01 AC 44 ms
51,680 KB
testcase_02 AC 44 ms
51,712 KB
testcase_03 AC 45 ms
51,720 KB
testcase_04 AC 97 ms
53,808 KB
testcase_05 AC 105 ms
54,388 KB
testcase_06 AC 48 ms
51,556 KB
testcase_07 AC 58 ms
52,656 KB
testcase_08 AC 67 ms
52,544 KB
testcase_09 AC 78 ms
54,188 KB
testcase_10 AC 97 ms
53,848 KB
testcase_11 AC 80 ms
53,600 KB
testcase_12 AC 82 ms
53,576 KB
testcase_13 AC 85 ms
53,828 KB
testcase_14 AC 76 ms
52,976 KB
testcase_15 AC 96 ms
54,256 KB
testcase_16 AC 99 ms
54,144 KB
testcase_17 AC 81 ms
53,484 KB
testcase_18 AC 115 ms
54,836 KB
testcase_19 AC 704 ms
67,896 KB
testcase_20 AC 727 ms
69,496 KB
testcase_21 AC 713 ms
68,004 KB
testcase_22 AC 673 ms
68,540 KB
testcase_23 AC 667 ms
69,080 KB
testcase_24 AC 750 ms
69,748 KB
testcase_25 AC 647 ms
68,360 KB
testcase_26 AC 671 ms
69,164 KB
testcase_27 AC 692 ms
70,216 KB
testcase_28 AC 645 ms
69,864 KB
testcase_29 AC 635 ms
68,500 KB
testcase_30 AC 750 ms
68,860 KB
testcase_31 AC 733 ms
69,476 KB
testcase_32 AC 731 ms
69,884 KB
testcase_33 AC 717 ms
69,868 KB
testcase_34 WA -
testcase_35 AC 817 ms
79,744 KB
testcase_36 AC 400 ms
62,860 KB
testcase_37 AC 816 ms
68,760 KB
testcase_38 AC 45 ms
51,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


class Main {
    static int q;
    static int[]t;
    static long[]x;
    Main(){
        long b=0;
        long[]c=new long[q];
        int p=0;
        for(int i=0;i<q;++i)
            if(t[i]==1){
                c[p++]=x[i]-b;
                x[i]-=b;
            }
            else if(t[i]==3)
                b+=x[i];
            else
                x[i]=c[(int)x[i]-1];
        Arrays.sort(c,0,p);
        int p2=0;
        Map<Long,Integer>hm=new HashMap<Long,Integer>();
        for(int i=0;i<p;++i)
            if(i>0&&c[i]==c[i-1]);
            else hm.put(c[i],p2++);
        PlusSegmentTree st=new PlusSegmentTree();
        b=0;
        for(int i=0;i<q;++i){
            if(t[i]==1){
                int j=hm.get(x[i]);
                st.update(j,st.query(j,j+1)+1);
            }else if(t[i]==2){
                int j=hm.get(x[i]);
                st.update(j,st.query(j,j+1)-1);
            }else
                b+=x[i];
            int ps=0,fl=p2+1;
            while(fl-ps>1){
                int y=(ps+fl)/2;
                if(st.query(y,p2)>=(y>0?c[y-1]+1+b:-1L<<50))
                    ps=y;
                else
                    fl=y;
            }
            if(false){
                out.println("b="+b);
                out.print("st:");
                for(int j=0;j<p2;++j){
                    out.print(" "+st.query(j,j+1));
                }
                out.println();
                out.println("ps="+ps);
            }
            out.println(Math.min(st.query(ps,p2),ps==p2?Long.MAX_VALUE:c[ps]+b));
        }
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        q=sc.nextInt();
        t=new int[q];
        x=new long[q];
        for(int i=0;i<q;++i){
            t[i]=sc.nextInt();
            x[i]=sc.nextLong();
        }
        new Main();
        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;
        }
    }
}
class PlusSegmentTree {
    static final int SIZE = 1 << 17;
    long[] seg;
    PlusSegmentTree() {
	this.seg = new long[2 * SIZE];
    }
    void update(int x, long value) {
	x += SIZE - 1;
	this.seg[x] = value;
	while (x > 0) {
	    x = (x - 1) / 2;
	    this.seg[x] = this.seg[2 * x + 1] + this.seg[2 * x + 2];
	}
    }
    long query(int l, int r) {
	l += SIZE - 1;
	r += SIZE - 1;
        long y = 0;
	while (l < r) {
	    if ((l & 1) == 0) {
		y += this.seg[l];
	    }
	    if ((r & 1) == 0) {
		y += this.seg[r - 1];
	    }
	    l /= 2;
	    r = (r - 1) / 2;
	}
	return y;
    }
}
0