哦不不不被放进模拟赛里还加强了结果线段树写挂了我无疑是愤怒的。
思路
因为 ,值域范围为 ,所以我们只能异或 这些数,同时最后只能变成这些数。通过打表我们可以得知除了这些数还有 满足条件。此时我们发现这些数均满足模 或模 余 ,由于我们模拟赛中为区间修改,所以我们可以用线段树维护区间内有多少个数模 、模 、模 余 ,最后求值的时候容斥一下。对于本题只需要写单点修改就行了。当然我的代码肯定还是区间修改的
#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f3f3f3f3f
#define elif else if
#define pii pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x&-x)
#define setdigit(x) cout<<fixed<<setprecision(x)
#define debug(...) fprintf(stderr,##__VA_ARGS__)
using namespace std;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
const int maxn=2e5+5;
int n,q,a[maxn];
struct node{int l,r,m3,m5,m1,lazy;}t[maxn<<2];
void pushdown(int p){
if(t[p].lazy!=-1){
t[p<<1].m3=(t[p].lazy%3==0)*(t[p<<1].r-t[p<<1].l+1);
t[p<<1|1].m3=(t[p].lazy%3==0)*(t[p<<1|1].r-t[p<<1|1].l+1);
t[p<<1].m5=(t[p].lazy%5==0)*(t[p<<1].r-t[p<<1].l+1);
t[p<<1|1].m5=(t[p].lazy%5==0)*(t[p<<1|1].r-t[p<<1|1].l+1);
t[p<<1].m1=(t[p].lazy%15==0)*(t[p<<1].r-t[p<<1].l+1);
t[p<<1|1].m1=(t[p].lazy%15==0)*(t[p<<1|1].r-t[p<<1|1].l+1);
t[p<<1].lazy=t[p<<1|1].lazy=t[p].lazy;
t[p].lazy=-1;
}
}
void build(int p,int l,int r){
t[p].l=l,t[p].r=r,t[p].lazy=-1;
if(l==r){t[p].m3=(a[l]%3==0),t[p].m5=(a[l]%5==0),t[p].m1=(a[l]%15==0);return;}
int mid=l+r>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
t[p].m3=t[p<<1].m3+t[p<<1|1].m3,t[p].m5=t[p<<1].m5+t[p<<1|1].m5,t[p].m1=t[p<<1].m1+t[p<<1|1].m1;
}
void update(int p,int l,int r,int k){
if(l<=t[p].l&&t[p].r<=r){t[p].lazy=k,t[p].m3=(k%3==0)*(t[p].r-t[p].l+1),t[p].m5=(k%5==0)*(t[p].r-t[p].l+1),t[p].m1=(k%15==0)*(t[p].r-t[p].l+1);return;}
pushdown(p);
int mid=t[p].l+t[p].r>>1;
if(l<=mid)update(p<<1,l,r,k);
if(r>mid)update(p<<1|1,l,r,k);
t[p].m3=t[p<<1].m3+t[p<<1|1].m3,t[p].m5=t[p<<1].m5+t[p<<1|1].m5,t[p].m1=t[p<<1].m1+t[p<<1|1].m1;
}
int query(int p,int l,int r){
if(l<=t[p].l&&t[p].r<=r)return(t[p].m3+t[p].m5-t[p].m1);
pushdown(p);
int mid=t[p].l+t[p].r>>1,res=0;
if(l<=mid)res+=query(p<<1,l,r);
if(r>mid)res+=query(p<<1|1,l,r);
return res;
}
void solve(){
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
build(1,1,n);
cout<<query(1,1,n);
for(int i=1,l,r;i<=q;i++){
cin>>l>>r;
update(1,l,l,r);
cout<<" "<<query(1,1,n);
}
cout<<"\n";
}
signed main(){
string filename="sausage";
// freopen((filename+".in").c_str(),"r",stdin),freopen((filename+".out").c_str(),"w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int Case=1;
cin>>Case;
while(Case--)solve();
}