結果

問題 No.618 labo-index
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-24 11:00:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 513 ms / 6,000 ms
コード長 2,589 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 165,688 KB
実行使用メモリ 9,320 KB
最終ジャッジ日時 2023-09-13 13:32:41
合計ジャッジ時間 12,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 435 ms
6,716 KB
testcase_20 AC 435 ms
6,676 KB
testcase_21 AC 441 ms
6,724 KB
testcase_22 AC 438 ms
6,732 KB
testcase_23 AC 438 ms
6,820 KB
testcase_24 AC 437 ms
6,776 KB
testcase_25 AC 442 ms
6,788 KB
testcase_26 AC 435 ms
6,684 KB
testcase_27 AC 439 ms
6,604 KB
testcase_28 AC 450 ms
6,720 KB
testcase_29 AC 444 ms
6,780 KB
testcase_30 AC 432 ms
6,720 KB
testcase_31 AC 443 ms
6,668 KB
testcase_32 AC 431 ms
6,720 KB
testcase_33 AC 443 ms
6,604 KB
testcase_34 AC 513 ms
9,320 KB
testcase_35 AC 477 ms
9,220 KB
testcase_36 AC 195 ms
5,576 KB
testcase_37 AC 341 ms
6,736 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

// 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);
  i64 SUM = 0;
  rep(i,0,Q - 1){
    cin >> T[i] >> X[i];
    if(T[i] == 3){
      SUM += X[i];
    }
    if(T[i] == 1)
    {
      X[i] -= SUM;
      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();
  }

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

    int l = 0;
    int r = Q + 1;
    while(r - l > 1){
      int mid = (l + r) / 2;
      int idx = ::lower_bound(Xs.begin(),Xs.end(),mid - BASE) - Xs.begin();
      if(idx == Xs.size()){
        r = mid;
        continue;
      }
      if(mid <= seg.get_inter(idx,seg.n)){
        l = mid;
      }
      else{
        r = mid;
      }
    } 
    cout << l << endl;
  }

}
0