結果

問題 No.618 labo-index
ユーザー 👑 kmjpkmjp
提出日時 2017-12-18 00:33:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 243 ms / 6,000 ms
コード長 1,828 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 169,840 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2024-05-09 11:02:50
合計ジャッジ時間 7,908 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 226 ms
8,144 KB
testcase_20 AC 227 ms
8,016 KB
testcase_21 AC 224 ms
8,016 KB
testcase_22 AC 224 ms
8,148 KB
testcase_23 AC 224 ms
8,020 KB
testcase_24 AC 226 ms
8,016 KB
testcase_25 AC 224 ms
8,020 KB
testcase_26 AC 223 ms
8,020 KB
testcase_27 AC 223 ms
8,148 KB
testcase_28 AC 219 ms
8,016 KB
testcase_29 AC 229 ms
8,148 KB
testcase_30 AC 224 ms
8,140 KB
testcase_31 AC 236 ms
8,016 KB
testcase_32 AC 222 ms
8,136 KB
testcase_33 AC 222 ms
8,144 KB
testcase_34 AC 237 ms
9,512 KB
testcase_35 AC 243 ms
9,644 KB
testcase_36 AC 213 ms
7,204 KB
testcase_37 AC 224 ms
7,268 KB
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

//さらに短縮
template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<ll,20> bt,bt2;

vector<int> V;
int Q;
ll T[101010],X[101010],F[101010],rev[101010];
int O[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>Q;
	ll tadd=0;
	FOR(i,Q) {
		cin>>T[i]>>X[i];
		if(T[i]==1) {
			rev[i]=V.size();
			V.push_back(i);
		}
		else if(T[i]==3) {
			tadd+=X[i];
			bt.add(0,X[i]);
			bt.add(V.size(),-X[i]);
		}
	}
	
	vector<pair<ll,int>> P;
	FOR(i,Q) if(T[i]==1) {
		F[i]=X[i]+bt(rev[i]);
		P.push_back({F[i],i});
	}
	sort(ALL(P));
	FOR(i,P.size()) O[P[i].second]=i;
	
	ll add=0;
	FOR(i,Q) {
		if(T[i]==1) {
			bt2.add(O[i],1);
		}
		else if(T[i]==2) {
			bt2.add(O[V[X[i]-1]],-1);
		}
		else {
			add+=X[i];
		}
		
		ll dif=add-tadd;
		int L=0;
		for(j=20;j>=0;j--) {
			if(L+(1<<j)>V.size()) continue;
			
			ll t=L+(1<<j)-dif;
			x=lower_bound(ALL(P),make_pair(t,0))-P.begin();
			int num=bt2(Q)-(x?bt2(x-1):0);
			if(num>=L+(1<<j)) L+=1<<j;
		}
		cout<<L<<endl;
		
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0