Submission #763950

#TimeUsernameProblemLanguageResultExecution timeMemory
763950CookieAddk (eJOI21_addk)C++14
92 / 100
64 ms6596 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 BIT{ ll bit[mxn + 1]; void upd(int p, ll v){ while(p <= n){ bit[p] += v; p += p & (-p); } } ll get(int p){ ll ans = 0; while(p){ ans += bit[p]; p -= p & (-p); } return(ans); } ll query(int l, int r){ if(l > r)return(0); return(get(r) - get(l - 1)); } }; BIT 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){ for(int j = 0; j < k; j++){ int x; cin >> x; } }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:59:16: warning: unused variable 'ans' [-Wunused-variable]
   59 |             ll ans = 0;
      |                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...