結果

問題 No.618 labo-index
ユーザー Sebastian KingSebastian King
提出日時 2017-12-18 15:50:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 165 ms / 6,000 ms
コード長 2,523 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 154,900 KB
実行使用メモリ 25,688 KB
最終ジャッジ日時 2023-08-22 05:28:29
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,752 KB
testcase_01 AC 3 ms
11,808 KB
testcase_02 AC 3 ms
11,672 KB
testcase_03 AC 3 ms
11,712 KB
testcase_04 AC 4 ms
11,768 KB
testcase_05 AC 4 ms
11,780 KB
testcase_06 AC 3 ms
11,872 KB
testcase_07 AC 3 ms
11,712 KB
testcase_08 AC 4 ms
11,768 KB
testcase_09 AC 3 ms
11,892 KB
testcase_10 AC 4 ms
11,712 KB
testcase_11 AC 3 ms
12,036 KB
testcase_12 AC 4 ms
11,700 KB
testcase_13 AC 4 ms
11,784 KB
testcase_14 AC 4 ms
11,764 KB
testcase_15 AC 4 ms
11,776 KB
testcase_16 AC 4 ms
11,788 KB
testcase_17 AC 4 ms
11,760 KB
testcase_18 AC 4 ms
11,956 KB
testcase_19 AC 77 ms
15,332 KB
testcase_20 AC 87 ms
15,396 KB
testcase_21 AC 85 ms
15,392 KB
testcase_22 AC 86 ms
15,312 KB
testcase_23 AC 82 ms
15,456 KB
testcase_24 AC 80 ms
15,388 KB
testcase_25 AC 86 ms
15,516 KB
testcase_26 AC 86 ms
15,384 KB
testcase_27 AC 87 ms
15,376 KB
testcase_28 AC 76 ms
15,316 KB
testcase_29 AC 82 ms
15,456 KB
testcase_30 AC 86 ms
15,396 KB
testcase_31 AC 85 ms
15,460 KB
testcase_32 AC 82 ms
15,360 KB
testcase_33 AC 80 ms
15,604 KB
testcase_34 AC 165 ms
25,688 KB
testcase_35 AC 165 ms
25,628 KB
testcase_36 AC 35 ms
13,796 KB
testcase_37 AC 97 ms
18,664 KB
testcase_38 AC 3 ms
11,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef __int128 ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 5e5 + 10;

int n, m;

void prework(){

}

void read(){

}

ll now;
int N, M;
ll f[MAXN];
int tx[MAXN], ty[MAXN];
int a[MAXN];
ll b[MAXN];

void add(int x){
//	cout << "ADD : " << x << endl;
	for (int i = M - 1 + x; i; i /= 2)
		a[i]++;
}

void del(int x){
//	cout << "DEL : " << x << endl;
	for (int i = M - 1 + x; i; i /= 2)
		a[i]--;
}

bool test(int L){
/*	cout << "TEST : " << L << ' ' << now << endl;
	for (int i = 1; i < 2 * M; i++)
		cout << "[" << i << ',' << a[i] << "] "; cout << endl;
*/	int ret = 0;
	if (b[1] + now >= L){
		return L <= a[1];
	}
	int l = 1, r = M;
	for (int i = 1; l != r; ){
		int m = (l + r) / 2;
//		cout << i << ' ' << l << ' ' << r << ' ' << m << ' ' << b[m + 1] << endl;
		if (b[m + 1] + now >= L){
			ret += a[i * 2 + 1];
			r = m, i = i * 2;
		}
		else{
			l = m + 1;
			i = i * 2 + 1;
		}
	}
	//if (b[l] + now <= L) ret++;
	return ret >= L;
}
/*
int query(){
	if (b[1] + now >= a[1])
		return a[1];
	if (b[N] + now < 1)
		return 0;
	// [1, M]
	for (int u = 1, l = 1, r = M; l != r; ){
		int m = (l + r) / 2;
		// at least (m+1) number is large then or equal to m+1
		// b[]
		if ()
	}
}
*/
void solve(int casi){
//	cout << "Case #" << casi << ": ";
	int Q;
	scanf("%d", &Q);
	map<ll, int> X;
	now = 0;
	int cnt = 0;
	for (int i = 1; i <= Q; i++){
		scanf("%d%d", &ty[i], &tx[i]);
		if (ty[i] == 3){
			now += tx[i];
		}
		if (ty[i] == 1){
			X[tx[i] - now] = 1;
			f[++cnt] = tx[i] - now;
		}
	}
	N = 0;
	for (auto &x : X){
		x.second = ++N;
		b[N] = x.first;
	}
	for (M = 1; M < N; M *= 2);
	for (int i = N + 1; i <= M; i++)
		b[i] = b[N] + Q + 2;
	for (int i = 1; i <= 2 * M; i++)
		a[i] = 0;
	/*
	cout << N << ' ' << M << endl;
	for (int i = 1; i <= M; i++)
		cout << b[i] << ' '; cout << endl;
	*/
	now = 0;
	int ans = 0;
	for (int i = 1; i <= Q; i++){
		if (ty[i] == 1){
			add(X[tx[i] - now]);
			if (test(ans + 1))
				ans++;
		}
		else if (ty[i] == 2){
			del(X[f[tx[i]]]);
			if (!test(ans))
				ans--;
		}
		else {
			now += tx[i];
			int L = 0, R = a[1] + 1;
			while (L + 1 < R){
				int Mid = (L + R) / 2;
				if (test(Mid))
					L = Mid;
				else
					R = Mid;
			}
			ans =L;//query();
		}
		printf("%d\n", ans);
	}
}

void printans(){

}

int main(){
//	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}

0