Problem:
Max Score: $1200$ Points

Problem statement

There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$.

A sushi chef carried out $Q$ operations for customers.

The $i$-th operation is follows:

The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers.

He puts a dish of sushi on the selected seats.

A customer who have selected for professional eats this sushi.

Repeat 1-3, $b_i$ times.

Please calculate the number of dishes of sushi that have been eaten by each customer.

Input

The input is given from Standard Input in the following format:

$N \ Q$
$a_1 \ b_1$
$a_2 \ b_2$
$ ： \ ： $
$a_Q \ b_Q$

Output

You have to print $N$ lines.

The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$.

Constraints

$3 \le N, Q \le 100,000$

$1 \le a_i \le N$

$1 \le b_i \le 10^{12}$

Any final results do not exceed $2 \times 10^{13}$.

Subtasks

Subtask 1 [ $60$ points ]

$N, Q \le 100$

$b_i = 1$

Subtask 2 [ $400$ points ]

$N, Q \le 100$

$b_i \le 10^{12}$

Subtask 3 [ $240$ points ]

$N, Q \le 100,000$

$b_i = 1$

Subtask 4 [ $500$ points ]

There are no additional constraints.

Sample Input 1

9 3
5 11
8 4
4 7

Sample Output 1

4
4
4
4
2
2
1
1
0

The change of the number of dishes of sushi have eaten is following:

Customer 1

Customer 2

Customer 3

Customer 4

Customer 5

Customer 6

Customer 7

Customer 8

Customer 9

1st Operation

3

2

2

2

2

0

0

0

0

2nd Operation

3

2

2

2

2

2

1

1

0

3rd Operation

4

4

4

4

2

2

1

1

0

Sample Input 2

6 6
3 5
6 11
1 6
4 7
5 2
2 5

Sample Output 2

10
10
5
5
4
2

Sample Input 3

5 6
1 1
2 1
3 1
1 1
5 1
3 1

Sample Output 3

2
2
1
1
0

Sample Input 4

10 10
10 10
9 20
8 30
7 40
6 50
5 60
4 70
3 80
2 90
1 100

Sample Output 4

223
123
77
50
33
21
12
7
3
1

