結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,392 KB
testcase_01 AC 4 ms
7,204 KB
testcase_02 AC 4 ms
7,272 KB
testcase_03 AC 4 ms
7,232 KB
testcase_04 AC 6 ms
7,336 KB
testcase_05 AC 6 ms
7,348 KB
testcase_06 AC 4 ms
7,268 KB
testcase_07 AC 5 ms
7,324 KB
testcase_08 AC 5 ms
7,280 KB
testcase_09 AC 6 ms
7,308 KB
testcase_10 AC 6 ms
7,268 KB
testcase_11 AC 5 ms
7,308 KB
testcase_12 AC 5 ms
7,268 KB
testcase_13 AC 6 ms
7,260 KB
testcase_14 AC 6 ms
7,392 KB
testcase_15 AC 6 ms
7,312 KB
testcase_16 AC 6 ms
7,244 KB
testcase_17 AC 6 ms
7,328 KB
testcase_18 AC 8 ms
7,316 KB
testcase_19 AC 248 ms
13,024 KB
testcase_20 AC 316 ms
13,132 KB
testcase_21 AC 261 ms
13,084 KB
testcase_22 AC 277 ms
13,068 KB
testcase_23 AC 284 ms
13,004 KB
testcase_24 AC 263 ms
13,064 KB
testcase_25 AC 294 ms
13,064 KB
testcase_26 AC 291 ms
13,024 KB
testcase_27 WA -
testcase_28 AC 242 ms
12,992 KB
testcase_29 AC 279 ms
13,108 KB
testcase_30 AC 253 ms
13,000 KB
testcase_31 AC 275 ms
13,132 KB
testcase_32 AC 297 ms
12,932 KB
testcase_33 AC 279 ms
12,936 KB
testcase_34 AC 680 ms
21,092 KB
testcase_35 AC 787 ms
21,376 KB
testcase_36 AC 180 ms
9,764 KB
testcase_37 AC 480 ms
14,780 KB
testcase_38 AC 4 ms
7,332 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++;
            }
        }
    }

    {
        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