# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
283854 | 2020-08-26T08:11:11 Z | 송준혁(#5751) | Žarulje (COI15_zarulje) | C++17 | 236 ms | 58232 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define MOD 1'000'000'007 using namespace std; typedef long long LL; typedef pair<int,int> pii; int N, Q; int A[202020], L[202020], R[202020], cnt[202020]; LL F[202020], I[202020], ans[202020], C; map<int,int> LC[202020], RC[202020]; vector<int> st; LL Pow(LL x, LL y){ if (y == 0) return 1; LL z = Pow(x, y/2); if (y & 1) return z * z % MOD * x % MOD; return z * z % MOD; } int main(){ scanf("%d %d", &N, &Q); F[0] = I[0] = 1; for (int i=1; i<=N; i++){ scanf("%d", &A[i]); F[i] = F[i-1] * i % MOD; I[i] = Pow(F[i], MOD-2); } st.pb(0); for (int i=1; i<=N; i++){ while (st.back() > A[i]) LC[i][st.back()]=cnt[st.back()], cnt[st.back()]=0, st.pop_back(); L[i] = cnt[A[i]], cnt[A[i]]++; if (st.back() != A[i]) st.push_back(A[i]); } while(st.size()) cnt[st.back()]=0, st.pop_back(); st.pb(0); for (int i=N; i>0; i--){ while (st.back() > A[i]) RC[i][st.back()]=cnt[st.back()], cnt[st.back()]=0, st.pop_back(); R[i] = cnt[A[i]], cnt[A[i]]++; if (st.back() != A[i]) st.push_back(A[i]); } while(st.size()) cnt[st.back()]=0, st.pop_back(); ans[1] = C = 1; for (int i=2; i<=N; i++){ C = C * I[L[i-1]+R[i-1]] % MOD * F[L[i-1]] % MOD; C = C * F[L[i-1]+R[i-1]+1] % MOD * I[L[i-1]+1] % MOD; C = C * I[L[i]+R[i]+1] % MOD * F[R[i]+1] % MOD; C = C * F[L[i]+R[i]] % MOD * I[R[i]] % MOD; ans[i] = C; for (pii t : LC[i]) ans[i] = ans[i] * F[t.se+RC[i][t.fi]] % MOD * I[t.se] % MOD * I[RC[i][t.fi]] % MOD; } while (Q--){ int t; scanf("%d", &t); printf("%lld\n", ans[t]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 19328 KB | Output is correct |
2 | Correct | 16 ms | 19456 KB | Output is correct |
3 | Correct | 17 ms | 19584 KB | Output is correct |
4 | Correct | 15 ms | 19624 KB | Output is correct |
5 | Correct | 18 ms | 19712 KB | Output is correct |
6 | Correct | 18 ms | 19712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 98 ms | 37156 KB | Output is correct |
2 | Correct | 151 ms | 45432 KB | Output is correct |
3 | Correct | 180 ms | 53344 KB | Output is correct |
4 | Correct | 176 ms | 55032 KB | Output is correct |
5 | Correct | 189 ms | 55424 KB | Output is correct |
6 | Correct | 186 ms | 56060 KB | Output is correct |
7 | Correct | 191 ms | 56568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 19328 KB | Output is correct |
2 | Correct | 16 ms | 19456 KB | Output is correct |
3 | Correct | 17 ms | 19584 KB | Output is correct |
4 | Correct | 15 ms | 19624 KB | Output is correct |
5 | Correct | 18 ms | 19712 KB | Output is correct |
6 | Correct | 18 ms | 19712 KB | Output is correct |
7 | Correct | 98 ms | 37156 KB | Output is correct |
8 | Correct | 151 ms | 45432 KB | Output is correct |
9 | Correct | 180 ms | 53344 KB | Output is correct |
10 | Correct | 176 ms | 55032 KB | Output is correct |
11 | Correct | 189 ms | 55424 KB | Output is correct |
12 | Correct | 186 ms | 56060 KB | Output is correct |
13 | Correct | 191 ms | 56568 KB | Output is correct |
14 | Correct | 27 ms | 21120 KB | Output is correct |
15 | Correct | 123 ms | 38652 KB | Output is correct |
16 | Correct | 205 ms | 48632 KB | Output is correct |
17 | Correct | 222 ms | 54904 KB | Output is correct |
18 | Correct | 233 ms | 58200 KB | Output is correct |
19 | Correct | 211 ms | 56696 KB | Output is correct |
20 | Correct | 231 ms | 57724 KB | Output is correct |
21 | Correct | 236 ms | 58232 KB | Output is correct |