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;
using ll = long long;
#define int ll
const int mod = 1e9 + 7;
map<int, int> umap;
vector<int> fact;
int lgpow(int b, int e)
{
if(e == 0)
return 1;
int x = lgpow(b, e / 2);
if((e % 2) == 1)
return (((x * x) % mod) * b) % mod;
return (x * x) % mod;
}
int inv(int x)
{
return lgpow(x, mod - 2);
}
int fct(int x)
{
while(x >= fact.size())
fact.push_back((fact.back() * fact.size()) % mod);
return fact[x];
}
int comb(int k, int n)
{
if(k < 0 || n < k)
return 0;
return ((fct(n) * inv(fct(k))) % mod * inv(fct(n - k))) % mod;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fact.push_back(1);
int q, p, ori = 1, sum = 0, nr = 0;
cin >> q >> p;
for(int i = 0; i < q; i ++)
{
int t, x;
cin >> t >> x;
if(!t)
{
nr ++;
umap[x] ++;
sum += x;
ori *= fct(umap[x]), ori %= mod;
ori *= inv(fct(umap[x] - 1)), ori %= mod;
}
else
{
nr --;
umap[x] --;
sum -= x;
ori *= fct(umap[x]), ori %= mod;
ori *= inv(fct(umap[x] + 1)), ori %= mod;
}
//nr + 1 locuri, p - sum 0-uri
if(!comb(nr, nr + p - sum))
cout << -1 << '\n';
else
cout << ((comb(nr, nr + p - sum) * inv(ori)) % mod * fct(nr)) % mod << '\n';
}
return 0;
}
Compilation message (stderr)
thegrade.cpp: In function 'll fct(ll)':
thegrade.cpp:30:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | while(x >= fact.size())
| ~~^~~~~~~~~~~~~~
# | 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... |