Submission #846748

#TimeUsernameProblemLanguageResultExecution timeMemory
846748JordanTsAddk (eJOI21_addk)C++17
92 / 100
1004 ms10664 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") using namespace std; const int MAXN=1e6+1; int N, Q, K; int A[MAXN]; int j[MAXN]; long long prefix[MAXN]; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void read() { cin >> N >> K; for(int i=1; i<=N; i++) { cin >> A[i]; prefix[i]=prefix[i-1]+A[i]; } } void change() { for(int i=1; i<K; i++) { swap(A[j[i]], A[j[i-1]]); } } long long rsq(int& l, const int& r, int& m) { long long sum=0; if(m>(r-l+1)/2) { m=(r-l+1)-m+1; } for(int i=0; i<m; i++) { sum+=(prefix[r-i]-prefix[l+i-1]); } return sum; } void solve() { cin >> Q; while(Q--) { int t; cin >> t; if(t==2) { int l, r, m; cin >> l >> r >> m; cout << rsq(l, r, m) << '\n'; } else { for(int i=0; i<K; i++) { cin >> j[i]; } ///change(); } } } int main() { fastIO(); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...