結果

問題 No.618 labo-index
ユーザー WA_TLEWA_TLE
提出日時 2017-12-18 00:49:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 697 ms / 6,000 ms
コード長 2,619 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 132,096 KB
実行使用メモリ 148,532 KB
最終ジャッジ日時 2023-08-22 05:14:20
合計ジャッジ時間 14,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 7 ms
5,012 KB
testcase_05 AC 9 ms
5,268 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 6 ms
4,692 KB
testcase_10 AC 8 ms
5,044 KB
testcase_11 AC 5 ms
4,384 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 6 ms
4,840 KB
testcase_14 AC 5 ms
4,404 KB
testcase_15 AC 8 ms
4,964 KB
testcase_16 AC 8 ms
5,280 KB
testcase_17 AC 5 ms
4,384 KB
testcase_18 AC 13 ms
6,556 KB
testcase_19 AC 555 ms
144,020 KB
testcase_20 AC 568 ms
142,340 KB
testcase_21 AC 552 ms
140,280 KB
testcase_22 AC 562 ms
138,904 KB
testcase_23 AC 558 ms
142,176 KB
testcase_24 AC 552 ms
141,764 KB
testcase_25 AC 557 ms
141,644 KB
testcase_26 AC 557 ms
140,208 KB
testcase_27 AC 570 ms
135,196 KB
testcase_28 AC 556 ms
144,532 KB
testcase_29 AC 552 ms
143,080 KB
testcase_30 AC 556 ms
138,836 KB
testcase_31 AC 568 ms
138,052 KB
testcase_32 AC 563 ms
143,148 KB
testcase_33 AC 563 ms
144,024 KB
testcase_34 AC 697 ms
148,532 KB
testcase_35 AC 315 ms
18,020 KB
testcase_36 AC 241 ms
12,996 KB
testcase_37 AC 545 ms
80,780 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
template <typename T=llint,typename index=llint>
class seg_1D{
public:
	T treeval;//人数
	index seghi,segmg;
	seg_1D *left;
	seg_1D *right;
	seg_1D(index hi,index mg){
		treeval=0;
		seghi=hi;segmg=mg;
		left=nullptr;right=nullptr;
	}
	~seg_1D(){delete left;delete right;}
	void make_left(index naka){if(left==nullptr){this->left=new seg_1D(seghi,naka);}}
	void make_right(index naka){if(right==nullptr){this->right=new seg_1D(naka,segmg);}}
	void seg_add(index x,T val){
		treeval+=val;
		if(segmg-seghi==1){return;}
		//人数を増やす
		index chu=(segmg+seghi)/2;
		if(segmg+seghi<0){chu=-((-segmg-seghi+1)/2);}
		make_left(chu);
		make_right(chu);
		if(x<left->segmg){left->seg_add(x,val);}
		else{right->seg_add(x,val);}
	}
	llint ask_que(T nin){//なりたたない限界
		//ninはそれより上のランクの研究者
		index chu=(segmg+seghi)/2;
		if(segmg+seghi<0){chu=-((-segmg-seghi+1)/2);}
		make_left(chu);
		make_right(chu);
		if(segmg-seghi==1){return seghi;}
		if(right->seghi<=right->treeval+nin){return right->ask_que(nin);}
		else{return left->ask_que(nin+right->treeval);}
	}
};
int main(void){
	int q;cin>>q;
	llint allab=0;
	seg_1D<> ki(-big,big);//でかいセグ木をとる
	vector<llint> hito;
	while(q--){
		int t;llint x;cin>>t>>x;
		if(t==1){
			hito.pub(x-allab);
			ki.seg_add(x-allab,1);
		}
		else if(t==2){
			ki.seg_add(hito[x-1],-1);
		}
		else if(t==3){allab+=x;}
		
		cout<<ki.ask_que(-allab)+allab<<endl;
	}
	return 0;
}
0