Submission #486381

#TimeUsernameProblemLanguageResultExecution timeMemory
486381rainboyŽarulje (COI15_zarulje)C11
60 / 100
1090 ms5328 KiB
#include <stdio.h> #define N 200000 #define MD 1000000007 int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int vv[N + 1], ff[N + 1], gg[N + 1]; void init() { int i; ff[0] = gg[0] = 1; for (i = 1; i <= N; i++) { vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD; ff[i] = (long long) ff[i - 1] * i % MD; gg[i] = (long long) gg[i - 1] * vv[i] % MD; } } int choose(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int aa[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) { int c = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : ii[j] - i_; if (c == 0) j++; else if (c < 0) { 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 int ii[N]; int n, k, h, i, j; init(); scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%d", &aa[i]); ii[i] = i; } sort(ii, 0, n); while (k--) { int l, r, c, ans; scanf("%d", &c), c--; l = 0, r = n - 1, ans = 1; for (i = 0; i < n; i = j) { int l_, r_, kl, kr; j = i + 1; while (j < n && aa[ii[j]] == aa[ii[i]]) j++; l_ = l, r_ = r, kl = kr = 0; for (h = i; h < j; h++) { if (ii[h] == c || ii[h] < l || ii[h] > r) continue; if (ii[h] < c) l_ = max(l_, ii[h] + 1), kl++; if (ii[h] > c) r_ = min(r_, ii[h] - 1), kr++; } ans = (long long) ans * choose(kl + kr, kl) % MD; l = l_, r = r_; } printf("%d\n", ans); } return 0; }

Compilation message (stderr)

zarulje.c: In function 'main':
zarulje.c:61:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
zarulje.c:63:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
zarulje.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d", &c), c--;
      |   ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...