• Luogu U37449 Lycanthropy


    题目

    差分

    CODE:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    const int pls = 50001;
    
    int pre[20000050];
    long long cur;
    long long tot;
    
    void add(int l, int r, int val)
    {
        pre[l + pls] += val;
        pre[r + 1 + pls] -= val;
    }
    
    int main()
    {
        int n,m;
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; ++i)
        {
            int v, x;
            scanf("%d%d", &v, &x);
            add(x - v + 1, x, -1);
            add(x + 1,x + v, 1);
            add(x - 3 * v + 1,x - 2 * v, 1);
            add(x - 2 * v + 1, x - v, -1);
            add(x + v + 1, x + 2 * v, 1);
            add(x + 2 * v + 1, x + 3 * v, -1);
        }
        for (int i = 1; i <= m + pls; ++i)
        {
            cur += pre[i];
            tot += cur;
            if (i > pls)
                printf("%lld ", tot);
        }
        printf("
    ");
        return 0;
    }
    

    zky聚聚的差分:

    #include<cstdio>
    #include<iostream>
    using namespace std;
    inline int qread(){
        register int x = 0, ch = getchar();
        while(!isdigit(ch)) ch = getchar();
        while(isdigit(ch))  x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
        return x;
    }
    const int maxn = 1000010;
    int mmap[maxn << 1];
    int ans[maxn << 1];
    int n, m;
    int main(void){
        n = qread();
        m = qread();
        for(int i = 1; i <= n; ++i){
            int x = qread(), y = qread();
            y += 100000;
            mmap[y] -= 2;
            mmap[y - (x << 1)] += 2;
            mmap[y + (x << 1)] += 2;
            mmap[y - (x << 1) - x]--;
            mmap[y + (x << 1) + x]--;
        }
        for(int i = 3; i <= m + 120000; ++i){
            ans[i] = (ans[i - 1] << 1) - ans[i - 2] - mmap[i - 1];
            if(i >= 100001 && i <= 100000 + m){
                if(i == 100001) printf("%d", ans[i]);
                else            printf(" %d", ans[i]);
            }
        }
        printf("
    ");
    }
    
  • 相关阅读:
    第03组 Alpha冲刺(2/4)
    第03组 Alpha冲刺
    第09组 Beta版本演示
    第09组 Beta冲刺(4/4)
    第09组 Beta冲刺(3/4)
    第09组 Beta冲刺(2/4)
    第09组 Beta冲刺(1/4)
    第09组 Alpha事后诸葛亮
    第09组 Alpha冲刺(4/4)
    第09组 Alpha冲刺(3/4)
  • 原文地址:https://www.cnblogs.com/pushinl/p/9891182.html
Copyright © 2020-2023  润新知