Night_sea_64 @ 2024-10-02 18:37:01
C,不是B2。
思路就是按
/*
-
---
------
--------
------------
-----------------
|
v
-
--
---
--
----
-----
*/
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,d[200010],cur,b[200010],nxt[200010];
string s,t;
struct node{int l,r;}a[200010];
bool operator<(const node &x,const node &y){
return x.l<y.l;
}
vector<int>v[200010];
int main()
{
cin>>n>>m>>s>>t;
s=' '+s,t=' '+t;
for(int i=1;i<=m;i++)
cin>>a[i].l>>a[i].r;
sort(a+1,a+m+1);
for(int i=1;i<=n;i++)
if(s[i]!=t[i])nxt[b[cur]]=i,b[++cur]=i;
nxt[b[cur]]=1e9;
for(int i=1;i<=m;i++)
{
a[i].l=lower_bound(b+1,b+cur+1,a[i].l)-b;
a[i].r=upper_bound(b+1,b+cur+1,a[i].r)-b-1;
if(a[i].l<=a[i].r)v[b[a[i].l]].push_back(b[a[i].r]);
}
for(int i=1;i<=n;i++)
{
random_shuffle(v[i].begin(),v[i].end());
sort(v[i].begin(),v[i].end());
d[i]+=d[i-1];
for(int j=1;j<v[i].size();j++)
{
int now=nxt[v[i][j-1]];
if(now<=v[i][j])v[now].push_back(v[i][j]);
}
if(v[i].size()>0)
{
char now;
if(d[i]%2)now=t[i];
else now=s[i];
if(now=='0')d[i]++,d[v[i][0]+1]--;
}
v[i].clear();
}
for(int i=1;i<=n;i++)
if(d[i]%2)cout<<t[i];
else cout<<s[i];
cout<<endl;
return 0;
}
by elbissoPtImaerD @ 2024-10-02 18:39:29
random_shuffle.
by yangyang1000 @ 2024-10-02 18:40:45
@Night_sea_64 似乎是对的?(我也不到)
by 幸存者 @ 2024-10-02 18:47:08
为啥要转化为相邻两个线段的差,你直接 set 维护 r 启发式合并不就行了