Submission #763952

#TimeUsernameProblemLanguageResultExecution timeMemory
763952CookieAddk (eJOI21_addk)C++14
100 / 100
267 ms10504 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:82:16: warning: unused variable 'ans' [-Wunused-variable]
   82 |             ll ans = 0;
      |                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...