Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n,why;
- vector <int> S;
- vector <int> ans;
- vector <int> m;
- void mnk(){
- n = S.size();
- m.resize(n,0);
- //cout<<"S\n";
- //cv(S);
- pii lr = {-1, -1};
- pii now;
- for (int i = 0; i < n;++i){
- int l = lr.first, r = lr.second;
- if (i >= l && i <= r){
- int idx = l + (r - i);
- m[i] = min(r - i + 1, m[idx]);
- }
- while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
- ++m[i];
- }
- now = {i - m[i] + 1, i + m[i] - 1};
- if (now.second > lr.second){
- lr = now;
- }
- }
- //cout<<"m\n";
- //cv(m);
- int k=-1;
- for (int i = 0; i < n; i+=2){
- if (i - m[i] == -1){
- k = (n - i) / 2;
- ans.push_back(k);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>why;
- S = {0};
- for (int i=0;i<n;++i) {
- int x;
- cin>>x;
- S.push_back(x);
- S.push_back(0);
- }
- mnk();
- sort(ans.begin(), ans.end());
- //cout<<"ans\n";
- cv(ans);
- }
- /*
- 6 2
- 1 1 2 2 1 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement