結果

問題 No.618 labo-index
ユーザー sekiya9311sekiya9311
提出日時 2017-12-20 01:15:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 822 ms / 6,000 ms
コード長 4,253 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 185,788 KB
実行使用メモリ 21,096 KB
最終ジャッジ日時 2023-08-22 07:28:48
合計ジャッジ時間 10,660 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,244 KB
testcase_01 AC 5 ms
7,300 KB
testcase_02 AC 5 ms
7,296 KB
testcase_03 AC 5 ms
7,236 KB
testcase_04 AC 5 ms
7,344 KB
testcase_05 AC 6 ms
7,180 KB
testcase_06 AC 5 ms
7,176 KB
testcase_07 AC 5 ms
7,272 KB
testcase_08 AC 6 ms
7,240 KB
testcase_09 AC 6 ms
7,400 KB
testcase_10 AC 6 ms
7,272 KB
testcase_11 AC 5 ms
7,276 KB
testcase_12 AC 5 ms
7,200 KB
testcase_13 AC 6 ms
7,296 KB
testcase_14 AC 6 ms
7,204 KB
testcase_15 AC 6 ms
7,244 KB
testcase_16 AC 6 ms
7,240 KB
testcase_17 AC 6 ms
7,352 KB
testcase_18 AC 8 ms
7,240 KB
testcase_19 AC 252 ms
12,904 KB
testcase_20 AC 320 ms
12,968 KB
testcase_21 AC 260 ms
12,972 KB
testcase_22 AC 283 ms
12,980 KB
testcase_23 AC 287 ms
12,988 KB
testcase_24 AC 261 ms
12,980 KB
testcase_25 AC 303 ms
12,916 KB
testcase_26 AC 295 ms
12,988 KB
testcase_27 AC 289 ms
13,088 KB
testcase_28 AC 248 ms
12,924 KB
testcase_29 AC 291 ms
13,016 KB
testcase_30 AC 257 ms
13,008 KB
testcase_31 AC 282 ms
13,140 KB
testcase_32 AC 303 ms
12,972 KB
testcase_33 AC 282 ms
13,012 KB
testcase_34 AC 694 ms
21,096 KB
testcase_35 AC 822 ms
21,096 KB
testcase_36 AC 231 ms
9,764 KB
testcase_37 AC 502 ms
14,824 KB
testcase_38 AC 4 ms
7,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

// 区間加算,区間参照
// 半開区間!!!
template<typename T = int>
class RangeAddQuery {
private:
     vector<T> data, lazy;
     int sz;
     void push(int k, int l, int r) {
          if (this->lazy[k]) {
               this->data[k] += this->lazy[k] * (r - l);
               if (k * 2 + 2 < sz * 2 - 1) {
                    this->lazy[2 * k + 1] += this->lazy[k];
                    this->lazy[2 * k + 2] += this->lazy[k];
               }
               this->lazy[k] = 0;
          }
     }
     void add(int l, int r, int L, int R, int k, T val) {
           this->push(k, l, r);
          if (L <= l && r <= R) {
               this->lazy[k] += val;
                  this->push(k, l, r);
          } else if (R <= l || r <= L) {
               return;
          } else if (r - l > 1) {
               const int mid = (l + r) / 2;
               this->add(l, mid, L, R, k * 2 + 1, val);
               this->add(mid, r, L, R, k * 2 + 2, val);
                  data[k] = data[k * 2 + 1] + data[k * 2 + 2];
          }
     }
     T query(int l, int r, int L, int R, int k) {
          this->push(k, l, r);
          if (L <= l && r <= R) {
               return data[k];
          } else if (R <= l || r <= L) {
               return 0;
          } else {
               const int mid = (l + r) / 2;
               const T left = this->query(l, mid, L, R, k * 2 + 1);
               const T right = this->query(mid, r, L, R, k * 2 + 2);
               return left + right;
          }
     }
public:
     RangeAddQuery(const int n) {
          this->sz = 1;
          while (this->sz < n) this->sz <<= 1;
          this->data.resize(this->sz * 2 - 1);
          this->lazy.resize(this->sz * 2 - 1);
     }
     void add(int l, int r, T val) {
          this->add(0, this->sz, l, r, 0, val);
     }
     T query(int l, int r) {
          return this->query(0, this->sz, l, r, 0);
     }
};

const int MAX = 1e5 + 10;
int Q;
long long t[MAX], x[MAX], prevX[MAX];
vector<pair<int, long long>> addCntIdx;// addCntIdx[i] = i番目に入ってきたやつのidx, その時点での区間加算値
map<long long, int> comp;
RangeAddQuery<long long> raq(MAX);

int main() {
    scanf("%d", &Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld%lld", t + i, x + i);
    }

    {
        set<long long> se;
        long long range = 0;
        for (int i = 0; i < Q; i++) {
            if (t[i] == 1) {
                // add
                se.insert(x[i] - range);
                addCntIdx.emplace_back(i, range);
            } else if (t[i] == 2) {
                // erase
            } else {
                // up power
                range += x[i];
            }
        }
        {
            int cnt = 0;
            for (long long e : se) {
                comp[e] = cnt++;
            }
            //comp[*max_element(begin(se), end(se))] = cnt + 1;
        }
    }

    {
        long long range = 0;
        int hCnt = 0;
        for (int i = 0; i < Q; i++) {
            if (t[i] == 1) {
                // add
                const int idx = comp[x[i] - range];
                raq.add(idx, idx + 1, 1);
                hCnt++;
            } else if (t[i] == 2) {
                // erase
                const auto idxAndRageAddVal = addCntIdx[x[i] - 1];
                const int idx = addCntIdx[x[i] - 1].first;
                const long long preRange = addCntIdx[x[i] - 1].second;
                const int cmpIdx = comp[x[idx] - preRange];
                raq.add(cmpIdx, cmpIdx + 1, -1);
                hCnt--;
            } else {
                // up power
                range += x[i];
            }

            long long low = 0, high = hCnt + 1;
            while (high - low > 1) {
                const long long mid = low + (high - low) / 2;
                //cerr << mid << endl;
                auto itr = comp.lower_bound(mid - range);
                long long get = itr == comp.end() ? MAX - 1 : itr->second;
                if (raq.query(get, MAX) >= mid) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            printf("%lld\n", low);
        }
    }

    return 0;
}
0