zoukankan      html  css  js  c++  java
  • 三步必杀

    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;
    }
  • 相关阅读:
    python3-file的修改实现类似shell中sed的功能
    python3-字典的循环
    python3-file文件操作
    python3-字典的增删改查
    python3-字典中存储列表
    python3-字典中的一些常用方法
    python3-字典中包含字典
    报错调试和工具使用
    (三)、Struts第三天
    struts体系结构
  • 原文地址:https://www.cnblogs.com/coder-cjh/p/11621759.html
Copyright © 2011-2022 走看看