有没有大佬帮我看看这篇代码的复杂度
#include<bits/stdc++.h>
using namespace std;
char s[2000050];
long long dp[2000050],to[2000050];
long long ans=0;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
cin>>s+1;
for (int i=1;i<=n;i++)dp[i]=1;
dp[0]=1;
for (int i=1;i<n;i++)
{
if (!to[i]){
stack<pair<char,int> >q;
q.push(make_pair(s[i],i));
int j;
for (j=i+1;j<=n;j++)
{
if (s[j]==q.top().first)
{
to[q.top().second]=j;
q.pop();
}
else
{
if (to[j])
{
j=to[j];
continue;
}
q.push(make_pair(s[j],j));
}
if (q.empty())break;
}
}
if (to[i])
{
dp[to[i]]+=dp[i-1];
ans+=dp[i-1];
}
}
cout<<ans;
return 0;
}