题解
正着来发现很怪,倒着来发现顺多了
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=114514;
ll tree[8*N]={0};
ll tag[8*N]={0};
string a,b;
void build(int node,int l,int r)
{
tag[node]=-1;
if(l==r)
{
tree[node]=b[l]-'0';
return ;
}
int mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
tree[node]=tree[node*2]+tree[node*2+1];
}
void pushdown(int node,int l,int r)
{
if(tag[node]==-1) return;
tree[node]=(r-l+1)*tag[node];
if(l!=r)
{
tag[node*2]=tag[node];
tag[node*2+1]=tag[node];
}
tag[node]=-1;
}
bool flag=1;
int query(int node,int l1,int r1,int x,int y)
{
pushdown(node,l1,r1);
if(l1>y||r1<x) return 0;
if(l1>=x&&r1<=y)
{
return tree[node];
}
int mid=(l1+r1)/2;
return query(node*2,l1,mid,x,y)+query(node*2+1,mid+1,r1,x,y);
}
void update(int node,int l1,int r1,int x,int y,int val)
{
pushdown(node,l1,r1);
if(l1>y||r1<x) return ;
if(l1>=x&&r1<=y)
{
tag[node]=val;
pushdown(node,l1,r1);
return;
}
int mid=(l1+r1)/2;
update(node*2,l1,mid,x,y,val);
update(node*2+1,mid+1,r1,x,y,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
int l[2*N],r[2*N];
void solve()
{
int n,q;
cin>>n>>q;
cin>>a>>b;
a=' '+a;
b=' '+b;
build(1,1,n);
for(int i=1;i<=q;i++) cin>>l[i]>>r[i];
flag=1;
for(int i=q;i>=1;i--)
{
int one=query(1,1,n,l[i],r[i]);
//printf("ones:%d\n",one);
if(one*2==r[i]-l[i]+1)
{
flag=0;
break;
}
int id=(one*2>r[i]-l[i]+1);
update(1,1,n,l[i],r[i],id);
}
for(int i=1;i<=n;i++)
{
//printf("%d's query:%d\n",i,query(1,1,n,i,i));
if(query(1,1,n,i,i)!=a[i]-'0') flag=0;
}
if(flag) puts("yes");
else puts("no");
}
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
标签:Nezzar,Binary,node,String,int,ll,tree,tag,r1
From: https://www.cnblogs.com/pure4knowledge/p/18306005