結果

問題 No.618 labo-index
ユーザー WA_TLEWA_TLE
提出日時 2017-12-18 00:46:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,617 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 132,392 KB
実行使用メモリ 148,680 KB
最終ジャッジ日時 2023-08-22 05:13:26
合計ジャッジ時間 14,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 689 ms
148,680 KB
testcase_35 AC 326 ms
18,148 KB
testcase_36 AC 248 ms
12,744 KB
testcase_37 AC 533 ms
80,592 KB
testcase_38 AC 1 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=int,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