Submission #72690578


Source Code Expand

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i, s, n) for (lli i = s; i < n; i++)
#define INF (1LL << 62)
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) #VariableName
#define LOG1(x)                                                                \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << endl;
#define LOG2(x, y)                                                             \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << endl;
#define LOG3(x, y, z)                                                          \
  if (DEBUG)                                                                   \
    cout << TO_STRING(x) << "=" << x << " " << TO_STRING(y) << "=" << y << " " \
         << TO_STRING(z) << "=" << z << endl;
#define LOG4(w, x, y, z)                                                       \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z        \
         << endl;
#define LOG5(w, x, y, z, a)                                                    \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << endl;
#define LOG6(w, x, y, z, a, b)                                                 \
  if (DEBUG)                                                                   \
    cout << TO_STRING(w) << "=" << w << " " << TO_STRING(x) << "=" << x << " " \
         << TO_STRING(y) << "=" << y << " " << TO_STRING(z) << "=" << z << " " \
         << TO_STRING(a) << "=" << a << " " << TO_STRING(b) << "=" << b        \
         << endl;

#define overload6(a, b, c, d, e, f, g, ...) g
#define LOG(...)                                                               \
  overload6(__VA_ARGS__, LOG6, LOG5, LOG4, LOG3, LOG2, LOG1)(__VA_ARGS__)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

mt19937 engine;
std::chrono::system_clock::time_point start, endTime;

#define DEBUG 0
lli op(lli a, lli b) { return a + b; }

lli e() { return 0; }

void solve() {
  //  write your code here

  lli N, Q;
  cin >> N >> Q;

  vector<lli> A(N);

  REP(i, 0, N) { cin >> A[i]; }

  atcoder::segtree<lli, op, e> seg(A);

  while (Q--) {
    lli num = 0;
    cin >> num;
    if (num == 1) {
      lli x;
      cin >> x;
      x--;
      swap(A[x], A[x + 1]);
      seg.set(x, A[x]);
      seg.set(x + 1, A[x + 1]);
    } else {
      lli l, r;
      cin >> l >> r;
      l--;
      cout << seg.prod(l, r) << endl;
    }
  }
}

// Generated by 2.13.0 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  // Failed to predict input format

  lli N = 1;
  // cin >> N;
  while (N--)
    solve();

  return 0;
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User ohuton_labo
Language C++23 (GCC 15.2.0)
Score 400
Code Size 3649 Byte
Status AC
Exec Time 446 ms
Memory 11652 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3544 KiB
00_sample_01.txt AC 1 ms 3596 KiB
01_random_00.txt AC 446 ms 10800 KiB
01_random_01.txt AC 446 ms 10608 KiB
01_random_02.txt AC 415 ms 10012 KiB
01_random_03.txt AC 374 ms 9292 KiB
01_random_04.txt AC 366 ms 9040 KiB
01_random_05.txt AC 339 ms 8968 KiB
01_random_06.txt AC 316 ms 8912 KiB
01_random_07.txt AC 312 ms 8920 KiB
01_random_08.txt AC 285 ms 8896 KiB
01_random_09.txt AC 263 ms 8912 KiB
01_random_10.txt AC 227 ms 8968 KiB
01_random_11.txt AC 416 ms 11388 KiB
01_random_12.txt AC 401 ms 10868 KiB
01_random_13.txt AC 386 ms 10352 KiB
01_random_14.txt AC 366 ms 9604 KiB
01_random_15.txt AC 350 ms 9344 KiB
01_random_16.txt AC 333 ms 9004 KiB
01_random_17.txt AC 317 ms 9020 KiB
01_random_18.txt AC 299 ms 9156 KiB
01_random_19.txt AC 281 ms 9048 KiB
01_random_20.txt AC 262 ms 9040 KiB
01_random_21.txt AC 243 ms 9040 KiB
01_random_22.txt AC 333 ms 9040 KiB
01_random_23.txt AC 336 ms 9024 KiB
02_handmade_00.txt AC 1 ms 3448 KiB
02_handmade_01.txt AC 1 ms 3588 KiB
02_handmade_02.txt AC 387 ms 11652 KiB