Submission #863889

#TimeUsernameProblemLanguageResultExecution timeMemory
863889FIFI_cppAddk (eJOI21_addk)C++17
36 / 100
2069 ms4436 KiB
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <cstdlib> #include <cmath> #include <stdio.h> #include <math.h> #include <queue> #include <stack> #include <deque> #include <fstream> #include <iterator> #include <set> #include <map> #include <iomanip> #define ll long long using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,k; cin >> n >> k; ll nums[100000]; ll prefix[100001]; ll curr = 0; for (int i = 0;i < n;i++) { cin >> nums[i]; curr += nums[i]; prefix[i + 1] = curr; } int q; cin >> q; while (q--) { int type; cin >> type; if (type == 1) { vector<ll> pos(k,0); for (int i = 0;i < k;i++) { cin >> pos[i]; } swap(nums[pos[0] - 1], nums[pos[k - 1] - 1]); for (int i = 0;i < k - 2;i++) { swap(nums[pos[i] - 1], nums[pos[i + 1] - 1]); } ll s = 0; for (int i = 0;i < n;i++) { prefix[i + 1] = s + nums[i]; s+=nums[i]; } } else { int begin,end,size; cin >> begin >> end >> size; int c_begin = begin; int c_end = begin + size - 1; ll curr_sum = 0; while (c_end <= end) { curr_sum += prefix[c_end] - prefix[c_begin - 1]; c_end++; c_begin++; } cout << curr_sum << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...