結果

問題 No.875 Range Mindex Query
ユーザー shino16shino16
提出日時 2022-09-15 23:30:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,713 bytes
コンパイル時間 3,613 ms
コンパイル使用メモリ 231,068 KB
実行使用メモリ 6,796 KB
最終ジャッジ日時 2023-08-22 17:04:17
合計ジャッジ時間 5,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,436 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "lib/prelude.hpp"
#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i, m, n) for (auto i = (m); i < (n); i++)
#define rep(i, n) rep2(i, 0, n)
#define repr2(i, m, n) for (auto i = (n); i-- > (m);)
#define repr(i, n) repr2(i, 0, n)
#define all(x) begin(x), end(x)
template <class T>
auto ndvec(size_t n, T&& x) { return vector(n, forward<T>(x)); }
template <class... Ts>
auto ndvec(size_t n, Ts&&... xs) { return vector(n, ndvec(forward<Ts>(xs)...)); }
#line 3 "lib/util/transpose.hpp"

template <class T, size_t... Is>
auto transpose_impl(const vector<T>& v, index_sequence<Is...>) {
  tuple<vector<decay_t<tuple_element_t<Is, T>>>...> w;
  (get<Is>(w).reserve(v.size()), ...);
  for (const auto& row : v)
    (get<Is>(w).push_back(get<Is>(row)), ...);
  return w;
}

template <class T>
auto transpose(const vector<T>& v) {
  return transpose_impl(v, make_index_sequence<tuple_size_v<T>>{});
}
#line 4 "lib/io.hpp"

struct int1 {
  int val;
  int1(int a = 1): val(a - 1) {}
  operator int() const { return val; }
};

template <size_t BufSize = 1 << 26>
class stdin_reader {
 public:
  stdin_reader() { buf[fread(buf, 1, sizeof(buf), stdin)] = 0; }

  template <class T>
  enable_if_t<is_integral_v<T>> read(T& x) {
    skip(); [[maybe_unused]] bool neg = false;
    if constexpr (is_signed_v<T>) neg = *p == '-' ? (p++, true) : false;
    x = 0; while (*p > ' ') x = x * 10 + (*p++ & 0x0F);
    if constexpr (is_signed_v<T>) x = neg ? -x : x;
  }
  template <class T> void_t<decltype(&T::val)> read(T& x) { x = T((unsigned)(*this)); }
  void read(char* q) {
    skip(); char* p0 = p; while (*p > ' ') p++;
    copy(p0, p, q);
  }
  template <size_t N> void read(char (&s)[N]) { read(s); }
  void read(string& s) {
    skip(); char* p0 = p; while (*p > ' ') p++;
    s.assign(p0, p);
  }
  template <class T, void_t<decltype(tuple_size<T>::value)>* = nullptr>
  void read(T& x) { read_tuple_like(x, make_index_sequence<tuple_size_v<T>>{}); }
  template <class T, class U> void read(pair<T, U>& x) { read(x.first), read(x.second); }
  template <class T, size_t N> void read(T (&a)[N]) { for (auto& e : a) read(e); }

  template <class T> operator T() { T x; return read(x), x; }
  template <class... Ts> void operator()(Ts&... xs) { (read(xs), ...); }
  int operator--() { return (int)*this - 1; }
  template <class T> void vec(vector<T>& v, int n) { v.resize(n); for (auto& e : v) read(e); }
  template <class T> vector<T> vec(int n) { vector<T> v; return vec(v, n), v; }
  template <class T>
  void vvec(vector<vector<T>>& v, int n, int m) { v.resize(n); for (auto& e : v) vec(e, m); }
  template <class T>
  vector<vector<T>> vvec(int n, int m) { vector<vector<T>> v; return vvec(v, n, m), v; }
  template <class... Ts> auto transpose(int n) { return ::transpose(vec<tuple<Ts...>>(n)); }

 private:
  char buf[BufSize], *p = buf;
  void skip() { while (*p <= ' ') p++; }
  template <class T, size_t... Is>
  void read_tuple_like(T& x, index_sequence<Is...>) { (*this)(get<Is>(x)...); }
};

template <size_t BufSize = 1 << 26>
class stdout_writer {
 public:
  ~stdout_writer() { flush(); }
  void flush() { fwrite(buf, 1, p - buf, stdout), p = buf; }
  void write_char(char c) { *p++ = c; }
  void write(char c) { write_char(c); }
  template <class T> enable_if_t<is_integral_v<T>> write(T x) {
    if (!x) return write_char('0');
    if constexpr (is_signed_v<T>) if (x < 0) write_char('-'), x = -x;
    static char tmp[16];
    char* q = end(tmp);
    while (x >= 10000) memcpy(q -= 4, digits.data + x % 10000 * 4, 4), x /= 10000;
    if (x < 10) write_char('0' + x);
    else if (x < 100)
      write_char('0' + (uint8_t)x / 10), write_char('0' + (uint8_t)x % 10);
    else if (x < 1000) memcpy(p, digits.data + x * 4 + 1, 3), p += 3;
    else memcpy(p, digits.data + x * 4, 4), p += 4;
    memcpy(p, q, end(tmp) - q), p += end(tmp) - q;
  }
  template <class T> void_t<decltype(&T::val)> write(T x) { write(x.val()); }
  void write(double x) {
    static char tmp[40]; sprintf(tmp, "%.10f", x); write(tmp);
  }
  void write(const char* s) { while (*s) *p++ = *s++; }
  void write(const string& s) { memcpy(p, s.c_str(), s.size()), p += s.size(); }
  template <class T, class U>
  void write(const pair<T, U>& x) { write(x.first), write_char(' '), write(x.second); }
  template <class... Ts>
  void write(const tuple<Ts...>& x) { write_tuple(x, make_index_sequence<sizeof...(Ts)>{}); }
  template <class... Ts>
  void write(const Ts&... xs) { ((write(xs), write_char(' ')), ...), --p; }
  template <class... Ts> void writeln(const Ts&... xs) { write(xs...), write_char('\n'); }

