-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP14648.cpp
48 lines (44 loc) · 913 Bytes
/
P14648.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define FOR(i, n) for(int i = 0 ; i < n ; i++)
void SWAP(int *x, int *y) {
int t = *x;
*x = *y;
*y = t;
return;
}
long long SUM(int *arr, int i, int j) {
long long sum = 0;
for (int a = i; a <= j; a++)
sum += arr[a];
return sum;
}
int main() {
int n, q;
int arr[1001];
scanf("%d %d", &n, &q);
FOR(i, n)
scanf("%d", arr + i);
for (int i = 0; i < q; i++) {
long long ret = 0;
int nQ;
scanf("%d", &nQ);
if (nQ == 1) {
int tmpArr[2];
for (int j = 0; j < 2; j++) {//
scanf("%d", tmpArr + j);
}
ret = SUM(arr, tmpArr[0] - 1, tmpArr[1] - 1);
SWAP(&arr[tmpArr[0] - 1], &arr[tmpArr[1] - 1]);
}
else {
int tmpArr[4];;
for (int j = 0; j < 4; j++) {
scanf("%d", tmpArr + j);
}
ret = SUM(arr, tmpArr[0] - 1, tmpArr[1] - 1) - SUM(arr, tmpArr[2] - 1, tmpArr[3] - 1);
}
printf("%lld\n", ret);
}
return 0;
}