結果

問題 No.618 labo-index
ユーザー sekiya9311sekiya9311
提出日時 2017-12-20 01:05:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,184 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 185,496 KB
実行使用メモリ 21,184 KB
最終ジャッジ日時 2023-08-22 07:25:33
合計ジャッジ時間 10,744 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,228 KB
testcase_01 AC 4 ms
7,316 KB
testcase_02 AC 5 ms
7,228 KB
testcase_03 AC 4 ms
7,256 KB
testcase_04 AC 6 ms
7,340 KB
testcase_05 AC 6 ms
7,288 KB
testcase_06 AC 5 ms
7,344 KB
testcase_07 AC 5 ms
7,236 KB
testcase_08 AC 5 ms
7,364 KB
testcase_09 AC 6 ms
7,256 KB
testcase_10 AC 7 ms
7,208 KB
testcase_11 AC 5 ms
7,204 KB
testcase_12 AC 5 ms
7,296 KB
testcase_13 AC 6 ms
7,396 KB
testcase_14 AC 6 ms
7,268 KB
testcase_15 AC 6 ms
7,280 KB
testcase_16 AC 7 ms
7,316 KB
testcase_17 AC 5 ms
7,320 KB
testcase_18 AC 7 ms
7,344 KB
testcase_19 AC 245 ms
13,232 KB
testcase_20 WA -
testcase_21 AC 259 ms
13,140 KB
testcase_22 AC 274 ms
12,992 KB
testcase_23 AC 283 ms
12,992 KB
testcase_24 WA -
testcase_25 AC 296 ms
13,076 KB
testcase_26 AC 290 ms
13,072 KB
testcase_27 AC 290 ms
13,120 KB
testcase_28 WA -
testcase_29 AC 276 ms
13,084 KB
testcase_30 AC 253 ms
13,024 KB
testcase_31 AC 274 ms
13,076 KB
testcase_32 AC 295 ms
12,968 KB
testcase_33 AC 272 ms
13,020 KB
testcase_34 AC 677 ms
21,028 KB
testcase_35 AC 791 ms
21,184 KB
testcase_36 AC 276 ms
9,860 KB
testcase_37 AC 491 ms
14,820 KB
testcase_38 AC 5 ms
7,220 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);
                if (raq.query(itr->second, MAX) >= mid) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            printf("%lld\n", low);
        }
    }

    return 0;
}
0