专栏文章
题解:AT_abc419_d [ABC419D] Substr Swap
AT_abc419_d题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mio4tb5t
- 此快照首次捕获于
- 2025/12/02 13:22 3 个月前
- 此快照最后确认于
- 2025/12/02 13:22 3 个月前
AT_abc419_d [ABC419D] Substr Swap
题意
有 两个字符串,每次交换 的 ,求最后的 。
题解
发现对于每一个位置,交换偶数次就相当于没有交换,所以只需要知道每个位置被交换过几次。
问题就转换成了区间加,通过差分实现即可。
代码
CPP#include<bits/stdc++.h>
#define int long long
#define double long double
#define bug cout<<"___songge888___"<<'\n';
using namespace std;
int n,m;
string s,t;
int cha[500010];
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
cin>>s>>t;
while(m--){
int l,r;
cin>>l>>r;
cha[l]++;
cha[r+1]--;
}
for(int i=1;i<=n;i++){
cha[i]+=cha[i-1];
if(cha[i]%2==0){
cout<<s[i-1];
}
else{
cout<<t[i-1];
}
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...