結果

問題 No.618 labo-index
ユーザー chocoruskchocorusk
提出日時 2019-09-06 16:50:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 6,000 ms
コード長 1,868 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 106,704 KB
実行使用メモリ 6,164 KB
最終ジャッジ日時 2023-09-06 05:59:25
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 57 ms
5,288 KB
testcase_20 AC 68 ms
5,088 KB
testcase_21 AC 64 ms
5,088 KB
testcase_22 AC 65 ms
5,276 KB
testcase_23 AC 61 ms
5,164 KB
testcase_24 AC 61 ms
5,132 KB
testcase_25 AC 64 ms
5,252 KB
testcase_26 AC 66 ms
5,280 KB
testcase_27 AC 66 ms
5,212 KB
testcase_28 AC 61 ms
5,156 KB
testcase_29 AC 61 ms
5,268 KB
testcase_30 AC 60 ms
5,172 KB
testcase_31 AC 63 ms
5,156 KB
testcase_32 AC 63 ms
5,192 KB
testcase_33 AC 63 ms
5,152 KB
testcase_34 AC 89 ms
6,164 KB
testcase_35 AC 154 ms
6,136 KB
testcase_36 AC 33 ms
4,996 KB
testcase_37 AC 67 ms
5,204 KB
testcase_38 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
template<typename T>
struct BIT{ //1-indexed
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
	int q; scanf("%d", &q);
	int t[100010];
	ll x[100010];
	vector<ll> v, vs;
	ll s=0;
	for(int i=0; i<q; i++){
		scanf("%d %lld", &t[i], &x[i]);
		if(t[i]==1){
			x[i]-=s;
			v.push_back(x[i]);
			vs.push_back(x[i]);
		}else if(t[i]==2){
			x[i]--;
		}else{
			s+=x[i];
		}
	}
	if(v.empty()){
		for(int i=0; i<q; i++) printf("0\n");
		return 0;
	}
	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()), vs.end());
	int m=vs.size();
	BIT<int> b(m);
	int cnt=0;
	s=0;
	for(int i=0; i<q; i++){
		if(t[i]==1){
			int k=lower_bound(vs.begin(), vs.end(), x[i])-vs.begin();
			b.add(k+1, 1);
			cnt++;
		}else if(t[i]==2){
			int k=lower_bound(vs.begin(), vs.end(), v[x[i]])-vs.begin();
			b.add(k+1, -1);
			cnt--;
		}else{
			s+=x[i];
		}
		if(cnt==0){
			printf("0\n");
			continue;
		}
		int l=0, r=cnt+1;
		while(r-l>1){
			int mid=(l+r)/2;
			int k=lower_bound(vs.begin(), vs.end(), mid-s)-vs.begin();
			if(cnt-b.sum(k)>=mid) l=mid;
			else r=mid;
		}
		printf("%d\n", l);
	}
	return 0;
}
0