Submission #69658751
Source Code Expand
// Problem: 'C - Rotate and Sum Query' // Contest: 'AtCoder - UNIQUE VISION Programming Contest 2024 Autumn (AtCoder Beginner Contest 425)' // URL: 'https://atcoder.jp/contests/abc425/tasks/abc425_c' // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by competitive-companion.el (https://github.com/luishgh/competitive-companion.el) #include <bits/stdc++.h> using namespace std; #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' typedef long long ll; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; vector<ll> pref; int c = 0; int n; ll pref_sum(ll l, ll r) { ll ret = pref[r]; if (l > 0) ret -= pref[l-1]; return ret; } ll query(ll l, ll r) { l += c, r += c; if (l >= n) l -= n; if (r >= n) r -= n; // cerr << "DEBUG " << l << ' ' << r << endl; if (l <= r) { return pref_sum(l, r); } else { return pref_sum(l, n - 1) + pref_sum(0, r); } } int main() {_; int q; cin >> n >> q; pref.assign(n+1, 0); for (int i = 0; i < n; i++) { cin >> pref[i]; if (i > 0) pref[i] += pref[i-1]; } while(q--) { int op; cin >> op; if (op == 1) { int x; cin >> x; c += x; c %= n; } else { int l, r; cin >> l >> r; l--, r--; cout << query(l, r) << endl; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Rotate and Sum Query |
User | luishgh |
Language | C++ 20 (gcc 12.2) |
Score | 350 |
Code Size | 1379 Byte |
Status | AC |
Exec Time | 53 ms |
Memory | 5180 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 350 / 350 | ||||
Status |
|
|
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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3464 KiB |
00_sample_01.txt | AC | 1 ms | 3520 KiB |
01_random_00.txt | AC | 1 ms | 3416 KiB |
01_random_01.txt | AC | 20 ms | 3408 KiB |
01_random_02.txt | AC | 28 ms | 4116 KiB |
01_random_03.txt | AC | 15 ms | 4668 KiB |
01_random_04.txt | AC | 27 ms | 3544 KiB |
01_random_05.txt | AC | 42 ms | 4700 KiB |
01_random_06.txt | AC | 26 ms | 3648 KiB |
01_random_07.txt | AC | 43 ms | 4672 KiB |
01_random_08.txt | AC | 35 ms | 4112 KiB |
01_random_09.txt | AC | 43 ms | 4600 KiB |
01_random_10.txt | AC | 33 ms | 3884 KiB |
01_random_11.txt | AC | 42 ms | 4712 KiB |
01_random_12.txt | AC | 26 ms | 4712 KiB |
01_random_13.txt | AC | 27 ms | 4636 KiB |
01_random_14.txt | AC | 53 ms | 4968 KiB |
01_random_15.txt | AC | 51 ms | 4988 KiB |
01_random_16.txt | AC | 49 ms | 4588 KiB |
01_random_17.txt | AC | 33 ms | 4520 KiB |
01_random_18.txt | AC | 41 ms | 5180 KiB |
01_random_19.txt | AC | 33 ms | 4640 KiB |