結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
51,696 KB
testcase_01 AC 47 ms
51,552 KB
testcase_02 AC 48 ms
51,544 KB
testcase_03 AC 50 ms
51,692 KB
testcase_04 AC 92 ms
53,828 KB
testcase_05 AC 104 ms
53,768 KB
testcase_06 AC 52 ms
51,600 KB
testcase_07 AC 62 ms
52,504 KB
testcase_08 AC 75 ms
53,608 KB
testcase_09 AC 87 ms
54,100 KB
testcase_10 AC 91 ms
54,104 KB
testcase_11 AC 80 ms
53,856 KB
testcase_12 AC 81 ms
53,856 KB
testcase_13 AC 102 ms
53,880 KB
testcase_14 AC 80 ms
53,572 KB
testcase_15 AC 101 ms
53,700 KB
testcase_16 AC 106 ms
53,836 KB
testcase_17 AC 90 ms
52,840 KB
testcase_18 AC 132 ms
52,492 KB
testcase_19 AC 749 ms
69,732 KB
testcase_20 AC 813 ms
69,500 KB
testcase_21 AC 778 ms
69,356 KB
testcase_22 AC 728 ms
67,716 KB
testcase_23 AC 716 ms
68,448 KB
testcase_24 AC 681 ms
68,664 KB
testcase_25 AC 677 ms
69,472 KB
testcase_26 AC 690 ms
69,760 KB
testcase_27 AC 709 ms
69,856 KB
testcase_28 AC 679 ms
69,724 KB
testcase_29 AC 675 ms
69,756 KB
testcase_30 AC 792 ms
69,360 KB
testcase_31 AC 824 ms
70,020 KB
testcase_32 AC 753 ms
68,964 KB
testcase_33 AC 793 ms
69,932 KB
testcase_34 WA -
testcase_35 AC 802 ms
79,776 KB
testcase_36 AC 451 ms
62,976 KB
testcase_37 AC 794 ms
68,852 KB
testcase_38 AC 47 ms
51,648 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;
            while(fl-ps>1){
                int y=(ps+fl)/2;
                if(st.query(y,p2)>=(y>0?c[y-1]+1:-1L<<45)+b)
                    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.max(0,Math.min(st.query(ps,p2),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