个人感觉 D 比 C 简单。
本题可以用 差分 来做。
题目大意
题目分析
如果你暴力
时间复杂度为 ,直接 TLE。
我们可以使用差分数组来记录翻转操作,然后通过前缀异或来计算每个位置的翻转状态。
代码实现
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int P = 998244353;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6+10, M = 1e8 + 10;
int n,m;
string s,t;
int ch[N];// 差分数组
int cnt=0;
signed main()
{
fst
cin>>n>>m;
cin>>s>>t;
for(int i=1;i<=m;i++){
int l,r;
cin>>l>>r;
ch[l]^=1;// 起点
if(r+1<=n)ch[r+1]^=1;// 终点
}
for(int i=1;i<=n;i++){
cnt^=ch[i];// 当前状态
if(cnt)cout<<t[i-1];
else cout<<s[i-1];
}
return 0;
}