Luogu U37449 Lycanthropy

Posted pushinl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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("
");
}

以上是关于Luogu U37449 Lycanthropy的主要内容,如果未能解决你的问题,请参考以下文章

解题报告:luogu P2220

#[luogu3412]仓鼠找sugar II

丢瓶盖

#loj3093 [BJOI2019]光线

Java分代垃圾回收机制:年轻代/年老代/持久代(转)

R留学生作业代码代写代编程代编程代编程