Writer: E869120

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int Q = int.Parse(str[1]);
        SegTree Seg = new SegTree(N);
        for(int i=2*N-2;i>=0;i--){
            if(i >= Seg.segf){
                Seg.cn[i] = 1; 
            }
            else{
                int sl = i*2+1;
                int sr = i*2+2;
                Seg.cn[i] = Seg.cn[sl]+Seg.cn[sr];
            }
        }
        for(int i=0;i<Q;i++){
            str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0])-1;
            long b = long.Parse(str[1]);
            int bf = 0;
            int bl = a;
            while(bf != bl){
                int bc = (bf+bl)/2;
                if(Seg.Sum(bc,a) + b >= Seg.GetValue(bc) * (a - bc + 1)){
                    bl = bc;
                }
                else{
                    bf = bc+1;
                }
            }
            long nb = Seg.Sum(bf,a) + b;
            if(nb % (a - bf + 1) == 0){
                Seg.SetC(bf,a,nb/(a-bf+1)); 
            }
            else{
                Seg.SetC(bf,bf+(int)(nb%(a-bf+1))-1,nb/(a-bf+1)+1);
                Seg.SetC(bf+(int)(nb%(a-bf+1)),a,nb/(a-bf+1)); 
            }
        }
        for(int i=0;i<N;i++){
            sb.Append(Seg.GetValue(i)+"\n");
        }
    }
}
struct SegTree{
    public long[] Mi;
    public bool[] uncom;
    public int[] cn;
    public long[] co;
    //葉の最初の場所
    public int segf;
    //segfのbit
    public int segfb;
    //葉の深さの内浅い方
    public int depth;
    //浅い葉の内座標が最大のもの
    public int borderP;
    //はみ出すものの数
    public int border;
    public SegTree(int N){
        Mi = new long[2*N-1];
        uncom = new bool[2*N-1];
        cn = new int[2*N-1];
        co = new long[2*N-1];
        for(depth = 1;(1 << depth) <= N;depth++){
            ;
        }
        segf = N-1;
        borderP = (1 << depth) - 2;
        border = 2*N - borderP - 2;
        segfb = border/2;
    }
    public int ToBit(int p){
        if(p >= border){
            return segfb + p - border;
        }
        else{
            return p;
        }
    }
    //葉のある場所
    public int ToLeaf(int p){
        if(p >= border){
            return segf + p - border;
        }
        else{
            return borderP + p + 1;
        }
    }
    //葉の示す頂点
    public int ToPoint(int leaf){
        if(leaf > borderP){
            return leaf - borderP - 1;
        }
        else{
            return leaf - segf + border;
        }
    }
    long Single(int b,int v,int depth){
        if(depth == -1){
            return Mi[v];
        }
        else{
            if((b & (1 << depth)) == 0){
                return Math.Max(Mi[v],Single(b,v*2+1,depth-1));
            }
            else{
                return Math.Max(Mi[v],Single(b,v*2+2,depth-1));
            }
        }
    }
    public long GetValue(int p){
        int b = ToBit(p);
        int d = p >= border ? depth - 2 : depth - 1;
        return Single(b,0,d);
    }
    //vの子の内bより大きいものに(bは子孫,bはToBitしたもの)
    void More(int b,int v,int depth,long C){
        if(v < segf){
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
        }
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            co[v*2+2] = cn[v*2+2] * C;
            Mi[v*2+2] = C;
            uncom[v*2+2] = true;
            if(((b+1) % (1 << depth)) != 0){
                More(b,v*2+1,depth-1,C);
            }
        }
        else{
            //左の子は全てb未満
            More(b,v*2+2,depth-1,C);
        }
        if(v < segf){
            co[v] = co[v*2+1] + co[v*2+2];
        }
    }
    //vの子の内bより小さなものに(bは子孫,bはToBitしたもの)
    void Less(int b,int v,int depth,long C){
        if(v < segf){
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
        }
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            Less(b,v*2+1,depth-1,C);
        }
        else{
            //左の子は全てb未満
            Mi[v*2+1] = C;
            co[v*2+1] = cn[v*2+1] * C;
            uncom[v*2+1] = true;
            if(b % (1 << depth) != 0){
                Less(b,v*2+2,depth-1,C);
            }
        }
        if(v < segf){
            co[v] = co[v*2+1] + co[v*2+2];
        }
    }
    void Section(int bl,int br,int v,int dl,int dr,long C){
        if(v >= segf){
            //葉
            Mi[v] = C;
            co[v] = C;
        }
        else{
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
            if((bl & (1 << dl)) == 0 && (br & (1 << dr)) == 0){
                //両方左
                Section(bl,br,v*2+1,dl-1,dr-1,C);
            }
            else if((bl & (1 << dl)) != 0 && (br & (1 << dr)) != 0){
                //両方右
                Section(bl,br,v*2+2,dl-1,dr-1,C);
            }
            else{
                //左と右に分かれた
                if(bl % (1 << dl) == 0){
                    //左の子は全て区間に
                    Mi[v*2+1] = C;
                    co[v*2+1] = cn[v*2+1] * C;
                    uncom[v*2+1] = true;
                }
                else{
                    More(bl-1,v*2+1,dl-1,C);
                }
                if((br + 1) % (1 << dl) == 0){
                    //右の子は全て区間に
                    Mi[v*2+2] = C;
                    co[v*2+2] = cn[v*2+2] * C;
                    uncom[v*2+2] = true;
                }
                else{
                    Less(br+1,v*2+2,dr-1,C);
                }
            }
            co[v] = co[v*2+1] + co[v*2+2];
        }
    }
    public void SetC(int l0,int r0,long C){
        int bl = ToBit(l0);
        int br = ToBit(r0);
        int dl = l0 >= border ? depth - 2 : depth - 1;
        int dr = r0 >= border ? depth - 2 : depth - 1;
        Section(bl,br,0,dl,dr,C);
    }
    //vの子の内bより大きいものに(bは子孫,bはToBitしたもの)
    long More(int b,int v,int depth){
        if(v < segf){
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
        }
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            if(((b+1) % (1 << depth)) != 0){
                return co[v*2+2] + More(b,v*2+1,depth-1);
            }
            else{
                return co[v*2+2];
            }
        }
        else{
            //左の子は全てb未満
            return More(b,v*2+2,depth-1);
        }
    }
    //vの子の内bより小さなものに(bは子孫,bはToBitしたもの)
    long Less(int b,int v,int depth){
        if(v < segf){
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
        }
        if((b & (1 << depth)) == 0){
            //右の子は全てbより大きい
            return Less(b,v*2+1,depth-1);
        }
        else{
            //左の子は全てb未満
            if(b % (1 << depth) != 0){
                return co[v*2+1] + Less(b,v*2+2,depth-1);
            }
            else{
                return co[v*2+1];
            }
        }
    }
    long Section(int bl,int br,int v,int dl,int dr){
        if(v >= segf){
            //葉
            return co[v];
        }
        else{
            if(uncom[v]){
                Mi[v*2+1] = Mi[v];
                co[v*2+1] = cn[v*2+1] * Mi[v];
                uncom[v*2+1] = true;
                Mi[v*2+2] = Mi[v];
                co[v*2+2] = cn[v*2+2] * Mi[v];
                uncom[v*2+2] = true;
                uncom[v] = false;
            }
            if((bl & (1 << dl)) == 0 && (br & (1 << dr)) == 0){
                //両方左
                return Section(bl,br,v*2+1,dl-1,dr-1);
            }
            else if((bl & (1 << dl)) != 0 && (br & (1 << dr)) != 0){
                //両方右
                return Section(bl,br,v*2+2,dl-1,dr-1);
            }
            else{
                long ans = 0;
                //左と右に分かれた
                if(bl % (1 << dl) != 0){
                    ans += More(bl-1,v*2+1,dl-1);
                }
                else{
                    ans += co[v*2+1];
                }
                if((br + 1) % (1 << dl) != 0){
                    ans += Less(br+1,v*2+2,dr-1);
                }
                else{
                    ans += co[v*2+2];
                }
                return ans;
            }
        }
    }
    public long Sum(int l0,int r0){
        int bl = ToBit(l0);
        int br = ToBit(r0);
        int dl = l0 >= border ? depth - 2 : depth - 1;
        int dr = r0 >= border ? depth - 2 : depth - 1;
        return Section(bl,br,0,dl,dr);
    }
}