Submission #882223

#TimeUsernameProblemLanguageResultExecution timeMemory
882223rainboyThe grade (info1cup18_thegrade)C11
100 / 100
32 ms5200 KiB
#include <stdio.h>

#define N	100000
#define A	1000000
#define MD	1000000007

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 main() {
	static int kk[A + 1];
	int n, q, cnt, v;
	long long sum;

	init();
	scanf("%d%d", &q, &n);
	cnt = 0, sum = 0, v = 1;
	while (q--) {
		int t, a;

		scanf("%d%d", &t, &a);
		if (t == 0)
			cnt++, sum += a, v = (long long) v * vv[++kk[a]] % MD;
		else
			cnt--, sum -= a, v = (long long) v * kk[a]-- % MD;
		printf("%lld\n", sum > n ? -1 : (long long) ff[n - sum + cnt] * gg[n - sum] % MD * v % MD);
	}
	return 0;
}

Compilation message (stderr)

thegrade.c: In function 'main':
thegrade.c:26:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%d", &q, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
thegrade.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d%d", &t, &a);
      |   ^~~~~~~~~~~~~~~~~~~~~
#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...