結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー tnakao0123tnakao0123
提出日時 2024-04-25 16:01:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,500 ms
コード長 2,529 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 67,416 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 16:01:56
合計ジャッジ時間 9,004 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 49 ms
6,940 KB
testcase_03 AC 20 ms
6,940 KB
testcase_04 AC 125 ms
6,940 KB
testcase_05 AC 96 ms
6,940 KB
testcase_06 AC 47 ms
6,940 KB
testcase_07 AC 103 ms
6,944 KB
testcase_08 AC 37 ms
6,944 KB
testcase_09 AC 204 ms
6,944 KB
testcase_10 AC 190 ms
6,940 KB
testcase_11 AC 191 ms
6,940 KB
testcase_12 AC 193 ms
6,940 KB
testcase_13 AC 193 ms
6,940 KB
testcase_14 AC 204 ms
6,940 KB
testcase_15 AC 193 ms
6,944 KB
testcase_16 AC 148 ms
6,944 KB
testcase_17 AC 144 ms
6,944 KB
testcase_18 AC 147 ms
6,940 KB
testcase_19 AC 147 ms
6,940 KB
testcase_20 AC 143 ms
6,940 KB
testcase_21 AC 145 ms
6,944 KB
testcase_22 AC 146 ms
6,940 KB
testcase_23 AC 119 ms
6,944 KB
testcase_24 AC 122 ms
6,944 KB
testcase_25 AC 123 ms
6,940 KB
testcase_26 AC 121 ms
6,944 KB
testcase_27 AC 120 ms
6,940 KB
testcase_28 AC 125 ms
6,944 KB
testcase_29 AC 125 ms
6,940 KB
testcase_30 AC 127 ms
6,944 KB
testcase_31 AC 145 ms
6,940 KB
testcase_32 AC 87 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2650.cc:  No.2650 [Cherry 6th Tune *] セイジャク - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

template <typename T>
struct SegTreeMaxDelay {
  int e2;
  vector<T> nodes;
  T defv;
  vector<bool> dls;
  SegTreeMaxDelay() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    nodes.assign(e2 * 2, defv);
    dls.assign(e2 * 2, false);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void __update(int k) {
    if (dls[k]) {
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0] = nodes[k1] = nodes[k];
      dls[k0] = dls[k1] = true;
      dls[k] = false;
    }
  }

  void set_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = v;
      dls[k] = true;
      return;
    }

    __update(k);

    int im = (i0 + i1) / 2;
    int k0 = k * 2 + 1, k1 = k0 + 1;
    set_range(r0, r1, v, k0, i0, im);
    set_range(r0, r1, v, k1, im, i1);
    nodes[k] = max(nodes[k0], nodes[k1]);
  }
  void set_range(int r0, int r1, T v) { set_range(r0, r1, v, 0, 0, e2); }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    __update(k);

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);
    return max(v0, v1);
  }
  T max_range(int r0, int r1) { return max_range(r0, r1, 0, 0, e2); }
};


/* global variables */

int xs[MAX_N], uxs[MAX_N];
SegTreeMaxDelay<int> st;

/* subroutines */

/* main */

int main() {
  int n, a;
  scanf("%d%d", &n, &a);
  for (int i = 0; i < n; i++) scanf("%d", xs + i);

  copy(xs, xs + n, uxs);
  sort(uxs, uxs + n);
  int m = unique(uxs, uxs + n) - uxs;

  st.init(m, -1);

  int tn;
  scanf("%d", &tn);

  for (int t = 0; t < tn; t++) {
    int l, r;
    scanf("%d%d", &l, &r), r++;

    int li = lower_bound(uxs, uxs + m, l) - uxs;
    int ri = lower_bound(uxs, uxs + m, r) - uxs;

    st.set_range(li, ri, t);
  }

  for (int i = 0; i < n; i++) {
    int xi = lower_bound(uxs, uxs + m, xs[i]) - uxs;
    auto e = st.max_range(xi, xi + 1);

    printf("%d\n", (e >= 0) ? e + 1 : -1);
  }

  return 0;
}
0