Advertisement
pb_jiang

ARC077B TLE

Dec 1st, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. // Problem: D - 11
  2. // Contest: AtCoder - AtCoder Beginner Contest 066
  3. // URL: https://atcoder.jp/contests/abc066/tasks/arc077_b
  4. // Memory Limit: 256 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  13. template <typename... Args> void logger(string vars, Args &&... values)
  14. {
  15.     cerr << vars << " = ";
  16.     string delim = "";
  17.     (..., (cerr << delim << values, delim = ", "));
  18.     cerr << endl;
  19. }
  20.  
  21. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  22. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  23. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  24. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  25.  
  26. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  27. using vi = vector<int>;
  28. using ll = long long;
  29. using pii = pair<int, int>;
  30.  
  31. int main(int argc, char **argv)
  32. {
  33.     int n;
  34.     cin >> n;
  35.     vi a(n + 1);
  36.     map<int, int> cnt;
  37.     int last_seg = 0;
  38.     int first_seg = 0;
  39.     for (int i = 0; i <= n; ++i) {
  40.         cin >> a[i];
  41.         if (cnt.count(a[i])) {
  42.             first_seg = cnt[a[i]];
  43.             last_seg = n - i;
  44.         }
  45.         // cnt.insert(a[i]);
  46.         cnt[a[i]] = i;
  47.     }
  48.     last_seg += first_seg;
  49.     dbg(last_seg);
  50.  
  51.     const int mod = int(1e9) + 7;
  52.     vi cnp1(n + 3), cnm1(n);
  53.     cnp1[0] = 1;
  54.     for (int i = 1; i < n; ++i)
  55.         for (int j = i; j > 0; --j)
  56.             cnp1[j] = (cnp1[j] + cnp1[j - 1]) % mod;
  57.     cnm1 = cnp1;
  58.     for (int j = n; j > 0; --j)
  59.         cnp1[j] = (cnp1[j] + cnp1[j - 1]) % mod;
  60.     for (int j = n + 1; j > 0; --j)
  61.         cnp1[j] = (cnp1[j] + cnp1[j - 1]) % mod;
  62.  
  63.     int k = n + 1;
  64.     vi dup(k + 1), no_dup(k + 1);
  65.     dup[1] = 0, dup[2] = 1;
  66.     auto comb = [last_seg, mod](int n, int r) {
  67.         static vi f(last_seg + 1);
  68.         if (f[0] == 0) {
  69.             f[0] = 1;
  70.             for (int i = 1; i <= last_seg; ++i)
  71.                 for (int j = i; j > 0; --j)
  72.                     f[j] = (f[j] + f[j - 1]) % mod;
  73.         }
  74.         return r <= last_seg ? f[r] : 0;
  75.     };
  76.     for (int i = 1; i <= k; ++i) {
  77.         dup[i] = (i <= 2 ? i - 1 : cnm1[i - 2]);
  78.         int repeat = comb(last_seg, i - 1);
  79.         no_dup[i] = ((ll(cnp1[i]) - dup[i] - repeat) % mod + mod) % mod;
  80.         // dbg(i, dup[i], no_dup[i], repeat);
  81.         cout << (ll(dup[i]) + no_dup[i] + mod) % mod << endl;
  82.     }
  83.     return 0;
  84. };
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement