Submission #674144

#TimeUsernameProblemLanguageResultExecution timeMemory
674144QwertyPiThe grade (info1cup18_thegrade)C++14
100 / 100
229 ms11164 KiB
#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)

thegrade.cpp: In function 'int32_t main()':
thegrade.cpp:22:31: warning: unused variable 'k' [-Wunused-variable]
   22 |  int q, e; cin >> q >> e; int k = 0;
      |                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...