Submission #239053

#TimeUsernameProblemLanguageResultExecution timeMemory
239053ne4eHbKaMate (COCI18_mate)C++17
100 / 100
1304 ms35076 KiB
#include <bits/stdc++.h> using namespace std; #define ft first #define sd second const int N = 2020; const int A = 26; const int md = 1e9 + 7; const int Q = 5e5 + 5; void madd(int &a, int b) {a += b; while(a < 0) a += md; while(a >= md) a -= md;} int msum(int a, int b) {a += b; while(a < 0) a += md; while(a >= md) a -= md; return a;} void mmul(int &a, int b) {a = 1ll * a * b % md;} int mpro(int a, int b) {return 1ll * a * b % md;} int mpow(int a, int p) { int ans = 1; for(int i = 1 << 30; i; i >>= 1) { mmul(ans, ans); if(p & i) mmul(ans, a); } return ans; } int n, q; string s; int t[Q]; char x[Q], y[Q]; int fact[N], ifact[N]; int C(int n, int k) {return mpro(mpro(ifact[k], ifact[n - k]), fact[n]);} struct z { map<int, int> u; vector<int> c, g, f; int n; void add(int i, bool r) { u[i] += r; } void init() { n = u.size(); c.resize(n); g.resize(n); f.resize(n); int i = 0; for(const auto &j : u) { c[i] = j.ft; g[i] = j.sd; f[i++] = 0; } for(int i = 0; i < n; ++i) for(int j = i; j < n; ++j) if(g[j]) madd(f[i], mpro(g[j], C(c[j], c[i]))); } int get(int x) { return f[lower_bound(c.begin(), c.end(), x) - c.begin()]; } } f[A][A]; int main() { #ifdef _LOCAL freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); for(int i = 0; i < N; ++i) fact[i] = !i ? 1 : mpro(fact[i - 1], i); for(int i = 0; i < N; ++i) ifact[i] = mpow(fact[i], md - 2); cin >> s >> q; n = s.size(); for(int j = 0; j < n; ++j) for(int i = 0; i < j; ++i) f[s[i] - 'a'][s[j] - 'a'].add(i, true); for(int i = 0; i < q; ++i) { cin >> t[i] >> x[i] >> y[i]; t[i] -= 2, x[i] -= 'a', y[i] -= 'a'; f[x[i]][y[i]].add(t[i], false); } for(int i = 0; i < A; ++i) for(int j = 0; j < A; ++j) f[i][j].init(); for(int i = 0; i < q; ++i) cout << f[x[i]][y[i]].get(t[i]) << '\n'; }

Compilation message (stderr)

mate.cpp: In function 'int main()':
mate.cpp:83:15: warning: array subscript has type 'char' [-Wchar-subscripts]
         f[x[i]][y[i]].add(t[i], false);
               ^
mate.cpp:83:21: warning: array subscript has type 'char' [-Wchar-subscripts]
         f[x[i]][y[i]].add(t[i], false);
                     ^
mate.cpp:91:23: warning: array subscript has type 'char' [-Wchar-subscripts]
         cout << f[x[i]][y[i]].get(t[i]) << '\n';
                       ^
mate.cpp:91:29: warning: array subscript has type 'char' [-Wchar-subscripts]
         cout << f[x[i]][y[i]].get(t[i]) << '\n';
                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...