This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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() {
int n,k;
cin >> n >> k;
vector<int> nums(n,0);
vector<int> prefix(n + 1,0);
int 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<int> pos(k,0);
for (int i = 0;i < k;i++)
{
cin >> pos[i];
}
iter_swap(nums.begin() + pos[0] - 1, nums.begin() + pos[k - 1] - 1);
for (int i = 0;i < k - 2;i++)
{
iter_swap(nums.begin() + pos[i] - 1, nums.begin() + pos[i + 1] - 1);
}
int 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;
int 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |