# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007595 |
2024-06-25T08:39:38 Z |
vjudge1 |
Addk (eJOI21_addk) |
C++17 |
|
166 ms |
9044 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
#define MAX 100005
int nArr, numRot, numQuery;
int A[MAX];
int sum[MAX];
int lz[4 * MAX], st[4 * MAX];
void pushDown(int id, int l, int r){
if (!lz[id]) return;
int m = (l + r) >> 1;
st[id << 1] += (m - l + 1) * lz[id];
st[id << 1 | 1] += (r - m) * lz[id];
lz[id << 1] += lz[id];
lz[id << 1 | 1] += lz[id];
lz[id] = 0;
}
void upd(int id, int l, int r, int u, int v, int val){
if (u > r || v < l) return;
if (u <= l && v >= r){
st[id] += (r - l + 1) * val;
lz[id] += val;
return;
}
int m = (l + r) >> 1;
pushDown(id, l, r);
upd(id << 1, l, m, u, v, val);
upd(id << 1 | 1, m + 1, r, u, v, val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
int query(int id, int l, int r, int u, int v){
if (u > r || v < l) return 0;
if (u <= l && v >= r) return st[id];
int m = (l + r) >> 1;
pushDown(id, l, r);
int ql = query(id << 1, l, m, u, v);
int qr = query(id << 1 | 1, m + 1, r, u, v);
return (ql + qr);
}
void process(void){
cin >> nArr >> numRot;
for (int i = 1; i <= nArr; ++i) cin >> A[i], upd(1, 1, nArr, i, nArr, A[i]);
cin >> numQuery;
for (int i = 1; i <= numQuery; ++i){
int cmd, l, r, m;
cin >> cmd;
if(cmd == 1){
vector<int> pos(numRot), val;
for(int&v : pos) cin >> v;
for (int j = 1; j < numRot; ++j) val.push_back(A[pos[j]]);
val.push_back(A[pos[0]]);
for (int j = 0; j < numRot; ++j){
upd(1, 1, nArr, pos[j], nArr, val[j] - A[pos[j]]);
A[pos[j]] = val[j];
}
}
else{
cin >> l >> r >> m;
cout << query(1, 1, nArr, l + m - 1, r) - query(1, 1, nArr, l - 1, r - m) << '\n';
}
}
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2652 KB |
Output is correct |
6 |
Correct |
4 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2652 KB |
Output is correct |
8 |
Correct |
6 ms |
2748 KB |
Output is correct |
9 |
Correct |
9 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
4952 KB |
Output is correct |
2 |
Correct |
27 ms |
5212 KB |
Output is correct |
3 |
Correct |
36 ms |
5576 KB |
Output is correct |
4 |
Correct |
73 ms |
8276 KB |
Output is correct |
5 |
Correct |
91 ms |
9044 KB |
Output is correct |
6 |
Correct |
91 ms |
8784 KB |
Output is correct |
7 |
Correct |
90 ms |
8788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
5712 KB |
Output is correct |
2 |
Correct |
94 ms |
8272 KB |
Output is correct |
3 |
Correct |
166 ms |
8272 KB |
Output is correct |
4 |
Correct |
104 ms |
9040 KB |
Output is correct |