Title - more than once prefix and differential

A full-length n sequence 0, m times modified for this sequence, each modification, I would specify a starting point x, you start from this starting point, each subsequent sequence number incremented by 1, plus 2, plus 3 ... "z

Input formats:

The first line two positive integers n (n <= 100000), m (m <= 100000),
followed m rows, each is a positive integer x (1 <= x <= n), each modification is starting point.

Output formats:

Output line comprises n positive integer representing the last sequence separated by spaces, no extra space end of the line.

Sample input:

Here we are given a set of inputs. E.g:

5 3 2 4 3

Sample output:

Given here corresponding output. E.g:

0 1 3 6 9

And the prefix differential relationship: class derivation and integration can be calculated from each other, or may request a prefix find multiple differential and

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int n,m;
ll dif[maxn];
ll dif_dif[maxn];
ll a[maxn];
int main(){
    scanf("%d %d",&n,&m);
    while(m--){
        int s;
        scanf("%d",&s);
        dif_dif[s]++;
    }
    for(int i=1; i<=n; i++){
        dif[i] = dif_dif[i] + dif[i-1];
        a[i] = dif[i] + a[i-1];
        printf("%lld",a[i]);
        if(i!=n)
            printf(" ");
        else
            printf("\n");
    }
    
    return 0;
}

Published 62 original articles · won praise 0 · Views 1749

Guess you like

Origin blog.csdn.net/jhckii/article/details/104399127