結果

問題 No.618 labo-index
ユーザー Sebastian KingSebastian King
提出日時 2017-12-18 03:22:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,286 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 168,300 KB
実行使用メモリ 17,024 KB
最終ジャッジ日時 2024-05-09 11:17:12
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 171 ms
17,024 KB
testcase_35 AC 173 ms
16,896 KB
testcase_36 WA -
testcase_37 AC 110 ms
10,752 KB
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve(int)’:
main.cpp:69:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |         scanf("%d", &Q);
      |         ~~~~~^~~~~~~~~~
main.cpp:74:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |                 scanf("%d%d", &ty[i], &tx[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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;
}

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;
			f[i] = 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] + 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 = N + 1;
			while (L + 1 < R){
				int Mid = (L + R) / 2;
				if (test(Mid))
					L = Mid;
				else
					R = Mid;
			}
			ans = L;
		}
		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