三步必杀

Solution

Step 1

考试的时候SB想到了异或……

首先复杂度肯定是线性,否则无法满足。

Step 2

区间操作,考虑转为差分,变成单点操作。

那么如果 s=e ,就是普通的差分

如果不是,也就是差分数组每次加上同一个数,考虑维护差分数组的差分数组。

每次加上公差,最后统计。

修改 O(1) ,统计 O(N) ,可以承受

Step 3

#include<bits/stdc++.h>
using namespace std;
long long sum[10000005],d[10000005];
template <typename T>void read(T &x){
    int f=1;x=0;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=!f;
    for(; isdigit(c);c=getchar()) x=x*10+c-'0';
    x*=f;
}
int n,m,l,r;
long long s,e,a[10000005];
int main(){
//  freopen("sequence.in","r",stdin);
//  freopen("sequence.out","w",stdout);
    read(n);read(m);
    while(m--){
        read(l);read(r);read(s);read(e);
        long long gc=(e-s)/(r-l);
        d[l+1]+=gc;d[r+1]-=gc;//差分数组的差分数组,从第二项到末项加上公差
        sum[l]+=s;sum[r+1]-=e;//差分数组本身两端进行修改
    }
    for(int i=1;i<=n;i++)
     sum[i]+=(d[i]+=d[i-1]);//统计差分数组
    long long ans=0,tmp=0,mx=0;
    for(int i=1;i<=n;i++)ans^=(tmp+=sum[i]),mx=max(mx,tmp);//统计原数组
    printf("%lld %lld",ans,mx);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/coder-cjh/p/11621759.html