結果
| 問題 | No.1558 Derby Live |
| コンテスト | |
| ユーザー |
sten_san
|
| 提出日時 | 2022-04-21 18:35:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 121 ms / 2,000 ms |
| コード長 | 4,805 bytes |
| コンパイル時間 | 1,958 ms |
| コンパイル使用メモリ | 201,560 KB |
| 最終ジャッジ日時 | 2025-01-28 19:24:32 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct iofast_t {
iofast_t() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} iofast;
struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
if constexpr (sizeof...(Args) == 0) return vector(arg, init);
else return vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
return vec(Element(), arg, args...);
}
template <typename Container>
auto distance(const Container &c, decltype(begin(c)) iter) {
return distance(begin(c), iter);
}
template <typename RIter, typename Compare = less<typename iterator_traits<RIter>::value_type>>
auto isort(RIter first, RIter last, Compare comp = Compare()) {
vector<int> i(distance(first, last));
iota(begin(i), end(i), 0);
sort(begin(i), end(i), [&](auto x, auto y) {
return comp(*(first + x), *(first + y));
});
return i;
}
template <typename, template <typename> typename, typename = void_t<>>
struct detect : false_type {};
template <typename T, template <typename> typename Check>
struct detect<T, Check, void_t<Check<T>>> : true_type {};
template <typename T, template <typename> typename Check>
constexpr inline bool detect_v = detect<T, Check>::value;
template <typename T>
using has_member_sort = decltype(declval<T>().sort());
template <typename Container, typename Compare = less<typename Container::value_type>>
auto sorted(Container c, Compare comp = Compare()) {
if constexpr (detect_v<Container, has_member_sort>) {
c.sort(comp);
return c;
}
else {
sort(begin(c), end(c), comp);
return c;
}
}
template <typename Container, typename Compare = equal_to<typename Container::value_type>>
auto uniqued(Container c, Compare comp = Compare()) {
c.erase(unique(begin(c), end(c), comp), end(c));
return c;
}
template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }
template <size_t N>
struct sperm : std::array<int, N> {
constexpr static size_t size() {
return N;
}
template <typename ...Args>
constexpr sperm(Args ...args): perm_() {
static_assert((std::is_convertible_v<Args, size_t> && ...), "Could not convert to size_t");
for (size_t i = 0; i < N; ++i) {
perm_[i] = i;
}
if constexpr (1 < sizeof...(Args)) {
bool f = true;
size_t p = 0, q = 0;
for (auto i : { static_cast<size_t>(args)... }) {
if (f) {
f = false; p = i; q = i;
continue;
}
perm_[p] = i; p = i;
}
perm_[p] = q;
}
}
constexpr sperm operator *(const sperm &r) const {
sperm x;
for (size_t i = 0; i < N; ++i) {
x[i] = perm_[r[i]];
}
return x;
}
constexpr auto &operator [](size_t i) {
return perm_[i];
}
constexpr const auto &operator [](size_t i) const {
return perm_[i];
}
private:
std::array<int, N> perm_;
};
template <size_t N>
auto &operator <<(std::ostream &os, const sperm<N> &sp) {
os << "(";
if constexpr (0 < std::size(sp)) {
os << sp[0];
for (size_t i = 1; i < std::size(sp); ++i) {
os << ", " << sp[i];
}
}
os << ")";
return os;
}
#include <atcoder/segtree>
using rep = sperm<18>;
rep op(rep x, rep y) {
return y * x;
}
rep elem() {
return {};
}
using segtree = atcoder::segtree<rep, op, elem>;
int main() {
int n, m, q; cin >> n >> m >> q;
segtree seg(m);
while (q--) {
int t; cin >> t;
if (t == 1) {
int d; cin >> d; --d;
rep p;
for (int i = 0; i < n; ++i) {
cin >> p[i]; --p[i];
}
seg.set(d, p);
}
if (t == 2) {
int s; cin >> s;
auto p = seg.prod(0, s);
rep q;
for (int i = 0; i < n; ++i) {
q[p[i]] = i;
}
cout << q[0] + 1;
for (int i = 1; i < n; ++i) {
cout << " " << q[i] + 1;
}
cout << endl;
}
if (t == 3) {
int l, r; cin >> l >> r; --l;
auto p = seg.prod(l, r);
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += abs(i - p[i]);
}
cout << ans << endl;
}
}
}
sten_san