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 <bits/stdc++.h>
using namespace std;
#define int long long
int modulo = 1e9 + 7;
int fact[200005],invfact[200005];
int n,suma,q,p,rep = 1;
int fr[1000005];
int C(int x,int y)
{
return fact[x] * invfact[y] % modulo * invfact[x - y] % modulo;
}
int lgpow(int x,int y)
{
int z = 1;
while (y != 0)
{
if (y % 2 == 1)
z = z * x % modulo;
x = x * x % modulo;
y /= 2;
}
return z;
}
int sb(int x,int y)
{
return C(x + y - 1,y - 1);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fact[0] = invfact[0] = 1;
for (int i = 1; i <= 200000; i++)
{
fact[i] = fact[i - 1] * i % modulo;
invfact[i] = lgpow(fact[i],modulo - 2);
}
cin >> q >> p;
for (int i = 1; i <= q; i++)
{
int x,y;
cin >> x >> y;
if (x == 0)
{
rep *= fact[fr[y]];
rep %= modulo;
fr[y]++;
n++;
suma += y;
rep *= invfact[fr[y]];
rep %= modulo;
}
else
{
rep *= fact[fr[y]];
rep %= modulo;
fr[y]--;
n--;
suma -= y;
rep *= invfact[fr[y]];
rep %= modulo;
}
if (suma > p)
cout << -1 << '\n';
else
cout << fact[n] * sb(p - suma,n + 1) % modulo * rep % modulo << '\n';
}
return 0;
}
# | 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... |