Submission #917176

# Submission time Handle Problem Language Result Execution time Memory
917176 2024-01-27T11:28:04 Z MateiKing80 The grade (info1cup18_thegrade) C++14
100 / 100
144 ms 4296 KB
#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

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
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 119 ms 1444 KB Output is correct
3 Correct 117 ms 1876 KB Output is correct
4 Correct 117 ms 1768 KB Output is correct
5 Correct 117 ms 1392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 126 ms 1876 KB Output is correct
3 Correct 126 ms 1868 KB Output is correct
4 Correct 124 ms 1928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 119 ms 1444 KB Output is correct
7 Correct 117 ms 1876 KB Output is correct
8 Correct 117 ms 1768 KB Output is correct
9 Correct 117 ms 1392 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 126 ms 1876 KB Output is correct
12 Correct 126 ms 1868 KB Output is correct
13 Correct 124 ms 1928 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 119 ms 1852 KB Output is correct
16 Correct 121 ms 1872 KB Output is correct
17 Correct 120 ms 1688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 119 ms 1444 KB Output is correct
3 Correct 117 ms 1876 KB Output is correct
4 Correct 117 ms 1768 KB Output is correct
5 Correct 117 ms 1392 KB Output is correct
6 Correct 135 ms 2768 KB Output is correct
7 Correct 132 ms 2720 KB Output is correct
8 Correct 119 ms 2768 KB Output is correct
9 Correct 124 ms 2664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 126 ms 1876 KB Output is correct
3 Correct 126 ms 1868 KB Output is correct
4 Correct 124 ms 1928 KB Output is correct
5 Correct 94 ms 2504 KB Output is correct
6 Correct 100 ms 3020 KB Output is correct
7 Correct 133 ms 4296 KB Output is correct
8 Correct 88 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 119 ms 1444 KB Output is correct
7 Correct 117 ms 1876 KB Output is correct
8 Correct 117 ms 1768 KB Output is correct
9 Correct 117 ms 1392 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 126 ms 1876 KB Output is correct
12 Correct 126 ms 1868 KB Output is correct
13 Correct 124 ms 1928 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 119 ms 1852 KB Output is correct
16 Correct 121 ms 1872 KB Output is correct
17 Correct 120 ms 1688 KB Output is correct
18 Correct 135 ms 2768 KB Output is correct
19 Correct 132 ms 2720 KB Output is correct
20 Correct 119 ms 2768 KB Output is correct
21 Correct 124 ms 2664 KB Output is correct
22 Correct 94 ms 2504 KB Output is correct
23 Correct 100 ms 3020 KB Output is correct
24 Correct 133 ms 4296 KB Output is correct
25 Correct 88 ms 2512 KB Output is correct
26 Correct 138 ms 3216 KB Output is correct
27 Correct 135 ms 2864 KB Output is correct
28 Correct 142 ms 2768 KB Output is correct
29 Correct 144 ms 3308 KB Output is correct
30 Correct 136 ms 2828 KB Output is correct