#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<ll> nums(n,0);
vector<ll> prefix(n + 1,0);
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];
}
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);
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
8 ms |
448 KB |
Output is correct |
5 |
Correct |
15 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
668 KB |
Output is correct |
7 |
Correct |
21 ms |
604 KB |
Output is correct |
8 |
Correct |
27 ms |
728 KB |
Output is correct |
9 |
Correct |
45 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
848 KB |
Output is correct |
2 |
Correct |
297 ms |
1984 KB |
Output is correct |
3 |
Correct |
506 ms |
2672 KB |
Output is correct |
4 |
Correct |
1815 ms |
4340 KB |
Output is correct |
5 |
Execution timed out |
2036 ms |
4588 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1274 ms |
1624 KB |
Output is correct |
2 |
Execution timed out |
2049 ms |
5004 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |