Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem C
Distribution Center

The factory of the Impractically Complicated Products Corporation has many manufacturing lines and the same number of corresponding storage rooms. The same number of conveyor lanes are laid out in parallel to transfer goods from manufacturing lines directly to the corresponding storage rooms. Now, they plan to install a number of robot arms here and there between pairs of adjacent conveyor lanes so that goods in one of the lanes can be picked up and released down on the other, and also in the opposite way. This should allow mixing up goods from different manufacturing lines to the storage rooms.

Depending on the positions of robot arms, the goods from each of the manufacturing lines can only be delivered to some of the storage rooms. Your task is to find the number of manufacturing lines from which goods can be transferred to each of the storage rooms, given the number of conveyor lanes and positions of robot arms.

Input

The input consists of a single test case, formatted as follows.

$n$ $m$

$x_1$ $y_1$

...

$x_m$ $y_m$

An integer $n$ ($2 \leq n \leq 200000$) in the first line is the number of conveyor lanes. The lanes are numbered from 1 to $n$, and two lanes with their numbers differing with 1 are adjacent. All of them start from the position $x = 0$ and end at $x = 100000$. The other integer $m$ ($1 \leq m x-coordinate of the $i$-th robot arm, which can pick goods on either the lane $y_i$ or the lane $y_i + 1$ at position $x = x_i$, and then release them on the other at the same x-coordinate.

You can assume that positions of no two robot arms have the same $x$-coordinate, that is, $x_i \ne x_j$ for any $i \ne j$.

Figure C.1. Illustration of Sample Input 1

Output

Output $n$ integers separated by a space in one line. The $i$-th integer is the number of the manufacturing lines from which the storage room connected to the conveyor lane $i$ can accept goods.

Sample Input 1

4 3
1000 1
2000 2
3000 3

Sample Output 1

2 3 4 4

Sample Input 2

4 3
1 1
3 2
2 3

Sample Output 2

2 4 4 2



Sample input:
4 3
1000 1
2000 2
3000 3


Sample output:
2 3 4 4

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,q = LI()
    qa = sorted([LI() for _ in range(q)])
    u = [0] * (n+2)
    d = [0] * (n+2)

    for x,i in qa:
        u[i+1] = u[i] + 1
        d[i] = d[i+1] + 1
    rr = []
    for i in range(1,n+1):
        rr.append(u[i]+d[i]+1)


    return '\n'.join(map(str,rr))


print(main())

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a={}
for i in range(m):
    b,c=map(int,input().split())
    a[i]=(b,c-1)
a=sorted(a.items(),key=lambda x:x[1])
b=[0]*(n+1);c=[0]*(n+1)
for i in range(n):b[i]=c[i]=i
for i in range(m):
    x=a[i][1][1]
    b[x]=max(b[x],b[x+1])
    c[x+1]=min(c[x],c[x+1])
print(*[b[i]-c[i]+1 for i in range(n)])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(m)]
A.sort()
*v_min, = range(n)
*v_max, = range(n)

for _, y in A:
    v_max[y-1] = v_max[y]
    v_min[y] = v_min[y-1]

print(*[v_max[i] - v_min[i] + 1 for i in range(n)])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,q = LI()
    qa = sorted([LI() for _ in range(q)])
    u = [0] * (n+2)
    d = [0] * (n+2)

    for x,i in qa:
        u[i+1] = u[i] + 1
        d[i] = d[i+1] + 1
    rr = []
    for i in range(1,n+1):
        rr.append(u[i]+d[i]+1)


    return ' '.join(map(str,rr))


print(main())

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
XY = []
for _ in range(M):
    x,y = map(int,input().split())
    xy = (x,y)
    XY.append(xy)
XY.sort(key = lambda x:x[0]) # x sort

*minY, = range(N)
*maxY, = range(N)

for _,y in XY:
    y0,y1 = y-1, y
    minY[y1] = minY[y0]
    maxY[y0] = maxY[y1]


ans = [maxY[i] - minY[i]+1 for i in range(N)]
print(*ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

ans = [1] * (n + 1)

prev = [0] * (n + 1)

xy.sort()
for x, y in xy:

    temp = ans[y] + ans[y + 1] - prev[y]
    ans[y] = temp
    ans[y + 1] = temp
    prev[y] = temp

print(" ".join(list(map(str, ans[1:]))))