Submission #1678786


Source Code Expand

#include <algorithm>
#include <vector>

template <typename T>
struct BIT {
  using value_type = T;
  using Index1 = int;
  std::vector<value_type> A;
  const int N, N2;
  BIT(int N) : A(N + 1, 0), N(N), N2(1 << std::__lg(N)) {}
  void add(Index1 a, value_type w) {
    for (Index1 x = a; x <= N; x += x & -x) {
      A[x] += w;
    }
  }
  value_type sum(Index1 a) const {
    value_type ret = 0;
    for (Index1 x = a; x > 0; x -= x & -x) {
      ret += A[x];
    }
    return ret;
  }
  Index1 lower_bound(value_type w) const {
    if (w <= 0) return 0;
    Index1 x = 0;
    for (int k = N2; k > 0; k >>= 1) {
      if (x + k <= N && A[x + k] < w) {
        w -= A[x + k];
        x += k;
      }
    }
    return x + 1;
  }
};
#include <cstdio>
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
template<typename T=int>inline T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
template<typename T=int>inline void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}

int main() {
  BIT<int> bit(200000);

  int Q = rd();
  for (int i = 0; i < Q; i++) {
    int t = rd(), x = rd();
    if (t == 1) {
      bit.add(x, 1);
    } else {
      int idx = bit.lower_bound(x);
      wr(idx);
      bit.add(idx, -1);
    }
  }
  return 0;
}

Submission Info

Submission Time
Task C - データ構造
User orisano
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1519 Byte
Status AC
Exec Time 28 ms
Memory 1664 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 1024 KB
sample_02.txt AC 1 ms 1024 KB
subtask1_01.txt AC 1 ms 1024 KB
subtask1_02.txt AC 1 ms 1024 KB
subtask1_03.txt AC 1 ms 1024 KB
subtask1_04.txt AC 3 ms 1024 KB
subtask1_05.txt AC 6 ms 1152 KB
subtask1_06.txt AC 2 ms 1024 KB
subtask1_07.txt AC 13 ms 1152 KB
subtask1_08.txt AC 28 ms 1664 KB
subtask1_09.txt AC 28 ms 1664 KB
subtask1_10.txt AC 20 ms 1280 KB
subtask1_11.txt AC 20 ms 1280 KB
subtask1_12.txt AC 10 ms 1024 KB
subtask1_13.txt AC 28 ms 1664 KB
subtask1_14.txt AC 28 ms 1664 KB
subtask1_15.txt AC 15 ms 1664 KB
subtask1_16.txt AC 15 ms 1408 KB