SHARE
TWEET

Untitled

lalalalalalalaalalla Sep 21st, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17.  
  18. /*
  19. #pragma GCC optimize("Ofast,no-stack-protector")
  20. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  21. #pragma GCC optimize("unroll-loops")
  22. #pragma GCC optimize("fast-math")
  23. #pragma GCC optimize("section-anchors")
  24. #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  25. #pragma GCC optimize("vpt")
  26. #pragma GCC optimize("rename-registers")
  27. #pragma GCC optimize("move-loop-invariants")
  28. #pragma GCC optimize("unswitch-loops")
  29. #pragma GCC optimize("function-sections")
  30. #pragma GCC optimize("data-sections")
  31. #pragma GCC optimize("branch-target-load-optimize")
  32. #pragma GCC optimize("branch-target-load-optimize2")
  33. #pragma GCC optimize("btr-bb-exclusive")
  34. */
  35.  
  36. #define int long long
  37. #define ll long long
  38. #define ull unsigned long long
  39. #define all(a) a.begin(), a.end()
  40. #define pii pair<int, int>
  41. #define pb push_back
  42. #define ld long double
  43.  
  44.  
  45. using namespace std;
  46.  
  47. const int INF = 1e13;
  48.  const int mod = 2600000069;
  49.  const int p = 179;
  50.  
  51. ll n, m;
  52. vector<ll> a, h, hr, pw(1000001);
  53.  
  54. inline ll subh(vector<ll>& h, ll l, ll r) {
  55.     ll big = h[r], small = 0;
  56.     if (l > 0) {
  57.         small = (h[l - 1] * pw[r - l + 1]) % mod;
  58.     }
  59.     return (big - small + mod) % mod;
  60. }
  61.  
  62. bool pal(ll ind) {
  63.     //    cout << subh(hr, n - ind, n - 1) << " " << subh(h, ind, ind + ind - 1) << "\n";
  64.     if (subh(hr, n - ind, n - 1) == subh(h, ind, ind + ind - 1)) {
  65.         return true;
  66.     }
  67.     return false;
  68. }
  69.  
  70. signed main() {
  71.     ios_base::sync_with_stdio(0);
  72.     cin.tie(0);
  73.     cout.tie(0);
  74. //    freopen("input.in", "r", stdin);
  75. //    freopen("output.out", "w", stdout);
  76.     cin >> n >> m;
  77.     a.resize(n);
  78.     for (ll i = 0; i < n; i++) {
  79.         cin >> a[i];
  80.     }
  81.     h.resize(n);
  82.     hr.resize(n);
  83.     pw[0] = 1;
  84.     for (ll i = 1; i < 1000001; i++) {
  85.         pw[i] = (pw[i - 1] * p) % mod;
  86.     }
  87.     h[0] = a[0];
  88.     hr[n - 1] = a[n - 1];
  89.     for (ll i = 1; i < n; i++) {
  90.         h[i] = (h[i - 1] * p + a[i]) % mod;
  91.     }
  92.     for (ll i = n - 2; i >= 0; i--) {
  93.         hr[i] = (hr[i + 1] * p + a[i]) % mod;
  94.     }
  95.     reverse(all(hr));
  96.     vector<ll> ans;
  97.     for (int i = 1; i <= n / 2; i++) {
  98.         if (pal(i)) {
  99.             ans.pb(n - i);
  100.         }
  101.     }
  102.     bool ok = true;
  103.     for (int i = 0; i <= n / 2; i++) {
  104.         if (a[i] != a[n - i - 1]) {
  105.             ok = false;
  106.             break;
  107.         }
  108.     }
  109.     reverse(all(ans));
  110.     for (auto x: ans) {
  111.         cout << x << " ";
  112.     }
  113.     cout << n;
  114. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top