結果

問題 No.2809 Sort Query
ユーザー risujirohrisujiroh
提出日時 2024-07-12 22:11:08
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,283 ms / 2,000 ms
コード長 4,119 bytes
コンパイル時間 4,902 ms
コンパイル使用メモリ 306,820 KB
実行使用メモリ 32,584 KB
最終ジャッジ日時 2024-07-12 22:12:38
合計ジャッジ時間 81,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1,157 ms
30,628 KB
testcase_02 AC 1,068 ms
30,300 KB
testcase_03 AC 990 ms
30,352 KB
testcase_04 AC 980 ms
29,184 KB
testcase_05 AC 1,076 ms
32,064 KB
testcase_06 AC 957 ms
29,860 KB
testcase_07 AC 960 ms
29,500 KB
testcase_08 AC 974 ms
32,508 KB
testcase_09 AC 940 ms
30,564 KB
testcase_10 AC 965 ms
30,008 KB
testcase_11 AC 1,027 ms
31,440 KB
testcase_12 AC 1,025 ms
31,696 KB
testcase_13 AC 1,001 ms
31,436 KB
testcase_14 AC 1,010 ms
31,560 KB
testcase_15 AC 1,030 ms
31,432 KB
testcase_16 AC 982 ms
31,436 KB
testcase_17 AC 1,022 ms
31,436 KB
testcase_18 AC 970 ms
31,564 KB
testcase_19 AC 1,055 ms
31,564 KB
testcase_20 AC 988 ms
31,432 KB
testcase_21 AC 1,260 ms
31,948 KB
testcase_22 AC 1,212 ms
32,584 KB
testcase_23 AC 1,264 ms
31,436 KB
testcase_24 AC 1,283 ms
31,304 KB
testcase_25 AC 1,263 ms
31,948 KB
testcase_26 AC 1,152 ms
29,028 KB
testcase_27 AC 1,144 ms
29,612 KB
testcase_28 AC 1,136 ms
29,864 KB
testcase_29 AC 1,122 ms
29,420 KB
testcase_30 AC 1,157 ms
29,384 KB
testcase_31 AC 1,104 ms
29,536 KB
testcase_32 AC 1,042 ms
28,956 KB
testcase_33 AC 1,066 ms
29,620 KB
testcase_34 AC 1,039 ms
29,556 KB
testcase_35 AC 1,067 ms
29,392 KB
testcase_36 AC 1,101 ms
31,312 KB
testcase_37 AC 1,112 ms
31,692 KB
testcase_38 AC 1,116 ms
31,564 KB
testcase_39 AC 1,094 ms
31,440 KB
testcase_40 AC 1,112 ms
31,944 KB
testcase_41 AC 989 ms
30,456 KB
testcase_42 AC 1,018 ms
29,244 KB
testcase_43 AC 969 ms
30,424 KB
testcase_44 AC 992 ms
30,576 KB
testcase_45 AC 1,029 ms
29,780 KB
testcase_46 AC 873 ms
29,276 KB
testcase_47 AC 915 ms
29,644 KB
testcase_48 AC 888 ms
29,416 KB
testcase_49 AC 919 ms
29,532 KB
testcase_50 AC 889 ms
29,528 KB
testcase_51 AC 822 ms
24,320 KB
testcase_52 AC 699 ms
24,320 KB
testcase_53 AC 690 ms
24,320 KB
testcase_54 AC 746 ms
24,192 KB
testcase_55 AC 680 ms
24,320 KB
testcase_56 AC 660 ms
19,252 KB
testcase_57 AC 487 ms
14,360 KB
testcase_58 AC 470 ms
17,396 KB
testcase_59 AC 464 ms
12,124 KB
testcase_60 AC 636 ms
24,716 KB
testcase_61 AC 858 ms
29,852 KB
testcase_62 AC 479 ms
16,712 KB
testcase_63 AC 692 ms
20,304 KB
testcase_64 AC 947 ms
29,236 KB
testcase_65 AC 538 ms
21,572 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

struct S {
  mutable Int v;
  Int id;

  friend auto operator<=>(const S&, const S&) = default;
};

void Solve() {
  Int n, q;
  Scan(n, q);
  TreeSet<S> s;
  for (Int i : Rep(n)) {
    s.insert({-1, i});
  }
  for (Int i : Rep(n)) {
    Int a;
    Scan(a);
    s.find_by_order(i)->v = a;
  }
  std::vector<Int> v(n);
  std::iota(v.begin(), v.end(), 0);
  while (q--) {
    Int t;
    Scan(t);
    if (t == 1) {
      Int k, x;
      Scan(k, x);
      --k;
      s.find_by_order(k)->v = x;
      v.push_back(k);
    } else if (t == 2) {
      ranges::sort(v);
      v.resize(Sz(v) - Sz(ranges::unique(v)));
      std::vector<S> tmp;
      for (Int k : Rev(v)) {
        auto it = s.find_by_order(k);
        tmp.push_back(*it);
        s.erase(it);
      }
      ranges::for_each(tmp, $(s.insert($1)));
      v.clear();
    } else {
      Int k;
      Scan(k);
      --k;
      Print(s.find_by_order(k)->v);
    }
  }
}

}  // namespace

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::setprecision(std::numeric_limits<Float>::max_digits10);

  Solve();
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

template <class Key, class T, class Compare = std::less<>>
using TreeMap = __gnu_pbds::tree<Key, T, Compare, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class Key, class Compare = std::less<>>
using TreeSet = TreeMap<Key, __gnu_pbds::null_type, Compare>;

#define $(...) \
  [&]<class T1 = int, class T2 = int>(T1&& $1 = 0, T2&& $2 = 0)->decltype(auto) { return __VA_ARGS__; }

using Int = int64_t;
using Float = double;

namespace ranges = std::ranges;
namespace views = std::views;

inline constexpr auto Rev = views::reverse;
inline constexpr auto Map = views::transform;
inline constexpr auto Filter = views::filter;

constexpr auto Rep(Int l, Int r) { return views::iota(std::min(l, r), r); }
constexpr auto Rep(Int n) { return Rep(0, n); }
constexpr auto Rep1(Int l, Int r) { return Rep(l, r + 1); }
constexpr auto Rep1(Int n) { return Rep(1, n + 1); }

constexpr Int Sz(auto&& r) { return static_cast<Int>(ranges::size(r)); }

template <class T, class U = T> bool Chmin(T& x, U&& y) { return y < x && (x = std::forward<U>(y), true); }
template <class T, class U = T> bool Chmax(T& x, U&& y) { return x < y && (x = std::forward<U>(y), true); }

inline constexpr Int INF = [] { std::array<char, sizeof(Int)> a; a.fill(0x3f); return std::bit_cast<Int>(a); }();

template <class T> concept Range = ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept TupleLike = std::__is_tuple_like<T>::value && !Range<T>;

namespace std {

istream& operator>>(istream& is, Range auto&& r) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

istream& operator>>(istream& is, TupleLike auto&& t) {
  return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

ostream& operator<<(ostream& os, Range auto&& r) {
  for (string_view sep = ""; auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

ostream& operator<<(ostream& os, TupleLike auto&& t) {
  const auto f = [&](auto&... xs) -> ostream& {
    [[maybe_unused]] string_view sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

}  // namespace std

#define DEF_INC_OR_DEC(op) \
  auto& operator op(Range auto&& r) { \
    for (auto&& e : r) { \
      op e; \
    } \
    return r; \
  } \
  auto& operator op(TupleLike auto&& t) { \
    std::apply([](auto&... xs) { (op xs, ...); }, t); \
    return t; \
  }

DEF_INC_OR_DEC(++)
DEF_INC_OR_DEC(--)

#undef DEF_INC_OR_DEC

void Scan(auto&&... xs) { std::cin >> std::tie(xs...); }
void Print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }

template <class F>
class Fix {
 public:
  explicit Fix(F f) : f_(std::move(f)) {}
  decltype(auto) operator()(auto&&... xs) const { return f_(std::ref(*this), std::forward<decltype(xs)>(xs)...); }

 private:
  F f_;
};

#endif  // __INCLUDE_LEVEL__
0