제출 #545936

#제출 시각아이디문제언어결과실행 시간메모리
545936rainboyFancy Fence (CEOI20_fancyfence)C11
100 / 100
66 ms4356 KiB
#include <stdio.h>

#define N	100000
#define MD	1000000007

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int hh[N], ww[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (hh[ii[j]] == hh[i_])
				j++;
			else if (hh[ii[j]] > hh[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int main() {
	static char used[N];
	static int ii[N], ll[N], rr[N];
	int n, i, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &hh[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &ww[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	ans = 0;
	for (i = 0; i < n; i++)
		ll[i] = rr[i] = i;
	for (i = 0; i < n; i++) {
		int i_, h, l, r;

		i_ = ii[i], h = (long long) hh[i_] * (hh[i_] + 1) / 2 % MD;
		used[i_] = 1, ans = (ans + (long long) ww[i_] * (ww[i_] + 1) / 2 % MD * h) % MD;
		l = r = i_;
		if (i_ > 0 && used[i_ - 1]) {
			l = ll[i_ - 1];
			ans = (ans + (long long) ww[l] * ww[i_] % MD * h) % MD, ww[l] = (ww[l] + ww[i_]) % MD;
			rr[l] = r, ll[r] = l;
		}
		if (i_ + 1 < n && used[i_ + 1]) {
			r = rr[i_ + 1];
			ans = (ans + (long long) ww[l] * ww[i_ + 1] % MD * h) % MD, ww[l] = (ww[l] + ww[i_ + 1]) % MD;
			rr[l] = r, ll[r] = l;
		}
	}
	printf("%d\n", ans);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

fancyfence.c: In function 'main':
fancyfence.c:38:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
fancyfence.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", &hh[i]);
      |   ^~~~~~~~~~~~~~~~~~~
fancyfence.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d", &ww[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...