之前有别人发帖子问过 我印象他被嘲讽为"没好好做功课" 市面上都说是 O(n) 的 具体些是 O(∣S∣+∣T∣) 的 可真的是吗
#include<bits/stdc++.h>
using namespace std;
const int maxn = 600005;
#define endl '\n'
#define art pair<int,int>
#define fir first
#define sec second
string s="$";
....
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
int ans26,ansB;
long long sum=0;
int kmp=0;
for(int i=1;i<=n;i++)
{
char ch;
cin>>ch;
cin>>w[i];
if(i!=1)
{
ch=(ch-'a'+ans)%26+'a';
w[i]^=ansB;
}else
{
ans26=w[1];
ansB=w[1];
}
s+=ch;
....
}
return 0;
}
这是 CF1286E 的洛谷上最优解代码的部分 这题里面 n 是 6e5 的 可以看到他用了 string 加法 为什么没有T? 所以string加法末尾加的复杂度是什么的?我试了一下 c++14 17 20 都能通过