結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
51,672 KB
testcase_01 AC 44 ms
51,644 KB
testcase_02 AC 45 ms
51,756 KB
testcase_03 AC 45 ms
51,668 KB
testcase_04 AC 88 ms
54,388 KB
testcase_05 AC 97 ms
53,916 KB
testcase_06 AC 48 ms
51,624 KB
testcase_07 AC 59 ms
52,572 KB
testcase_08 AC 61 ms
52,532 KB
testcase_09 AC 90 ms
53,692 KB
testcase_10 AC 89 ms
54,316 KB
testcase_11 AC 82 ms
51,800 KB
testcase_12 AC 84 ms
52,684 KB
testcase_13 AC 96 ms
54,176 KB
testcase_14 AC 85 ms
52,808 KB
testcase_15 AC 97 ms
54,028 KB
testcase_16 AC 95 ms
53,592 KB
testcase_17 AC 81 ms
54,652 KB
testcase_18 AC 119 ms
54,616 KB
testcase_19 AC 716 ms
68,304 KB
testcase_20 AC 756 ms
70,088 KB
testcase_21 AC 743 ms
67,936 KB
testcase_22 AC 712 ms
68,864 KB
testcase_23 AC 689 ms
68,716 KB
testcase_24 AC 643 ms
68,528 KB
testcase_25 AC 648 ms
69,004 KB
testcase_26 AC 677 ms
68,632 KB
testcase_27 AC 648 ms
69,840 KB
testcase_28 AC 643 ms
68,460 KB
testcase_29 AC 681 ms
68,808 KB
testcase_30 AC 717 ms
69,252 KB
testcase_31 AC 721 ms
69,564 KB
testcase_32 AC 760 ms
67,392 KB
testcase_33 AC 714 ms
69,504 KB
testcase_34 WA -
testcase_35 AC 819 ms
78,280 KB
testcase_36 AC 424 ms
62,860 KB
testcase_37 AC 779 ms
68,876 KB
testcase_38 AC 44 ms
51,560 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<<45))
                    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