結果

問題 No.618 labo-index
ユーザー FF256grhyFF256grhy
提出日時 2017-12-18 13:06:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,188 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 174,212 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2023-08-22 05:24:04
合計ジャッジ時間 9,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 362 ms
16,184 KB
testcase_35 AC 353 ms
16,256 KB
testcase_36 AC 300 ms
12,792 KB
testcase_37 AC 328 ms
12,548 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> class SegTree {
private:
	T * a = NULL;
	int M, S;
	T (*F)(T, T);
	T I;

public:
	// [0, size) が使用可能になる、func が演算、id は単位元
	void init(int size, T (*func)(T, T), T id) {
		assert(size > 0);
		M = size;
		F = func;
		I = id;
		S = 1;
		while(S < size) { S *= 2; }
		delete[] a;
		a = new T[S * 2];
		inc(i, S * 2) { a[i] = I; }
	}
	
	// 参照(値を変更した後は calc() を呼ぶこと)
	T & operator[](int p) {
		assert(inID(p, 0, M));
		p += S;
		return a[p];
	}
	
	// テーブルの再計算
	void calc() {
		decID(i, 1, S) {
			a[i] = F(a[i * 2], a[i * 2 + 1]);
		}
	}
	
	// a[p] を v に変更し再計算
	void update(int p, T v) {
		assert(inID(p, 0, M));
		p += S;
		a[p] = v;
		while(p != 1) {
			p /= 2;
			a[p] = F(a[p * 2], a[p * 2 + 1]);
		}
	}
	
	// [l, r) に f を適用した結果を返す
	T range(int l, int r) {
		assert(inII(l, 0, M));
		assert(inII(r, 0, M));
		// if(l > r) { return F(range(l, M), range(0, r)); }
		assert(l <= r);
		l += S;
		r += S;
		
		T v = I, w = I;
		while(l < r) {
			if(l + 1 == r) { v = F(v, a[l]); break; }
			
			if(l % 2 == 1) { v = F(v, a[l]); }
			if(r % 2 == 1) { w = F(a[r - 1], w); }
			
			l = (l + 1) / 2;
			r = r / 2;
		}
		
		return F(v, w);
	}
};

template<typename T> T  MIN(T x, T y) { return min(x, y); }
template<typename T> T  MAX(T x, T y) { return max(x, y); }
template<typename T> T  add(T x, T y) { return x + y; }
template<typename T> T prod(T x, T y) { return x * y; }

// ---- ---- ---- ----

LL q, t[100000], x[100000], os, rk[100000], INF = 1e15;
set<pair<LL, int>> s;
vector<int> rm;
SegTree<LL> c, m;

bool f(int z) {
	LL n = c.range(z, q);
	LL v = m.range(z, q) - os;
	return (n <= v);
}

int main() {
	cin >> q;
	inc(i, q) { cin >> t[i] >> x[i]; }
	
	inc(i, q) {
		if(t[i] == 1) { s.emplace(x[i] - os, i); rm.PB(i); }
		if(t[i] == 3) { os -= x[i]; }
	}
	int cnt = 0;
	FOR(it, s) { rk[it -> SE] = cnt++; }
	
	c.init(q, add,   0);
	m.init(q, MIN, INF);
	os = 0;
	inc(i, q) {
		if(t[i] == 1) {
			c.update(rk[i], c[rk[i]] + 1);
			m.update(rk[i], x[i] + os);
		}
		if(t[i] == 2) {
			x[i]--;
			c.update(rk[rm[x[i]]], c[rk[rm[x[i]]]] - 1);
			m.update(rk[rm[x[i]]], INF);
		}
		if(t[i] == 3) { os -= x[i]; }
		
		/*
		cout << " [ ";
		inc(j, q) {
			if(c[j] == 0) { printf("... "); } else { printf("%3lld ", m[j] - os); }
		}
		cout << "]\n";
		*/
		
		int l = -1, h = q;
		while(h - l > 1) {
			int md = (l + h) / 2;
			(f(md) ? h : l) = md;
		}
		cout << c.range(h, q) << "\n";
		
		/*
		int ok = q + 1;
		dec(i, q + 1) { if(f(i)) { ok = i; } else { break; } }
		cout << c.range(ok, q) << "\n";
		*/
	}
	
	return 0;
}
0