結果
| 問題 | No.618 labo-index | 
| コンテスト | |
| ユーザー |  Kutimoti_T | 
| 提出日時 | 2018-06-24 09:57:39 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,964 bytes | 
| コンパイル時間 | 2,179 ms | 
| コンパイル使用メモリ | 171,372 KB | 
| 実行使用メモリ | 9,596 KB | 
| 最終ジャッジ日時 | 2024-06-30 22:18:58 | 
| 合計ジャッジ時間 | 8,946 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 4 | 
| other | AC * 2 WA * 33 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
/* include file*/
#include <functional>
#include <vector>
using namespace std;
int Q;
vector<i64> T,X;
vector<i64> Xs;
int ZERO = 0;
template <class Monoid>
struct Segment {
  using Func = function<Monoid(Monoid, Monoid)>;
  vector<Monoid> node;
  Monoid ide;
  int n = 1;
  Func bin_f;
  Func update_f;
  Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
      : bin_f(f_), ide(ide_), update_f(u_f) {
    int sz = init.size();
    while (n < sz) n *= 2;
    node.assign(n * 2 - 1, ide);
    for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
  }
  void update(int i, Monoid x) {
    i += n - 1;
    node[i] = update_f(node[i], x);
    while (i) {
      i = (i - 1) / 2;
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }
  Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (a <= l && r <= b) return node[k];
    if (r <= a || b <= l) return ide;
    Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
    Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
    return bin_f(lm, rm);
  }
  i64 lower_bound(i64 BASE,i64 sum = 0,int k = 0,int l = 0,int r = -1){
    if(r < 0) r = n;
    if(l + 1 == r){
      if(r == n) return max(0LL,Xs[l] + BASE);
      // cout << "l" << l << endl;
      // cout << "Xs" << Xs[l] + BASE << endl;
      // cout << Xs[r] + BASE << endl;
      // cout << "node" << node[k] << endl;
      // cout << "sum" << sum << endl;
      if(Xs[l] + BASE <= 0){
        return sum;
      }
      return max(Xs[l] + BASE ,node[k] + sum);
    }
    if(Xs[(l + r) / 2] + BASE <= node[k * 2 + 2] + sum){
      return lower_bound(BASE,sum, k * 2 + 2,(l + r) / 2,r);
    }
    else{
      return lower_bound(BASE, sum + node[k * 2 + 2],k * 2 + 1,l,(l + r) / 2);
    }
  }
};
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1
int main(){
  cin >> Q;
  T.resize(Q);
  X.resize(Q);
  Xs.push_back(0);
  rep(i,0,Q - 1){
    cin >> T[i] >> X[i];
    if(T[i] == 1)
    Xs.push_back(X[i]);
  }
  sort(Xs.begin(),Xs.end());
  Xs.erase(unique(Xs.begin(), Xs.end()),Xs.end());
  rep(i,0,Q - 1){
    if(T[i] == 1)
      X[i] = lower_bound(Xs.begin(), Xs.end(), X[i]) - Xs.begin();
  }
  ZERO = lower_bound(Xs.begin(), Xs.end(), 0) - Xs.begin();
  vector<i64> R;
  Segment<i64> seg(vector<i64>(Xs.size(),0),0,[](i64 a,i64 b){
    return a + b;
  },[](i64 a,i64 b){
    return a + b;
  });
  i64 BASE = 0;
  rep(i,0,Q - 1){
    if(T[i] == 1){
      seg.update(X[i], 1);
      R.push_back(X[i]);
    }
    if(T[i] == 2){
      seg.update(R[X[i] - 1],-1);
    }
    if(T[i] == 3){
      BASE += X[i];
    }
    cout << seg.lower_bound(BASE) << endl;
  }
}
            
            
            
        