# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
882223 | rainboy | The grade (info1cup18_thegrade) | C11 | 32 ms | 5200 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |