답안 #557023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557023 2022-05-04T14:56:15 Z rainboy Sterilizing Spray (JOI15_sterilizing) C
5 / 100
5000 ms 5324 KB
#include <stdio.h>

#define N	100000
#define N_	(1 << 17)	/* N_ = pow2(ceil(log2(N))) */

long long st[N_ * 2]; int n_, d;

void pul(int i) {
	st[i] = st[i << 1 | 0] + st[i << 1 | 1];
}

void build(int *aa, int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 0; i < n; i++)
		st[n_ + i] = aa[i];
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void upd(int i, int x) {
	i += n_;
	st[i] = x;
	while (i > 1)
		pul(i >>= 1);
}

void update_(int i) {
	if (st[i] == 0)
		return;
	if (i >= n_) {
		st[i] /= d;
		return;
	}
	update_(i << 1 | 0), update_(i << 1 | 1);
	pul(i);
}

void update(int l, int r) {
	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			update_(l++);
		if ((r & 1) == 0)
			update_(r--);
	}
}

long long query(int l, int r) {
	long long x = 0;

	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			x += st[l++];
		if ((r & 1) == 0)
			x += st[r--];
	}
	return x;
}

int main() {
	static int aa[N];
	int n, q, i;

	scanf("%d%d%d", &n, &q, &d);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	build(aa, n);
	while (q--) {
		int t, x, l, r;

		scanf("%d", &t);
		if (t == 1) {
			scanf("%d%d", &i, &x), i--;
			upd(i, x);
			aa[i] = x;
		} else {
			scanf("%d%d", &l, &r), l--, r--;
			if (t == 2) {
				if (d > 1)
					update(l, r);
				for (i = l; i <= r; i++)
					aa[i] /= d;
			} else {
				long long sum;

				sum = 0;
				for (i = l; i <= r; i++)
					sum += aa[i];
				printf("%lld\n", sum);
			}
		}
	}
	return 0;
}

Compilation message

sterilizing.c: In function 'main':
sterilizing.c:67:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  scanf("%d%d%d", &n, &q, &d);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.c:69:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
sterilizing.c:74:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
sterilizing.c:76:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |    scanf("%d%d", &i, &x), i--;
      |    ^~~~~~~~~~~~~~~~~~~~~
sterilizing.c:80:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |    scanf("%d%d", &l, &r), l--, r--;
      |    ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 8 ms 444 KB Output is correct
6 Correct 8 ms 436 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 8 ms 444 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4014 ms 1772 KB Output is correct
2 Correct 2449 ms 1592 KB Output is correct
3 Correct 4037 ms 2604 KB Output is correct
4 Execution timed out 5043 ms 2968 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 460 KB Output is correct
2 Correct 327 ms 1556 KB Output is correct
3 Correct 505 ms 1692 KB Output is correct
4 Correct 1141 ms 2096 KB Output is correct
5 Correct 4703 ms 4156 KB Output is correct
6 Correct 4647 ms 4152 KB Output is correct
7 Correct 4712 ms 4140 KB Output is correct
8 Correct 4731 ms 4020 KB Output is correct
9 Execution timed out 5053 ms 3108 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1768 ms 1604 KB Output is correct
2 Correct 2035 ms 3316 KB Output is correct
3 Correct 1138 ms 2624 KB Output is correct
4 Correct 1567 ms 2840 KB Output is correct
5 Correct 4830 ms 5324 KB Output is correct
6 Correct 4814 ms 5160 KB Output is correct
7 Correct 4829 ms 5188 KB Output is correct
8 Correct 4801 ms 5208 KB Output is correct
9 Execution timed out 5084 ms 4016 KB Time limit exceeded
10 Halted 0 ms 0 KB -