Submission #793207

# Submission time Handle Problem Language Result Execution time Memory
793207 2023-07-25T15:52:46 Z rainboy Addk (eJOI21_addk) C
100 / 100
83 ms 7508 KB
#include <stdio.h>

#define N	100000
#define K	10

void update(long long *ft, int i, int n, long long x) {
	while (i < n) {
		ft[i] += x;
		i |= i + 1;
	}
}

long long query(long long *ft, int i) {
	long long x = 0;

	while (i >= 0) {
		x += ft[i];
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	static int aa[N];
	static long long ft1[N], ft2[N];
	int n, k, q, h, i, j;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n; i++)
		update(ft1, i, n, aa[i]), update(ft2, i, n, (long long) aa[i] * i);
	scanf("%d", &q);
	while (q--) {
		static int ii[K];
		int t, l, r, m, tmp;

		scanf("%d", &t);
		if (t == 1) {
			for (h = 0; h < k; h++)
				scanf("%d", &ii[h]), ii[h]--;
			for (h = 0; h < k; h++) {
				i = ii[h], j = ii[(h + 1) % k];
				update(ft1, i, n, aa[j] - aa[i]), update(ft2, i, n, (long long) (aa[j] - aa[i]) * i);
			}
			for (h = 0; h + 1 < k; h++) {
				i = ii[h], j = ii[h + 1];
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
			}
		} else {
			scanf("%d%d%d", &l, &r, &m), l--, r--;
			printf("%lld\n", query(ft2, r) - query(ft2, l - 1)
					- (query(ft1, r) - query(ft1, l - 1)) * (l - 1)
					- (query(ft2, r) - query(ft2, l + m - 1))
					+ (query(ft1, r) - query(ft1, l + m - 1)) * (l + m - 1)
					- (query(ft2, r) - query(ft2, r - m + 1))
					+ (query(ft1, r) - query(ft1, r - m + 1)) * (r - m + 1));
		}
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
Main.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
Main.c:41:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &ii[h]), ii[h]--;
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:51:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |    scanf("%d%d%d", &l, &r, &m), l--, r--;
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 6 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1364 KB Output is correct
2 Correct 16 ms 1976 KB Output is correct
3 Correct 23 ms 2508 KB Output is correct
4 Correct 40 ms 4392 KB Output is correct
5 Correct 57 ms 6188 KB Output is correct
6 Correct 55 ms 5932 KB Output is correct
7 Correct 58 ms 5904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 3588 KB Output is correct
2 Correct 52 ms 5268 KB Output is correct
3 Correct 83 ms 7508 KB Output is correct
4 Correct 62 ms 6372 KB Output is correct