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;
map<int,ll> nums;
ll prefix[100001];
void sw (int k1,int k2)
{
ll inter = nums[k2];
nums[k2] = nums[k1];
nums[k1] = inter;
}
void init_pref()
{
ll curr = 0;
for (auto it:nums)
{
curr+=it.second;
prefix[it.first + 1] = curr;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;
cin >> n >> k;
ll curr = 0;
for (int i = 0;i < n;i++)
{
ll inter = 0;
cin >> inter;
nums[i] = inter;
}
init_pref();
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];
}
sw(pos[0] - 1,pos[k - 1] - 1);
for (int i = 0;i < k - 2;i++)
{
sw(pos[i] - 1,pos[i + 1] - 1);
}
init_pref();
}
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;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:42:8: warning: unused variable 'curr' [-Wunused-variable]
42 | ll curr = 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... |