# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
763952 |
2023-06-23T03:53:24 Z |
Cookie |
Addk (eJOI21_addk) |
C++14 |
|
267 ms |
10504 KB |
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
const int mxn = 1e5 + 5;
int n, k;
struct ST{
ll st[4 * mxn + 1];
void upd(int nd, int l, int r,int id, ll v){
if(id > r || id < l)return;
if(l == r){
st[nd] = v;
return;
}
int mid = (l + r) >> 1;
upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
st[nd] = st[nd << 1] + st[nd << 1 | 1];
}
ll get(int nd, int l, int r, int ql, int qr){
if(ql > r || qr < l)return(0);
if(ql <= l && qr >= r)return(st[nd]);
int mid = (l + r) >> 1;
return(get(nd << 1, l, mid, ql, qr) + get(nd << 1 | 1, mid + 1, r, ql, qr));
}
int kth(int nd, int l, int r, int k){
if(l == r)return(l);
int mid = (l + r) >> 1;
if(st[nd << 1] >= k){
return(kth(nd << 1, l, mid, k));
}else{
return(kth(nd << 1 | 1, mid + 1, r, k - st[nd << 1]));
}
}
ll query(int l, int r){
return(get(1, 1, n, l, r));
}
void upd(int id, ll v){
upd(1, 1, n, id, v);
}
};
ST bit, bit2;
ll a[mxn + 1];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i]; bit.upd(i, a[i]); bit2.upd(i, a[i] * i);
}
int q; cin >> q;
for(int i = 1; i <= q; i++){
int idq; cin >> idq;
if(idq == 1){
vt<int>id(k), temp(k);
for(int j = 0; j < k; j++){
cin >> id[j]; temp[j] = a[id[j]];
}
for(int j = 0;j < k; j++){
bit.upd(id[j], a[id[(j + 1) % k]]);
bit2.upd(id[j], a[id[(j + 1) % k]] * id[j]);
}
for(int j = 0; j < k; j++){
a[id[j]] = temp[(j + 1) % k];
}
}else{
int l, r, m; cin >> l >> r >> m;
ll ans = 0;
/*
for(int j = l; j <= r; j++){
int low = max(j - m + 1, l), high = min(r - m + 1, j);
ans += 1LL * (high - low + 1) * a[j];
}
cout << ans << "\n";
*/
ll low = bit.query(l, l + m - 1) * l + bit2.query(l + m, r) - bit.query(l + m, r) * m + bit.query(l + m, r);
ll high = bit.query(r - m + 1, r) * (r - m + 1) + bit2.query(l, r - m);
//cout << high << " " << low << " " << "\n";
cout << high - low + bit.query(l, r) << "\n";
}
}
return(0);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:82:16: warning: unused variable 'ans' [-Wunused-variable]
82 | ll ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
596 KB |
Output is correct |
7 |
Correct |
10 ms |
668 KB |
Output is correct |
8 |
Correct |
11 ms |
724 KB |
Output is correct |
9 |
Correct |
16 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1788 KB |
Output is correct |
2 |
Correct |
51 ms |
1976 KB |
Output is correct |
3 |
Correct |
70 ms |
3240 KB |
Output is correct |
4 |
Correct |
129 ms |
5968 KB |
Output is correct |
5 |
Correct |
185 ms |
6648 KB |
Output is correct |
6 |
Correct |
173 ms |
6500 KB |
Output is correct |
7 |
Correct |
183 ms |
6548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
3260 KB |
Output is correct |
2 |
Correct |
165 ms |
8544 KB |
Output is correct |
3 |
Correct |
267 ms |
10504 KB |
Output is correct |
4 |
Correct |
205 ms |
9424 KB |
Output is correct |