結果

問題 No.618 labo-index
ユーザー azbrugbyazbrugby
提出日時 2019-03-04 17:25:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,701 ms / 6,000 ms
コード長 2,363 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 80,520 KB
実行使用メモリ 7,980 KB
最終ジャッジ日時 2023-09-05 18:28:54
合計ジャッジ時間 23,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 827 ms
6,752 KB
testcase_20 AC 830 ms
6,544 KB
testcase_21 AC 832 ms
6,616 KB
testcase_22 AC 824 ms
6,480 KB
testcase_23 AC 829 ms
6,604 KB
testcase_24 AC 829 ms
6,684 KB
testcase_25 AC 827 ms
6,560 KB
testcase_26 AC 819 ms
6,584 KB
testcase_27 AC 829 ms
6,616 KB
testcase_28 AC 825 ms
6,524 KB
testcase_29 AC 826 ms
6,708 KB
testcase_30 AC 830 ms
6,632 KB
testcase_31 AC 827 ms
6,548 KB
testcase_32 AC 836 ms
6,548 KB
testcase_33 AC 826 ms
6,552 KB
testcase_34 AC 2,701 ms
7,980 KB
testcase_35 AC 2,688 ms
7,924 KB
testcase_36 AC 210 ms
6,032 KB
testcase_37 AC 1,453 ms
7,088 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#define mk make_pair
#define pb push_back
#define printf printf_s
#define scanf scanf_s
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 100001, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;

ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}
ll gcd(ll v1, ll v2) {
	if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}

ll pw(ll v1, ll v2) {
	ll v3 = 1;
	while (v2 > 0) {
		if (v2 % 2)v3 = (v3*v1) % MOD;
		v1 = (v1*v1) % MOD;
		v2 /= 2;
	}
	return v3;
}

struct ab {
	ll a, b;
	bool operator<(const ab& right) const {
		return right.b*a - right.a*b < 0;
	}
};

ll Q,xl[N],ti=1,bt[N];
pos tx[N];

void sxl() {
	ll xl2[N],ti2=ti;
	for (int i1 = 1, i2 = 1; i1 < ti; i1++) {
		if (i1 != 1 && xl[i1] == xl[i1 - 1]) {
			ti2--;
		}
		else {
			xl2[i2] = xl[i1];
			i2++;
		}
	}
	memset(xl, 0, sizeof(xl));
	for (int i = 1; i < ti2; i++)xl[i] = xl2[i];
	ti = ti2;
}

void ad(ll v1, ll v2) {
	while (v1 <= ti - 1) {
		bt[v1] += v2;
		v1 += v1 & -v1;
	}
}

ll sm(ll v1) {
	ll v2 = 0;
	while (v1 > 0) {
		v2 += bt[v1];
		v1 -= v1 & -v1;
	}
	return v2;
}

bool ok(ll tt,ll mdv,ll tot) {
	ll v1 = sm(lower_bound(xl + 1, xl + ti, mdv-tt) - xl - 1);
	return (tot - v1) >= mdv;
}

void src(ll tt,ll tot) {
	ll mnv = 0, mxv = 1000000001;
	while (mxv - mnv > 1) {
		ll md = (mxv + mnv) / 2;
		if (ok(tt,md,tot))mnv = md;
		else mxv = md;
	}
	cout << mnv << endl;
}

int main() {
	cin >> Q;
	for (ll i = 0, tt = 0; i < Q; i++) {
		cin >> tx[i].first >> tx[i].second;
		if (tx[i].first == 3)tt += tx[i].second;
		if (tx[i].first == 1) {
			xl[ti] = tx[i].second - tt;
			ti++;
		}
	}
	sort(xl + 1, xl + ti);
	sxl();
	vector<ll> rsc;
	for (ll i = 0,tt=0,tot=0; i < Q; i++) {
		if (tx[i].first == 1) {
			ll id1 = find(xl + 1, xl + ti, tx[i].second - tt) - xl;
			ad(id1, 1);
			rsc.push_back(tx[i].second - tt);
			tot++;
		}
		if (tx[i].first == 2) {
			ad(find(xl + 1, xl + ti, rsc[tx[i].second - 1]) - xl, -1);
			tot--;
		}
		if (tx[i].first == 3)tt += tx[i].second;
		src(tt,tot);
	}


	return 0;
}
0