P6114 Lyndon 分解【模板】

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
string s;
int main(){
    ios::sync_with_stdio(false);
    int ans=0;
    cin>>s;
    int n=s.size();
    s=" "+s;
    int i;
    for(i=1;i<=n;){
        int j=i;
        int k=i+1;
        while(k<=n&&s[j]<=s[k]){
            if(s[j]<s[k]){
                j=i;
            }
            else j++;
            k++;
        }
        while(i<=j){
            ans^=i+k-j-1;
            i+=k-j;
        }
    }
    cout<<ans<<endl;
}
View Code

 

posted @ 2020-07-27 09:53  朝暮不思  阅读(71)  评论(0编辑  收藏  举报