Submission #832156

#TimeUsernameProblemLanguageResultExecution timeMemory
832156vjudge1Addk (eJOI21_addk)C++17
0 / 100
1545 ms2944 KiB
#include<bits/stdc++.h> using namespace std; const int nmax = 1e5+5; int A[nmax]; int segtree[4*nmax]; void build(int idx, int low, int high) { if(low==high) { segtree[idx] = A[low]; return; } int mid = (low+high)/2; build(2*idx, low, mid); build(2*idx+1, mid+1, high); segtree[idx] = segtree[2*idx]+segtree[2*idx+1]; } int query(int idx, int low, int high, int l, int r) { if(low>=l && high<=r) { return segtree[idx]; } if(low>r || high<l) { return 0; } int mid = (low+high)/2; int left = query(2*idx,low,mid,l,r); int right = query(2*idx+1,mid+1,high,l,r); return left+right; } int main() { int N,K,Q; cin >> N >> K; for(int i=1; i<=N; i++) { cin >> A[i]; } build(1,1,N); cin >> Q; int com,l,r,m; int ujung, kal; int sem; int sum; for(int i=1; i<=Q; i++) { cin >> com; sum = 0; if(com==1) { cin >> m; } else { cin >> l >> r >> m; ujung = m-1; kal = 0; //ujung kiri for(int i=l; i<=(l+ujung-1); i++) { kal++; sum+=(kal*A[i]); } //tengah if(l+ujung <= r-ujung) { sem = query(1,1,N,l+ujung,r-ujung); sem*=m; sum+=sem; } //ujung kanan kal=0; for(int i=r; i>=r-ujung+1; i--) { kal++; sum+=(kal*A[i]); } cout << sum << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...