- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <random>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- #define AboTaha_on_da_code ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- #define X first
- #define Y second
- const int dx[8]={0, 0, 1, -1, 1, -1, -1, 1};
- const int dy[8]={1, -1, 0, 0, 1, -1, 1, -1};
- const double EPS = 1e-8;
- const int mod = 1e9+7; // 1e9+7, 998244353
- const int phi = 1e9+6; // 1e9+7, 998244353
- // BEFORE coding are you sure you understood the statement correctly?
- // PLEASE do not forget to read the sample explanation carefully.
- // WATCH out for overflows & RTs in general.
- // TEST your idea or code on the corner cases.
- // ANALYZE each idea you have thoroughly.
- const int M = 1e5+10;
- vector <int> pos[M];
- void burn(int tc) {
- int n, m, k; cin >> n >> m >> k;
- vector <int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i], a[i]%=m;
- pos[a[i]].push_back(i);
- }
- vector <int> nxt(n, -1);
- set <int> done;
- for (int i = 0; i < n; i++) {
- if (done.count(a[i])) continue;
- done.insert(a[i]);
- for (int j = 1; j < pos[a[i]].size(); j++) {
- nxt[pos[a[i]][j-1]] = pos[a[i]][j];
- }
- }
- vector <vector <int>> dp(n, vector <int> (k+1, 0));
- int sm = 0;
- for (int i = 0; i < n; i++) {
- dp[i][1] += 1+sm;
- if (dp[i][1] >= mod) dp[i][1]-=mod;
- for (int j = 1; j < k; j++) {
- if (~nxt[i]) {
- dp[nxt[i]][j+1]+=dp[i][j];
- dp[nxt[i]][j]+=dp[i][j];
- if (dp[nxt[i]][j+1] >= mod) dp[nxt[i]][j+1]-=mod;
- if (dp[nxt[i]][j] >= mod) dp[nxt[i]][j]-=mod;
- }
- }
- sm+=dp[i][k];
- if (sm >= mod) sm-=mod;
- }
- cout << sm;
- for (int i = 0; i < n; i++) {
- pos[a[i]].pop_back();
- }
- }
- int main()
- {
- AboTaha_on_da_code
- freopen("fortune.in", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int T = 1; cin >> T;
- for (int i = 1; i <= T; i++) {
- // cout << "Case " << i << ": ";
- burn(i);
- cout << '\n';
- }
- return (0-0);
- }
[text] j
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: