Submission #363929

# Submission time Handle Problem Language Result Execution time Memory
363929 2021-02-07T14:26:09 Z ogibogi2004 The grade (info1cup18_thegrade) C++14
100 / 100
410 ms 10476 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=1e6+6;
const ll mod=1e9+7;
ll fastpow(ll x,ll p)
{
	if(p==0)return 1;
	ll t=fastpow(x,p/2);
	t*=t;t%=mod;
	if(p%2==1)t*=x;
	t%=mod;return t;
}
ll inv(ll x)
{
	return fastpow(x,mod-2);
}
ll fact[MAXN];
ll cnt[MAXN],bigX=1,cntall,sum;
ll comb(ll n,ll k)
{
	if(k>n)return 0;
	ll ret=fact[n];
	ret*=inv(fact[k]);
	ret%=mod;
	ret*=inv(fact[n-k]);
	ret%=mod;
	return ret;
}
void add(ll x)
{
	cntall++;sum+=x;
	bigX*=cntall;
	bigX%=mod;
	cnt[x]++;
	bigX*=inv(cnt[x]);
	bigX%=mod;
}
void remove(ll x)
{
	bigX*=inv(cntall);
	bigX%=mod;sum-=x;
	cntall--;
	bigX*=cnt[x];
	bigX%=mod;
	cnt[x]--;
}
ll q,p;
ll calc()
{
	ll ret=1;
	ret=comb(cntall+p-sum,p-sum);
	ret*=bigX;
	ret%=mod;
	if(ret==0)return -1;
	return ret;
}
void precompute()
{
	fact[0]=1;
	for(ll i=1;i<MAXN;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
	}
}
int main()
{
	precompute();
	cin>>q>>p;
	for(int i=0;i<q;i++)
	{
		int type,x;
		cin>>type>>x;
		if(type==1)remove(x);
		else add(x);
		cout<<calc()<<endl;
	}
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8172 KB Output is correct
2 Correct 12 ms 8172 KB Output is correct
3 Correct 13 ms 8172 KB Output is correct
4 Correct 14 ms 8172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 8172 KB Output is correct
2 Correct 367 ms 9324 KB Output is correct
3 Correct 394 ms 9964 KB Output is correct
4 Correct 382 ms 9588 KB Output is correct
5 Correct 388 ms 9320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8300 KB Output is correct
2 Correct 389 ms 9836 KB Output is correct
3 Correct 410 ms 9708 KB Output is correct
4 Correct 383 ms 9580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8172 KB Output is correct
2 Correct 12 ms 8172 KB Output is correct
3 Correct 13 ms 8172 KB Output is correct
4 Correct 14 ms 8172 KB Output is correct
5 Correct 20 ms 8172 KB Output is correct
6 Correct 367 ms 9324 KB Output is correct
7 Correct 394 ms 9964 KB Output is correct
8 Correct 382 ms 9588 KB Output is correct
9 Correct 388 ms 9320 KB Output is correct
10 Correct 23 ms 8300 KB Output is correct
11 Correct 389 ms 9836 KB Output is correct
12 Correct 410 ms 9708 KB Output is correct
13 Correct 383 ms 9580 KB Output is correct
14 Correct 23 ms 8172 KB Output is correct
15 Correct 378 ms 9580 KB Output is correct
16 Correct 367 ms 9580 KB Output is correct
17 Correct 369 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 8172 KB Output is correct
2 Correct 367 ms 9324 KB Output is correct
3 Correct 394 ms 9964 KB Output is correct
4 Correct 382 ms 9588 KB Output is correct
5 Correct 388 ms 9320 KB Output is correct
6 Correct 368 ms 9708 KB Output is correct
7 Correct 371 ms 9708 KB Output is correct
8 Correct 380 ms 9836 KB Output is correct
9 Correct 404 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8300 KB Output is correct
2 Correct 389 ms 9836 KB Output is correct
3 Correct 410 ms 9708 KB Output is correct
4 Correct 383 ms 9580 KB Output is correct
5 Correct 386 ms 10220 KB Output is correct
6 Correct 383 ms 10220 KB Output is correct
7 Correct 397 ms 10476 KB Output is correct
8 Correct 395 ms 10092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8172 KB Output is correct
2 Correct 12 ms 8172 KB Output is correct
3 Correct 13 ms 8172 KB Output is correct
4 Correct 14 ms 8172 KB Output is correct
5 Correct 20 ms 8172 KB Output is correct
6 Correct 367 ms 9324 KB Output is correct
7 Correct 394 ms 9964 KB Output is correct
8 Correct 382 ms 9588 KB Output is correct
9 Correct 388 ms 9320 KB Output is correct
10 Correct 23 ms 8300 KB Output is correct
11 Correct 389 ms 9836 KB Output is correct
12 Correct 410 ms 9708 KB Output is correct
13 Correct 383 ms 9580 KB Output is correct
14 Correct 23 ms 8172 KB Output is correct
15 Correct 378 ms 9580 KB Output is correct
16 Correct 367 ms 9580 KB Output is correct
17 Correct 369 ms 9708 KB Output is correct
18 Correct 368 ms 9708 KB Output is correct
19 Correct 371 ms 9708 KB Output is correct
20 Correct 380 ms 9836 KB Output is correct
21 Correct 404 ms 9708 KB Output is correct
22 Correct 386 ms 10220 KB Output is correct
23 Correct 383 ms 10220 KB Output is correct
24 Correct 397 ms 10476 KB Output is correct
25 Correct 395 ms 10092 KB Output is correct
26 Correct 373 ms 9964 KB Output is correct
27 Correct 376 ms 9836 KB Output is correct
28 Correct 367 ms 9708 KB Output is correct
29 Correct 374 ms 9836 KB Output is correct
30 Correct 370 ms 9708 KB Output is correct