Submission #1511879


Source Code Expand

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct BIT {
  int n;
  vector<int> xs;
  BIT (int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
  int sum(int a, int b) {
    return sum(b) - sum(a-1);
  }
  int kth(int k) {
    int lo = -1, hi = n+1;
    while (hi - lo > 1) {
      int mid = (lo + hi) / 2;
      if (sum(mid) >= k) hi = mid;
      else lo = mid;
    }
    return hi;
  }
};

int Q;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> Q;
  vector<P> qs;
  vector<int> xs;
  rep(i, Q) {
    int t, x;
    cin >> t >> x;
    if (t == 1) xs.pb(x);
    qs.pb(P(t, x));
  }
  sort(all(xs));
  uniq(xs);
  BIT bit(xs.size());

  for (P q : qs) {
    int t = q._1, x = q._2;
    if (t == 1) {
      x = lower_bound(all(xs), x) - xs.begin();
      bit.add(x, 1);
    }
    else {
      int p = bit.kth(x);
      bit.add(p, -1);
      cout << xs[p] << "\n";
    }
  }
  return 0;
}

Submission Info

Submission Time
Task C - データ構造
User funcsr
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1623 Byte
Status AC
Exec Time 89 ms
Memory 3824 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 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 6 ms 512 KB
subtask1_05.txt AC 12 ms 764 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 49 ms 2292 KB
subtask1_08.txt AC 89 ms 3312 KB
subtask1_09.txt AC 89 ms 3312 KB
subtask1_10.txt AC 85 ms 3696 KB
subtask1_11.txt AC 85 ms 3824 KB
subtask1_12.txt AC 73 ms 3432 KB
subtask1_13.txt AC 89 ms 3180 KB
subtask1_14.txt AC 88 ms 3180 KB
subtask1_15.txt AC 66 ms 3180 KB
subtask1_16.txt AC 73 ms 3824 KB