답안 #915841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915841 2024-01-24T18:58:03 Z andrei_iorgulescu The grade (info1cup18_thegrade) C++14
100 / 100
103 ms 7252 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 5052 KB Output is correct
2 Correct 78 ms 5024 KB Output is correct
3 Correct 78 ms 4948 KB Output is correct
4 Correct 78 ms 4812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 4944 KB Output is correct
2 Correct 95 ms 5972 KB Output is correct
3 Correct 98 ms 6488 KB Output is correct
4 Correct 96 ms 6224 KB Output is correct
5 Correct 97 ms 5972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 5200 KB Output is correct
2 Correct 97 ms 6480 KB Output is correct
3 Correct 96 ms 6356 KB Output is correct
4 Correct 97 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 5052 KB Output is correct
2 Correct 78 ms 5024 KB Output is correct
3 Correct 78 ms 4948 KB Output is correct
4 Correct 78 ms 4812 KB Output is correct
5 Correct 78 ms 4944 KB Output is correct
6 Correct 95 ms 5972 KB Output is correct
7 Correct 98 ms 6488 KB Output is correct
8 Correct 96 ms 6224 KB Output is correct
9 Correct 97 ms 5972 KB Output is correct
10 Correct 78 ms 5200 KB Output is correct
11 Correct 97 ms 6480 KB Output is correct
12 Correct 96 ms 6356 KB Output is correct
13 Correct 97 ms 6484 KB Output is correct
14 Correct 78 ms 4944 KB Output is correct
15 Correct 96 ms 6228 KB Output is correct
16 Correct 96 ms 6228 KB Output is correct
17 Correct 97 ms 6352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 4944 KB Output is correct
2 Correct 95 ms 5972 KB Output is correct
3 Correct 98 ms 6488 KB Output is correct
4 Correct 96 ms 6224 KB Output is correct
5 Correct 97 ms 5972 KB Output is correct
6 Correct 97 ms 6352 KB Output is correct
7 Correct 98 ms 6356 KB Output is correct
8 Correct 97 ms 6412 KB Output is correct
9 Correct 97 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 5200 KB Output is correct
2 Correct 97 ms 6480 KB Output is correct
3 Correct 96 ms 6356 KB Output is correct
4 Correct 97 ms 6484 KB Output is correct
5 Correct 97 ms 7108 KB Output is correct
6 Correct 96 ms 6992 KB Output is correct
7 Correct 98 ms 7252 KB Output is correct
8 Correct 97 ms 6864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 5052 KB Output is correct
2 Correct 78 ms 5024 KB Output is correct
3 Correct 78 ms 4948 KB Output is correct
4 Correct 78 ms 4812 KB Output is correct
5 Correct 78 ms 4944 KB Output is correct
6 Correct 95 ms 5972 KB Output is correct
7 Correct 98 ms 6488 KB Output is correct
8 Correct 96 ms 6224 KB Output is correct
9 Correct 97 ms 5972 KB Output is correct
10 Correct 78 ms 5200 KB Output is correct
11 Correct 97 ms 6480 KB Output is correct
12 Correct 96 ms 6356 KB Output is correct
13 Correct 97 ms 6484 KB Output is correct
14 Correct 78 ms 4944 KB Output is correct
15 Correct 96 ms 6228 KB Output is correct
16 Correct 96 ms 6228 KB Output is correct
17 Correct 97 ms 6352 KB Output is correct
18 Correct 97 ms 6352 KB Output is correct
19 Correct 98 ms 6356 KB Output is correct
20 Correct 97 ms 6412 KB Output is correct
21 Correct 97 ms 6480 KB Output is correct
22 Correct 97 ms 7108 KB Output is correct
23 Correct 96 ms 6992 KB Output is correct
24 Correct 98 ms 7252 KB Output is correct
25 Correct 97 ms 6864 KB Output is correct
26 Correct 99 ms 6592 KB Output is correct
27 Correct 98 ms 6360 KB Output is correct
28 Correct 97 ms 6484 KB Output is correct
29 Correct 103 ms 6480 KB Output is correct
30 Correct 100 ms 6436 KB Output is correct