  template <class... Ts> void operator()(const Ts&... xs) { writeln(xs...); }
  template <class It> void iter(It first, It last, char sep = ' ') {
    if (first == last) write_char('\n');
    else {
      while (first != last) write(*first++), write_char(sep);
      p[-1] = '\n';
    }
  }

#define INSTANT(s) \
  void s() { writeln(#s); }
  INSTANT(No) INSTANT(NO) INSTANT(Aoki)
  INSTANT(possible) INSTANT(Possible) INSTANT(POSSIBLE)
  INSTANT(impossible) INSTANT(Impossible) INSTANT(IMPOSSIBLE)
#undef INSTANT
  void Yes(bool b = true) { writeln(b ? "Yes" : "No"); }
  void YES(bool b = true) { writeln(b ? "YES" : "NO"); }
  void Takahashi(bool b = true) { writeln(b ? "Takahashi" : "Aoki"); }

 private:
  char buf[BufSize], *p = buf;
  template <class T, size_t... Is> void write_tuple(const T& x, index_sequence<Is...>) {
    ((write(get<Is>(x)), write_char(' ')), ...), --p;
  }
  struct four_digits {
    char data[40000];
    constexpr four_digits() : data() {
      for (int i = 0; i < 10000; i++)
        for (int n = i, j = 4; j--;) data[i * 4 + j] = n % 10 + '0', n /= 10;
    }
  } static constexpr digits{};
};

static stdin_reader<> in;
static stdout_writer<> out;
#line 3 "lib/algebra.hpp"

#define CONST(val) [] { return val; }
#define WRAP_FN(func) \
  [](auto&&... args) { return func(forward<decltype(args)>(args)...); }

template <class Unit, class Op>
struct monoid : private Unit, private Op {
  using type = decltype(declval<Unit>()());
  monoid(Unit unit, Op op) : Unit(unit), Op(op) {}
  type unit() const { return Unit::operator()(); }
  type op(type a, type b) const { return Op::operator()(a, b); }
};

template <class Unit, class Op, class Inv>
struct group : monoid<Unit, Op>, private Inv {
  using type = typename monoid<Unit, Op>::type;
  group(Unit unit, Op op, Inv inv) : monoid<Unit, Op>(unit, op), Inv(inv) {}
  type inv(type a) const { return Inv::operator()(a); }
};

template <class T>
struct addition {
  using type = T;
  type unit() const { return 0; }
  type op(type a, type b) const { return a + b; }
  type inv(type a) const { return -a; }
};

template <class T>
struct maximum {
  using type = T;
  type unit() const { return numeric_limits<T>::min(); }
  type op(type a, type b) const { return a > b ? a : b; }
};

template <class T>
struct minimum {
  using type = T;
  type unit() const { return numeric_limits<T>::max(); }
  type op(type a, type b) const { return a > b ? b : a; }
};
#line 3 "lib/ds/segtree.hpp"

template <class M>
class segment_tree {
 public:
  using value_type = typename M::type;
  template <class Iter>
  segment_tree(Iter f, Iter l, M m = M()) : m(m), data((l - f) * 2) {
    copy(f, l, data.begin() + (l - f));
    init();
  }
  template <class F>
  segment_tree(int n, F f, M m = M()) : m(m), data(n * 2) {
    rep(i, n) data[i + n] = f(i);
    init();
  }
  segment_tree(int n = 0, M m = M()) : m(m), data(n * 2, m.unit()) {}

  int size() const { return data.size() / 2; }
  value_type prod(int l, int r) const {
    value_type accl = m.unit(), accr = m.unit();
    for (l += size(), r += size(); l < r; l >>= 1, r >>= 1) {
      if (l & 1) accl = m.op(accl, data[l++]);
      if (r & 1) accr = m.op(data[--r], accr);
    }
    return m.op(accl, accr);
  }
  void add(int i, value_type v) {
    exec(i, [=](value_type& e) { e = m.op(e, v); });
  }
  void set(int i, value_type v) {
    exec(i, [=](value_type& e) { e = v; });
  }
  template <class F>
  void exec(int i, F f) {
    f(data[i + size()]);
    for (i += size(); i >>= 1;) data[i] = m.op(data[i << 1], data[i << 1 | 1]);
  }
  // min r s.t. !f(prod(l, r)) or size()+1 if no such r exists
  template <class F>
  int partition_point(int l, F f) const {
    if (!f(m.unit())) return l;
    if (f(data[1])) return size() + 1;
    if (l < size() && !f(data[l + size()])) return l + 1;
    int r = l + size();
    value_type acc = m.unit();
    do {
      value_type acc2 = m.op(acc, data[r]);
      if (f(acc2)) {
        acc = acc2, r++;
        while (r % 2 == 0) r /= 2;
      } else {
        r *= 2;
      }
    } while (r < size());
    if (f(m.op(acc, data[r]))) r++;
    return (++r -= size()) < l ? size() : r;
  }
  // mint r s.t. prod(l, r) >= x
  template <class Comp = less<>>
  int lower_bound(int l, value_type x, Comp comp = Comp()) const {
    return partition_point(l, [&](auto y) { return comp(y, x); });
  }

 private:
  M m;
  vector<value_type> data;

  void init() {
    repr2(i, 1, size()) data[i] = m.op(data[i << 1], data[i << 1 | 1]);
  }
};
#line 3 "main.cpp"

int main() {
  int n = in, q = in;
  auto a = in.vec<int>(n);
  segment_tree seg(all(a), minimum<int>{});
  while (q--) {
    int op = in, l = in, r = in;
    if (op == 1) {
      l--, r--;
      int tmp = seg.prod(r, r + 1);
      seg.exec(l, [&](auto& v) { swap(v, tmp); });
      seg.exec(r, [&](auto& v) { v = tmp; });
    } else {
      l--;
      int mini = seg.prod(l, r);
      int i = seg.partition_point(l, [&](auto v) { return v > mini; });
      out(i);
    }
  }
}
0