# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
674144 | QwertyPi | The grade (info1cup18_thegrade) | C++14 | 229 ms | 11164 KiB |
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>
#define int long long
#define fi first
#define se second
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 11;
int pm(int a, int b){
return b == 0 ? 1 : pm(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD;
}
int mi(int a){
return pm(a, MOD - 2);
}
map<int, int> M; int s = 0;
int f[MAXN];
int32_t main(){
f[0] = 1; for(int i = 1; i < MAXN; i++) f[i] = f[i - 1] * i % MOD;
int q, e; cin >> q >> e; int k = 0;
int mul = 1;
for(int i = 0; i < q; i++){
int t, v; cin >> t >> v;
if(t == 0){
M[v]++; s++; e -= v;
mul = mul * mi(M[v]) % MOD;
}else{
mul = mul * M[v] % MOD;
M[v]--; s--; e += v;
}
if(e < 0){
cout << -1 << endl;
}else{
cout << f[s + e] * mul % MOD * mi(f[e]) % MOD << endl;
}
}
}
Compilation message (stderr)
# | 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... |