description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = []
ans = [0] * n
for i in range(n):
q, w = map(int, input().split())
a.append([q, w, i])
a.sort()
ans[a[0][2]] = 1
m = a[0][1]
for i in range(1, n):
m = max(a[i - 1][1], m)
if a[i][0] <= m:
ans[a[i][2]] = ans[a[i - 1][2]]
else:
ans[a[i][2]] = int(not ans[a[i - 1][2]])
g = 0
for i in range(n):
if ans[i] == 0:
g = 1
ans[i] = 2
if g == 0:
print(-1)
else:
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
n = int(input())
for i in range(n):
li = []
origli = []
q = int(input())
for j in range(q):
a, b = input().split(" ")
a, b = int(a), int(b)
li.append([a, b])
origli.append([a, b])
li.sort()
newli = [li[0]]
i = 1
s1 = set()
s2 = set()
s1.add(tuple(li[0]))
while i < len(li):
if li[i][0] <= newli[-1][1]:
if tuple(li[i - 1]) in s1:
s1.add(tuple(li[i]))
else:
s2.add(tuple(li[i]))
if newli[-1][1] < li[i][1]:
newli[-1][1] = li[i][1]
i += 1
else:
if tuple(li[i - 1]) in s1:
s2.add(tuple(li[i]))
else:
s1.add(tuple(li[i]))
newli.append([li[i][0], li[i][1]])
i += 1
ans = []
if len(newli) == 1:
print(-1)
continue
for i in range(len(origli)):
if tuple(origli[i]) in s1:
ans.append(1)
elif tuple(origli[i]) in s2:
ans.append(2)
joined_string = " ".join([str(v) for v in ans])
print(joined_string)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def add(Dict, key, value):
if key in Dict:
Dict[key].append(value)
else:
Dict[key] = [value]
def Coloring(n, data):
assert n == len(data), "Error parsing data and its length"
allCord = set()
opening = dict()
closing = dict()
reference = dict()
for i in range(n):
allCord.add(data[i][0])
allCord.add(data[i][1])
reference[data[i][0]] = i
reference[data[i][1]] = i
add(opening, data[i][0], i)
add(closing, data[i][1], i)
cord = list(allCord)
cord.sort()
groups = []
curGroup = []
active = set()
for i in range(len(cord)):
curCord = cord[i]
op = []
if curCord in opening:
op = opening[curCord]
for elem in op:
active.add(elem)
curGroup.append(elem)
cl = []
if curCord in closing:
cl = closing[curCord]
for elem in cl:
active.remove(elem)
if not bool(active):
groups.append(curGroup)
curGroup = []
if len(groups) <= 1:
print("-1")
else:
colors = [None] * n
for elem in groups[0]:
colors[elem] = 1
for i in range(1, len(groups)):
for elem in groups[i]:
colors[elem] = 2
for i in range(n):
print(colors[i], end=" ")
print()
def SolveProblemC():
T = int(input())
for queries in range(T):
n = int(input())
segment_data = []
for segment in range(n):
l, r = map(int, input().split())
segment_data.append([l, r])
Coloring(n, segment_data)
SolveProblemC()
|
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_DEF VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for c in range(int(input())):
N = int(input())
counter = 0
segments = []
for n in range(N):
l, r = map(int, input().split())
segments.append([[l, r], counter])
counter += 1
segments.sort()
ans = [-1] * N
rightBound = segments[0][0][1]
valid = -1
for i in range(1, len(segments)):
if segments[i][0][0] > rightBound:
valid = i
break
else:
rightBound = max(rightBound, segments[i][0][1])
if valid == -1:
print(-1)
else:
for i in range(valid):
ans[segments[i][1]] = 1
for i in range(valid, len(segments)):
ans[segments[i][1]] = 2
for a in ans:
print(a, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
ans = [0] * n
cc = 0
l = []
for xx in range(n):
a, b = map(int, input().split())
qqq = [a, b, xx]
l.append(qqq)
l4 = sorted(l, key=lambda x: x[0])
c = 1
x = 2
zz = 0
kk = 0
f = 0
for i in range(n - 1):
if l4[f][1] >= l4[i + 1][0]:
kk += 1
if zz == 0:
l4[i].append(1)
l4[i + 1].append(1)
zz = 1
else:
l4[i + 1].append(1)
zz = 1
else:
if zz == 0:
l4[i].append(c)
l4[i + 1].append(x)
zz = 1
else:
l4[i + 1].append(x)
zz = 1
break
if l4[f][1] < l4[i + 1][1]:
f = i + 1
if kk == n - 1:
print(-1)
continue
for j in range(i + 1, n):
l4[j].append(2)
l4.sort(key=lambda x: x[2])
for i in range(n):
print(l4[i][3], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n, intersections, curr_group = int(input()), 0, 1
l = [[[int(x) for x in input().split()], i, curr_group] for i in range(n)]
l.sort(key=lambda x: x[0])
current_group_max = l[0][0][1]
for i in range(1, n):
if current_group_max >= l[i][0][0]:
intersections += 1
else:
curr_group = curr_group % 2 + 1
l[i][2] = curr_group
current_group_max = max(current_group_max, l[i][0][1])
if intersections == n - 1:
print(-1)
else:
l.sort(key=lambda x: x[1])
print(" ".join([str(i[2]) for i in l]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append([x, y, i])
a.sort()
g1 = a[0][0]
g11 = a[0][1]
g2 = a[1][0]
g22 = a[1][1]
b = [0] * n
z = a[-1][2]
b[z] = 2
maxr = -1
f = False
for i in range(n - 1):
x, y, z = a[i][0], a[i][1], a[i][2]
b[z] = 1
maxr = max(maxr, y)
if maxr < a[i + 1][0]:
f = True
break
if not f:
print(-1)
else:
for j in range(i + 1, n):
z = a[j][2]
b[z] = 2
print(*b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
q = int(sys.stdin.readline())
for _ in range(q):
n = int(sys.stdin.readline())
a = []
for i in range(n):
l, r = map(int, sys.stdin.readline().split())
a.append([l, r, i])
a.sort()
ans = [2] * n
maxx = a[0][1]
ans[a[0][2]] = 1
for i in range(1, n):
maxx = max(maxx, a[i - 1][1])
if a[i][0] <= maxx:
ans[a[i][2]] = ans[a[i - 1][2]]
if ans.count(1) != 0 and ans.count(2) != 0:
print(*ans)
else:
print(-1)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for t in range(T):
N = int(input())
segs = []
for i, n in enumerate(range(N)):
seg = [int(x) for x in input().split()] + [i]
segs.append(seg)
segs.sort(key=lambda x: x[0])
clas = 1
nots = [2] * len(segs)
A, B, _ = segs[0]
for seg in segs:
C, D, idx = seg
if D >= A and C <= B:
nots[idx] = clas
B = max(B, D)
else:
clas += 1
break
if clas == 1:
print(-1)
else:
print(*nots)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin
t = int(input())
for _ in range(t):
n = int(input())
l = [(list(map(int, stdin.readline().split())) + [i]) for i in range(n)]
l.sort()
rb = l[0][1]
res = [1] * n
res[l[0][2]] = 2
flag = False
for v in l[1:]:
if v[0] > rb:
flag = True
break
else:
rb = max(rb, v[1])
res[v[2]] = 2
if not flag:
print(-1)
else:
print(*res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def do_intersect(a, b):
return min(a[1], b[1]) >= max(a[0], b[0])
for _ in range(int(input())):
n = int(input())
inps = [tuple(map(int, input().split())) for _ in range(n)]
org = [pair for pair in inps]
inps.sort()
sets = [inps[0]]
for i in range(1, n):
merged = False
for j in range(len(sets)):
if do_intersect(sets[j], inps[i]):
new_set = min(inps[i][0], sets[j][0]), max(inps[i][1], sets[j][1])
sets[j] = new_set
merged = True
break
if not merged:
sets.append(inps[i])
if len(sets) == 1:
print(-1)
else:
ans = []
for inp in org:
if do_intersect(inp, sets[0]):
ans.append(1)
else:
ans.append(2)
print(*ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
a, d, f = [], dict(), 0
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = sorted(a)
cur = b[0][1]
for l, r in b:
if l > cur:
f = 1
break
else:
d[l, r] = 1
if r > cur:
cur = r
if not f:
print(-1)
else:
for l, r in a:
if (l, r) in d:
print("1 ", end="")
else:
print("2 ", end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
q = int(input())
for i in range(q):
n = int(input())
ilist = []
for j in range(n):
ilist.append(list(map(int, input().rstrip().split())))
ilist[j].append(j)
ilist.sort()
seglist = [2] * n
seglist[ilist[0][2]] = 1
goodvalue = -1
currentmax = ilist[0][1]
for k in range(n - 1):
if currentmax >= ilist[k + 1][0]:
seglist[ilist[k + 1][2]] = 1
currentmax = max([currentmax, ilist[k + 1][1]])
if currentmax < ilist[k + 1][0]:
break
if sum(seglist) == n:
print(-1)
else:
print(*seglist)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
l = []
for i in range(n):
a, b = map(int, input().split())
l.append((a, 0, i))
l.append((b, 1, i))
g = sorted(range(n))
l.sort(key=lambda x: x[0])
t = [(2) for i in range(n)]
k = 0
test = 0
count = 0
indice = i
start = 0
h = 0
for i in range(2 * n):
if l[i][1] == 0:
k += 1
else:
k -= 1
if k == 0 and i < 2 * n - 1:
if l[i + 1] == l[i]:
start += 1
else:
start == 0
if start == 2:
test == 0
break
for i in range(2 * n):
if l[i][1] == 0:
k += 1
else:
k -= 1
if k == 0 and i < 2 * n - 1 and l[i + 1] > l[i]:
test = 1
indice = i
break
if count == 2:
test = 0
break
if test == 0:
print(-1)
else:
for j in range(indice):
t[l[j][2]] = 1
print(*t, sep=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR VAR NUMBER IF VAR NUMBER EXPR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = []
for i in range(n):
a.append([list(map(int, input().split())), i])
ans = [-1] * n
a.sort()
f = -1
maxr = -1
for i in range(n - 1):
maxr = max(a[i][0][1], maxr)
if maxr < a[i + 1][0][0]:
f = i
break
if f == -1:
print(-1)
else:
for i in range(f + 1):
ans[a[i][1]] = 1
for i in range(f + 1, n):
ans[a[i][1]] = 2
for i in ans:
print(i, end=" ")
print("")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
x = int(input())
a = [(list(map(int, input().split())) + [j]) for j in range(x)]
a.sort()
g1 = 0
ans = [0] * x
g1 = a[0][1]
ans[a[0][2]] = 1
for j in range(1, x):
if g1 < a[j][0]:
ans[a[j][2]] = 2
break
else:
g1 = max(a[j][1], g1)
ans[a[j][2]] = 1
else:
print(-1)
continue
for k in range(j, x):
ans[a[k][2]] = 2
print(*ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def C():
q = int(input())
for _ in range(q):
n = int(input())
tuples = []
for i in range(n):
ab = [int(x) for x in input().split()]
tuples.append((ab[0], ab[1], i))
tuples.sort()
sol = ["-1"] * n
r_act = tuples[0][1]
flag = 0
for l, r, i in tuples:
if flag == 0:
if l <= r_act:
r_act = max(r, r_act)
sol[i] = "1"
else:
r_act = r
sol[i] = "2"
flag = 1
if flag == 1:
if l <= r_act:
r_act = max(r, r_act)
sol[i] = "2"
else:
r_act = r
sol[i] = "1"
flag = 0
if "-1" in sol or "1" not in sol or "2" not in sol:
print(-1)
continue
print(" ".join(sol))
C()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in [0] * int(input()):
n = int(input())
t = [2] * n
m = g = 0
for l, r, i in sorted([*map(int, input().split()), i] for i in range(n)):
g += l > m
m = max(m, r)
t[i] -= g & 1
print(*(t, [-1])[g < 2])
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR LIST NUMBER VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
otr = []
for item in range(n):
otr.append(tuple(int(x) for x in input().split()))
sortr = [(0, 0)] * 2 + sorted(otr)
dic = {}
dic[0, 0] = 1
c1 = 0
c2 = 0
maxy = 0
for item in range(2, len(sortr)):
if maxy >= sortr[item][0]:
if dic[sortr[item - 1]] == 1:
dic[sortr[item]] = 1
c1 += 1
else:
dic[sortr[item]] = 2
c2 += 1
elif c1 == 0:
dic[sortr[item]] = 1
c1 += 1
else:
dic[sortr[item]] = 2
c2 += 1
if sortr[item][1] > maxy:
maxy = sortr[item][1]
if c1 == 0 or c2 == 0:
print(-1)
else:
ans = ""
for item in otr:
ans += str(dic[item]) + " "
print(ans[:-1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
final = []
for k in range(t):
n = int(input())
skl = []
for i in range(n):
a, b = map(int, input().split())
skl.append((a, -1, i))
skl.append((b, 1, i))
skl.sort()
m = 0
ans = ["0"] * n
for i, p in enumerate(skl):
if m == 0 and i != 0:
for j in range(i, 2 * n):
ans[skl[j][2]] = "2"
break
m -= p[1]
if p[1] == -1:
ans[skl[i][2]] = "1"
if not "2" in ans:
final.append("-1")
else:
final.append(" ".join(ans))
print("\n".join(final))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER STRING VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER STRING IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for test in range(t):
n = int(input())
arr = []
for i in range(n):
l, r = map(int, input().split())
arr.append([l, r, i])
arr = sorted(arr, key=lambda item: item[0])
i = 1
ans = [0] * n
ans[arr[0][2]] = 1
mm = arr[0][1]
f = 0
while i < n:
mm = max(arr[i - 1][1], mm)
if arr[i][0] <= mm and f != 1:
ans[arr[i][2]] = 1
else:
f = 1
ans[arr[i][2]] = 2
i += 1
if f == 0:
print(-1)
else:
for i in ans:
print(i, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
segs = []
for i in range(n):
l, r = map(int, input().split())
segs.append((l, r, i))
segs.sort(key=lambda x: x[1])
suffixMinX = [-1] * n
suffixMinX[n - 1] = segs[n - 1][0]
for i in range(n - 2, -1, -1):
suffixMinX[i] = min(suffixMinX[i + 1], segs[i][0])
ret = [None] * n
for i in range(n - 1):
if segs[i][1] < suffixMinX[i + 1]:
for j in range(i + 1):
ret[segs[j][2]] = "1"
for j in range(i + 1, n):
ret[segs[j][2]] = "2"
print(" ".join(ret))
break
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin, stdout
Q = int(input())
for i in range(Q):
N = int(input())
pair = []
for j in range(N):
arr = [int(x) for x in stdin.readline().split()]
pair.append(arr)
data = sorted(pair, key=lambda e: (e[0], e[1]))
cur = 0
flag = 0
ans = {}
j = 0
ans[data[j][0], data[j][1]] = cur + 1
max_num = data[j][1]
for j in range(1, N):
if data[j][0] <= max_num:
ans[data[j][0], data[j][1]] = cur + 1
else:
cur = (cur + 1) % 2
ans[data[j][0], data[j][1]] = cur + 1
if cur == 1:
flag = 1
max_num = max(max_num, data[j][1])
if flag == 0:
print(-1)
else:
for j in range(N):
p = pair[j]
if j != N - 1:
print(ans[p[0], p[1]], end=" ")
else:
print(ans[p[0], p[1]], end="\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
query = int(input())
for _ in range(query):
n = int(input())
array = []
for i in range(n):
a, b = map(int, input().split())
array.append([a, b, i])
array.sort()
max1 = array[0][1]
flag = False
answer = [0] * n
answer[array[0][2]] = 1
for i in range(1, n):
if not flag and array[i][0] <= max1:
max1 = max(max1, array[i][1])
answer[array[i][2]] = 1
else:
flag = True
answer[array[i][2]] = 2
if not flag:
print(-1)
else:
print(*answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
x = []
for j in range(n):
l, r = map(int, input().split(" "))
x.append((l, r))
y = sorted(x, key=lambda x: x[0])
j = 1
f = 0
max = y[0][1]
while j < len(y):
if y[j][0] > max:
q = y[j][0]
f = 1
break
elif y[j][1] > max:
max = y[j][1]
j = j + 1
if f == 1:
j = 0
w = []
while j < len(x):
if x[j][0] >= q:
w.append(2)
else:
w.append(1)
j = j + 1
for k in w:
print(k, end=" ")
print()
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in [0] * int(input()):
n = int(input())
a = []
for i in range(n):
l, r = map(int, input().split())
a += (l, 0, i), (r, 1, i)
a.sort()
g, c, t = 2, 0, [0] * n
for x, m, i in a:
if m:
c -= 1
else:
if c == 0:
g ^= 3
t[i] = g
c += 1
if 2 in t:
print(*t)
else:
print(-1)
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
arr = dict()
for i in range(n):
r = [int(x) for x in stdin.readline().split()]
arr[i] = r
keys = list(arr.keys())
keys.sort(key=lambda x: arr[x][0])
ans = [(0) for i in range(n)]
ma = arr[keys[0]][1]
end = -1
for i in range(1, n):
j = keys[i]
k = keys[i - 1]
if arr[j][0] > ma:
end = i
break
elif arr[j][1] > ma:
ma = arr[j][1]
if end == -1:
stdout.write("-1 \n")
else:
for i in range(n):
if i < end:
ans[keys[i]] = "1"
else:
ans[keys[i]] = "2"
stdout.write(" ".join(ans) + "\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
a = []
for i in range(n):
l, r = list(map(int, input().split()))
a.append([l, r, i])
a.sort()
ma = a[0][1]
b = -1
for i in range(n):
if ma < a[i][0]:
b = i
break
else:
ma = max(a[i][1], ma)
if b == -1:
print(b)
else:
v = [2] * n
for i in range(i):
v[a[i][2]] = 1
print(*v)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
input = sys.stdin.readline
Q = int(input())
for test in range(Q):
n = int(input())
LR = [(list(map(int, input().split())) + [i]) for i in range(n)]
LR.sort()
GR1 = [LR[0][0], LR[0][1]]
for i in range(1, n):
l, r, _ = LR[i]
if r < GR1[0] or l > GR1[1]:
ANS = i
break
else:
GR1 = [min(GR1[0], l), max(GR1[1], r)]
else:
print(-1)
continue
ANSLIST = [1] * n
for j in range(ANS, n):
ANSLIST[LR[j][2]] = 2
for a in ANSLIST:
print(a, end=" ")
print()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
q = int(input())
qarr = []
for i in range(0, q):
intnum = int(input())
intnumarr = []
for j in range(0, intnum):
size = input()
size = size.split()
for k in range(0, 2):
size[k] = int(size[k])
size.append(j)
intnumarr.append(size)
qarr.append(intnumarr)
for i in range(0, q):
workarr = qarr[i]
workarr.sort()
workarr[0].append(1)
x = 0
end = workarr[0][1]
for j in range(1, len(workarr)):
if workarr[j][0] <= end:
workarr[j].append(x % 2 + 1)
else:
x += 1
workarr[j].append(x % 2 + 1)
if workarr[j][3] == workarr[j - 1][3]:
end = max(workarr[j][1], end)
else:
end = workarr[j][1]
y = 0
for j in range(0, len(workarr)):
if workarr[j][3] == 1:
y += 1
else:
pass
if y == len(workarr):
print("-1")
else:
for j in range(0, len(workarr)):
workarr[j][0] = workarr[j][2]
workarr.sort()
for j in range(0, len(workarr)):
print(workarr[j][3], end=" ")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def solution(x):
distrib = [-1] * len(x)
distrib[x[0][2]] = 1
maxR = x[0][1]
k = 1
while k < len(x) and x[k][0] <= maxR:
distrib[x[k][2]] = 1
maxR = max(maxR, x[k][1])
k += 1
if k == len(x):
return [-1]
for i in range(k, len(x)):
distrib[x[i][2]] = 2
return distrib
T = int(input())
for _ in range(T):
N = int(input())
x = []
for i in range(N):
L, R = map(int, input().split())
x.append((L, R, i))
x.sort()
d = solution(x)
print(*d)
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN LIST NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
l = []
for j in range(n):
b, r = map(int, input().split())
l.append([b, r, j, 0])
l.sort(key=lambda x: x[0])
k = 0
m = l[0][1]
while k < n - 1 and m >= l[k + 1][0]:
if l[k + 1][1] > m:
m = l[k + 1][1]
k += 1
if k == n - 1:
print(-1)
else:
for j in range(k + 1):
l[j][3] = 1
for j in range(k + 1, n):
l[j][3] = 2
l.sort(key=lambda x: x[2])
for j in range(n):
print(l[j][3], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
class Pair:
def __init__(self, s, i):
b = s.split(" ")
self.left = int(b[0])
self.right = int(b[1])
self.num = i
self.group = 0
t = int(input())
for j in range(0, t):
n = int(input())
arr = []
for i in range(0, n):
arr.append(Pair(input(), i))
arr1 = arr.copy()
arr.sort(key=lambda c: c.right)
minSuf = [None] * n
for i, e in reversed(list(enumerate(arr))):
arr[i].group = 2
if i < n - 1:
minSuf[i] = min(e.left, minSuf[i + 1])
else:
minSuf[i] = e.left
if i > 0 and arr[i - 1].right < minSuf[i]:
for k in range(0, i):
arr[k].group = 1
break
if arr[0].group == 2:
print(-1, end=" ")
else:
for p in arr1:
print(p.group, end=" ")
print()
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
N = int(input())
for i in range(N):
T = int(input())
newtable = []
for i in range(T):
a, b = map(int, input().split())
newtable.append((a, b, i))
newtable.sort()
sta = 0
ans = [-1] * T
flag = 0
t = 0
i = 0
while i < T:
s, t, k = newtable[i]
if t > sta:
sta = t
ans[k] = flag % 2 + 1
i += 1
while i < T and newtable[i][0] <= sta:
x, y, j = newtable[i]
ans[j] = flag % 2 + 1
if y > sta:
sta = y
i += 1
flag += 1
if flag == 1:
print(-1)
else:
print(" ".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())) + [i] for i in range(n))
ans = [0] * n
group = 1
maxx = a[0][1]
for l, r, i in a:
if group == 1 and maxx < l:
group = 2
if r > maxx:
maxx = r
ans[i] = group
if group == 2:
print(*ans)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for t in range(T):
l = []
N = int(input())
ans = [0] * N
for n in range(N):
a, b = map(int, input().split())
l.append((a, b, n))
l.sort()
ans[l[0][2]] = 1
MAX = l[0][1]
for i in range(1, N):
if l[i][0] > MAX:
break
ans[l[i][2]] = 1
MAX = max(MAX, l[i][1])
else:
print(-1)
continue
for i in range(i, N):
ans[l[i][2]] = 2
for i in ans:
print(i, end=" ")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
l = []
for i in range(0, n):
a, b = map(int, input().split())
l.append((min(a, b), max(a, b), i))
l.sort()
grp = 1
prev = int(0)
j = int(0)
ans = []
for curr, r, i in l:
if grp == 2:
ans.append((i, 2))
elif curr > prev and j != 0:
ans.append((i, 2))
grp = 2
else:
ans.append((i, 1))
prev = max(prev, r)
j += 1
if grp == 1:
print(-1)
else:
ans.sort()
for i in range(0, n):
print(ans[i][1], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for l00p in range(int(input())):
a = []
ans = []
for i in range(int(input())):
ans.append(1)
a.append(tuple(list(int(x) for x in input().split()) + [i]))
a.sort(key=lambda tup: tup[0])
flag = 0
NO = 1
right = a[0][1]
for l, r, pos in a:
if flag:
ans[pos] = 2
continue
if l > right:
ans[pos] = 2
flag = 1
NO = 0
right = max(right, r)
if NO:
print(-1)
else:
for i in ans:
print(i, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
ar = []
for i in range(n):
ar.append(list(map(int, input().split())) + [i])
ar.sort(key=lambda x: x[0])
su = 0
flag = False
ma = ar[0][1]
for i in range(1, n):
if ar[i][0] > ma:
flag = True
break
else:
ma = max(ma, ar[i][1])
if flag:
ans = [0] * n
for j in range(i):
ans[ar[j][2]] = 1
for j in range(i, n):
ans[ar[j][2]] = 2
print(*ans)
else:
print(-1)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
n = int(input())
dp = [(2) for i in range(n)]
lst = [(0) for i in range(2 * n)]
count = 0
for i in range(n):
u, v = map(int, input().split())
lst[count] = [u, -1, i]
lst[count + 1] = [v, 1, i]
count += 2
lst.sort()
total = 0
for i in lst:
total = total - i[1]
if total > 0:
dp[int(i[-1])] = 1
else:
break
if dp.count(1) == n:
print(-1)
else:
print(*dp)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER LIST VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
from itertools import accumulate
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
lr = [(list(map(int, input().split())) + [i]) for i in range(n)]
lr.sort()
mx = [lr[0][1]]
for i in range(1, n):
mx.append(max(mx[-1], lr[i][1]))
flg = 0
ans = [(1) for i in range(n)]
for i in range(n):
l, r, idx = lr[i]
if i > 0:
if flg or l > mx[i - 1]:
ans[idx] = 2
flg = 1
if flg == 0:
print(-1)
continue
else:
print(*ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def ii():
return int(input())
def li():
return list(map(int, input().split()))
def mi():
return map(int, input().split())
for _ in range(ii()):
N = ii()
ar = [(li() + [i]) for i in range(N)]
ar.sort()
last = ar[0][0]
ans = [2] * N
for l, r, i in ar:
if l > last:
break
ans[i] = 1
last = max(last, r)
if 2 in ans:
print(*ans)
else:
print(-1)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
class Interval:
def __init__(self, le, ri):
self.le = le
self.ri = ri
self.group = -1
def __repr__(self):
return f"({self.le}, {self.ri})"
T = int(input())
for t in range(T):
N = int(input())
a = [None] * N
for i in range(N):
a[i] = Interval(*map(int, input().split()))
b = sorted(a, key=lambda _i: _i.ri)
curr = 0
for i in range(1, N):
if b[i].le <= b[curr].ri:
curr = i
for i in range(N):
b[i].group = "1" if i <= curr else "2"
if curr == N - 1:
print(-1)
else:
print(" ".join(str(a[i].group) for i in range(N)))
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR STRING STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for _ in range(T):
n = int(input())
events = []
results = [(0) for i in range(n)]
fail = False
for i in range(n):
l, r = map(int, input().split())
events.append((l, 0, i))
events.append((r, 1, i))
events.sort()
cnt = 0
cur_seg = 1
for _, t, i in events:
if t == 0:
cnt += 1
results[i] = cur_seg
else:
cnt -= 1
if cnt == 0:
cur_seg = 1 + cur_seg % 2
if len(set(results)) == 2:
print(*results)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for test in range(t):
n = int(input())
ans = ["1" for i in range(n)]
start, end = dict(), dict()
for i in range(n):
a, b = list(map(int, input().split()))
if a in start:
start[a].append(i + 1)
else:
start[a] = [i + 1]
if i + 1 in end:
end[i + 1].append(b)
else:
end[i + 1] = [b]
st_sorted = sorted(list(start.keys()))
m = 0
ok = False
ans_pos = -1
for pos in range(len(st_sorted) - 1):
for i in start[st_sorted[pos]]:
m = max(m, max(end[i]))
if m < st_sorted[pos + 1]:
ok = True
ans_pos = pos
break
if ok:
for i in range(pos + 1, len(st_sorted)):
for pos in start[st_sorted[i]]:
ans[pos - 1] = "2"
print(" ".join(ans))
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def solve(coords, ans):
n = len(coords)
coords1 = coords[:]
coords1.sort()
groups = []
min_val, max_val = coords1[0][0], coords1[0][1]
for i in range(1, n):
x, y = coords1[i][0], coords1[i][1]
if x <= max_val:
max_val = max(max_val, y)
elif len(groups) == 0:
groups.append((min_val, max_val))
min_val = x
max_val = y
else:
max_val = max(max_val, y)
groups.append((min_val, max_val))
if len(groups) != 2:
ans.append([-1])
return
ans1 = []
for i in coords:
x, y = i[0], i[1]
for j in range(2):
l, r = groups[j][0], groups[j][1]
if x >= l and y <= r:
ans1.append(j + 1)
break
ans.append(ans1)
def main():
t = int(input())
ans = []
for i in range(t):
n = int(input())
coords = []
for j in range(n):
x, y = map(int, input().split())
coords.append((x, y))
solve(coords, ans)
for i in ans:
for j in i:
print(j, end=" ")
print()
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER RETURN ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for _ in range(T):
n = int(input())
s = []
for k in range(n):
l, r = [int(i) for i in input().split()]
s.append([l, 1, k])
s.append([r, 2, k])
s.sort()
u = [2] * n
o = set()
for i in s:
u[i[2]] = 1
if i[2] not in o:
o.add(i[2])
else:
o.remove(i[2])
if not o:
if i != s[-1]:
print(*u)
break
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for i in range(T):
n = int(input())
X = []
for j in range(n):
l, r = map(int, input().split())
X.append([j, l, r])
X = sorted(X, key=lambda x: x[1])
Y = ["2"] * n
s = -1
rmax = X[0][2]
Y[X[0][0]] = "1"
for i in range(1, n):
if X[i][1] > rmax:
s = i
break
rmax = max(rmax, X[i][2])
Y[X[i][0]] = "1"
if s < 0:
print(-1)
else:
print(" ".join(Y))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
x, y = map(int, input().split())
l.append((x, y, i))
l.sort()
l1 = l[0][0]
r1 = l[0][1]
g = 1
groups = [0] * n
for i in range(n):
if l[i][0] > r1:
g = 2
groups[l[i][2]] = g
r1 = max(r1, l[i][1])
if g == 1:
print(-1)
else:
print(*groups)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
sobs = []
for j in range(n):
a, b = map(int, input().split())
sobs.append([[a, -1], j])
sobs.append([[b, 1], j])
sobs.sort()
counts = 0
passed = []
success = []
alls = [(0) for q in range(n)]
succeed = False
for sob in sobs:
if succeed:
if sob[0][1] == -1:
pass
else:
success.append(sob[1])
continue
if sob[0][1] == -1:
counts += 1
else:
counts -= 1
passed.append(sob[1])
if counts == 0:
succeed = True
if succeed and success:
for a in passed:
alls[a] = 1
for b in success:
alls[b] = 2
print(*alls)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST LIST VAR NUMBER VAR EXPR FUNC_CALL VAR LIST LIST VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR IF VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())) + [i] for i in range(n))
cut = a[0][1]
ans = [2] * n
ok = False
for i in range(n):
if cut < a[i][0]:
for k in range(i):
ans[a[k][2]] = 1
ok = True
break
cut = max(cut, a[i][1])
if ok == True:
print(*ans)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
MOD = 10**9 + 7
I = lambda: list(map(int, input().split()))
(t,) = I()
while t:
t -= 1
(n,) = I()
a = [2] * n
l = []
for i in range(n):
l.append(I() + [i])
l.sort()
mn = l[0][0]
mx = l[0][1]
i = 0
while i < n and l[i][0] <= mx:
mx = max(mx, l[i][1])
a[l[i][2]] = 1
i += 1
if all([(i == 1) for i in a]) or all([(i == 2) for i in a]):
print(-1)
else:
print(*a)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
test = int(input())
for irene in range(test):
a = []
n = int(input())
ans = ["1"] * n
for i in range(n):
a.append((*map(int, input().split()), i))
a.sort()
tnt, mn = -1, 0
for l, r, i in a:
if l > mn:
tnt += 1
mn = max(mn, r)
if tnt % 2:
ans[i] = "2"
if tnt == 0:
print(-1)
else:
print(" ".join(ans))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
pts = []
for i in range(n):
a, b = map(int, input().split())
pts.append((a, b, i))
pts = sorted(pts)
mark = [(1) for i in range(n)]
ok = 0
mi = pts[0][0]
ma = pts[0][1]
for i in range(n - 1):
if ok:
mark[pts[i + 1][2]] = 2
continue
seg1 = pts[i + 1]
if max(seg1[0], mi) > min(seg1[1], ma):
mark[seg1[2]] = 2
ok = 1
else:
mi = min(mi, seg1[0])
ma = max(ma, seg1[1])
if not ok:
print(-1)
else:
print(*mark)
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for i in range(T):
n = int(input())
inp = []
temp = []
for j in range(n):
a, b = [int(u) for u in input().split()]
inp.append([a, b])
temp.append([a, b])
inp.sort()
check = 0
begin = inp[0][0]
end = inp[0][1]
for j in range(n):
if inp[j][0] > end:
check = 1
break
if inp[j][1] > end:
end = inp[j][1]
ans = []
if check == 0:
print(-1)
else:
for j in range(n):
if temp[j][0] >= begin and temp[j][1] <= end:
ans.append("1")
else:
ans.append("2")
print(" ".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
inf = float("inf")
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline()
for _ in range(int(input())):
n = int(input())
l = sorted(get_array() + [i] for i in range(n))
right = l[0][1]
count = 0
for i in range(n):
if l[i][0] > right:
break
right = max(right, l[i][1])
count += 1
if count == n:
print(-1)
else:
ans = [1] * n
for j in l:
ans[j[2]] = 2
count -= 1
if not count:
break
print(*ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def get():
return list(map(int, input().split(" ")))
def d():
n = int(input())
t = []
for i in range(n):
t.append(get() + [i])
t.sort()
i = 0
r = t[0][1]
ans = ["2"] * n
while i < n and t[i][0] <= r:
ans[t[i][2]] = "1"
r = max(r, t[i][1])
i += 1
if "2" in ans:
print(" ".join(ans))
else:
print(-1)
for i in range(int(input())):
d()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR WHILE VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for _ in range(T):
n = int(input())
seg = []
for s in range(n):
l, r = [int(x) for x in input().split()]
seg.append((l, r))
pos = {}
for i in range(n):
if seg[i] in pos:
pos[seg[i]].append(i)
else:
pos[seg[i]] = [i]
seg.sort()
right = seg[0][1]
goodindex = -1
for j in range(1, n):
if seg[j][0] > right:
goodindex = j
break
right = max(right, seg[j][1])
if goodindex == -1:
print(-1)
else:
ans = ["2"] * n
for i in range(goodindex):
ans[pos[seg[i]][-1]] = "1"
pos[seg[i]].pop()
print(" ".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
q = int(input())
lst = []
for c in range(q):
a, b = map(int, input().split())
lst.append([a, b, c])
lst.sort()
p = -1
m = lst[0][1]
for c in range(len(lst) - 1):
m = max(m, lst[c][1])
if m < lst[c + 1][0]:
p = c
break
if p == -1:
print("-1")
else:
lst2 = [(2) for r in range(len(lst))]
for r in range(p + 1):
lst2[lst[r][2]] = 1
print(*lst2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for i in range(T):
n = int(input())
seg = []
for i in range(n):
seg.append([int(i) for i in input().split()] + [i])
seg.sort()
gp = [1] * n
ans = [-1] * n
end = seg[0][1]
for i in range(n):
if seg[i][0] <= end:
gp[i] = gp[i - 1]
else:
gp[i] = gp[i - 1] + 1
end = max(seg[i][1], end)
ans[seg[i][2]] = gp[i]
if gp[-1] == 1:
print(-1)
else:
for x in ans:
if x == 1:
print("1", end=" ")
else:
print("2", end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
t = int(input())
for i in range(t):
n = int(input())
a = []
for j in range(n):
l, r = map(int, sys.stdin.readline().split())
a.append([l, r, j])
c = [2] * n
a.sort()
j = 0
m1 = a[0][1]
while j < n:
p = a[j][0]
q = a[j][1]
if p <= m1:
m1 = max(m1, q)
c[a[j][2]] = 1
else:
break
j = j + 1
if 2 not in c:
print(-1)
else:
print(" ".join(map(str, c)))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
while t:
d = []
lol = 0
lo = 0
prev = 0
ind = -1
cou = 0
n = int(input())
for i in range(n):
l, r = map(int, input().split())
d.append((l, r))
d1 = sorted(d)
for i in d1:
l, r = i[0], i[1]
cou += 1
if cou == 1:
l1 = l
r1 = r
elif r < l1 or l > r1 and ind == -1:
if r < l1:
ind = l1
else:
ind = l
else:
l1 = min(l, l1)
r1 = max(r, r1)
cou = 0
if ind == -1:
print(-1, end=" ")
else:
for i in d:
if i[0] <= ind - 1 and i[1] <= ind - 1:
print(1, end=" ")
else:
print(2, end=" ")
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
n = int(input())
a = []
f = 0
for i in range(n):
l, r = map(int, input().split())
a.append([l, r, i])
a.sort(key=lambda x: x[0])
rm = a[0][1]
for i in range(n):
if a[i][0] > rm:
b = a[i]
f = 1
break
if a[i][1] > rm:
rm = a[i][1]
if f == 0:
print(-1)
else:
a.sort(key=lambda x: x[2])
for i in range(n):
if a[i][0] < b[0]:
print(1, end=" ")
else:
print(2, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
q = int(input())
for i in range(0, q):
n = int(input())
l = []
r = []
for j in range(0, n):
l1, r1 = map(int, input().split())
l += [l1]
r += [(l1, r1)]
r.sort()
l1 = -1
rm = -1
for j in range(0, n - 1):
if r[j][1] > rm:
rm = r[j][1]
if rm < r[j + 1][0]:
l1 = r[j + 1][0]
break
if l1 == -1:
print(-1, end="")
else:
for j in range(0, n):
if l[j] < l1:
print(1, end=" ")
else:
print(2, end=" ")
print()
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
n = int(input())
segments = []
for i in range(n):
l, r = map(int, input().split())
segments.append([l, r, i])
segments.sort()
ans = [(1) for i in range(n)]
prev = 1
maxR = 0
ansOfMaxR = 1
for i in range(n):
cl, cr, ci = segments[i]
if i == 0:
maxR = cr
ans[ci] = 1
prev = 1
ansOfMaxR = 1
else:
if cl > maxR:
if ansOfMaxR == 1:
ans[ci] = 2
prev = 2
elif ansOfMaxR == 2:
ans[ci] = 1
prev = 1
else:
ans[ci] = ansOfMaxR
prev = ansOfMaxR
if cr > maxR:
maxR = cr
ansOfMaxR = ans[ci]
if len(set(ans)) == 2:
print(*ans)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
q = int(input())
for i in range(q):
rec = []
n = int(input())
flag = False
ans = [1] * n
for j in range(n):
l, r = map(int, input().split())
rec.append((l, r, j))
rec = sorted(rec)
k = rec[0][1]
for a in range(n):
if k < rec[a][0]:
flag = True
for b in range(a):
ans[rec[b][2]] = 2
break
k = max(k, rec[a][1])
if flag:
print(" ".join(map(str, ans)))
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for t in range(T):
n = int(input())
l = [0] * n
r = [0] * n
for i in range(n):
l[i], r[i] = [int(x) for x in input().split()]
gr = [0] * n
sl = [*range(n)]
sl.sort(key=lambda x: l[x])
tr = r[sl[0]]
g = 1
for i in range(n):
tl = l[sl[i]]
if tl > tr:
g = 2
for j in range(i, n):
gr[sl[j]] = 2
break
else:
gr[sl[i]] = 1
tr = max([tr, r[sl[i]]])
if g == 1:
print(-1)
else:
print(*gr)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in [0] * int(input()):
n = int(input())
t = [0] * n
g = c = k = 0
a = sorted(
sum(
zip(
*(
((l, 1, i), (r + 1, 0, i))
for (l, r), i in ((map(int, input().split()), i) for i in range(n))
)
),
(),
)
)
for x, m, i in a:
if m:
if c == 0:
k += 1
g ^= 1
t[i] = g + 1
c += 1
else:
c -= 1
if k < 2:
print(-1)
else:
print(*t)
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
n = int(input())
l = []
for i in range(n):
li, ri = map(int, input().split())
l.append([li, ri, i, 1])
l.sort(key=lambda x: x[0])
r = l[0][1]
for i in range(1, n):
if l[i][0] <= r:
l[i][3] = 1
r = max(r, l[i][1])
else:
l[i][3] = 2
b = False
for i in range(1, n):
if l[i][3] != l[i - 1][3]:
b = True
if not b:
print(-1)
else:
l.sort(key=lambda x: x[2])
for i in range(n):
print(l[i][3], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin
t = int(input())
res = []
for _ in range(t):
n = int(input())
xs = [(list(map(int, stdin.readline().strip().split())) + [i]) for i in range(n)]
xs.sort()
rs = [1] * n
q = 1
ml, mr = 0, xs[0][1]
for l, r, i in xs:
if q == 1 and l <= mr:
mr = max(mr, r)
elif q == 1:
q = 2
rs[i] = q
if q == 1:
rs = [-1]
res.append(" ".join(map(str, rs)))
print("\n".join(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def solve():
n = int(input())
points = []
for i in range(n):
l, r = [int(x) for x in input().split()]
points.append((l, r, i))
points.sort()
border = -1
cnt_sets = 1
cur_set = 0
ans = [(0) for _ in range(n)]
for l, r, pos in points:
if (l > border and border < r) and border != -1:
cnt_sets += 1
cur_set ^= 1
border = max(l, r)
else:
border = max(border, r, l)
ans[pos] = cur_set
if cnt_sets == 1:
print(-1)
return
ans = [(x + 1) for x in ans]
print(*ans)
def main():
t = int(input())
for _ in range(t):
solve()
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for i in range(int(input())):
l = []
n = int(input())
for j in range(n):
x, y = map(int, input().split())
l.append((min(x, y), max(x, y), j))
ans = []
group = " 1"
prev = int(0)
j = int(0)
l.sort()
for cur, b, c in l:
if group == " 2":
ans.append((c, 2))
elif cur > prev and j != 0:
ans.append((c, 2))
group = " 2"
else:
ans.append((c, 1))
prev = max(prev, b)
j += 1
if group == " 1":
print("-1")
else:
ans.sort()
for a, b in ans:
print(b, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for j in range(int(input())):
n = int(input())
s = []
ind = [int(0)] * n
for i in range(n):
s.append(tuple(list(map(int, input().split())) + [i]))
s.sort()
mx = max(s[0][0], s[0][1])
ind[s[0][2]] = 1
for i in range(1, len(s)):
if mx < min(s[i][0], s[i][1]):
break
mx = max(s[i][0], s[i][1], mx)
ind[s[i][2]] = 1
if sum(ind) == n:
print(-1, end=" ")
else:
for i in ind:
print(i + 1, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def solve(n, lrs):
elements = enumerate(lrs)
elements = list(sorted(elements, key=lambda x: x[1][1]))
i, j = 0, n - 1
g_1 = elements[i][1]
g_2 = elements[j][1]
a_group_index = [elements[i][0]]
b_group_index = [elements[j][0]]
while len(a_group_index) + len(b_group_index) < n:
while i + 1 != j and g_1[1] >= elements[i + 1][1][0]:
i += 1
a_group_index.append(elements[i][0])
g_1[1] = max(g_1[1], elements[i][1][1])
while j - 1 != i and g_2[0] <= elements[j - 1][1][1]:
j -= 1
b_group_index.append(elements[j][0])
g_2[0] = min(g_2[0], elements[j][1][0])
if len(a_group_index) + len(b_group_index) == n:
break
i += 1
a_group_index.append(elements[i][0])
g_1[1] = max(g_1[1], elements[i][1][1])
if g_1[1] >= g_2[0]:
return "-1"
r = [0] * n
for e in a_group_index:
r[e] = 1
for e in b_group_index:
r[e] = 2
return " ".join(map(str, r))
for _ in range(int(input())):
n = int(input())
lrs = [list(map(int, input().split())) for _ in range(n)]
print(solve(n, lrs))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR NUMBER ASSIGN VAR LIST VAR VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for t in range(T):
n = int(input())
arr = [[None for x in range(3)] for y in range(n)]
for i in range(n):
user_in = input()
a, b = user_in.split(" ")
a = int(a)
b = int(b)
arr[i] = [a, b, i]
arr.sort()
val = 0
d = [None for x in range(n)]
d[arr[0][2]] = 1
length = arr[0][1]
for i in range(1, n):
if arr[i][0] > length:
if d[arr[i - 1][2]] == 1:
d[arr[i][2]] = 2
val = 1
else:
d[arr[i][2]] = 1
else:
d[arr[i][2]] = d[arr[i - 1][2]]
length = max(length, arr[i][1])
if val == 0:
print(-1)
else:
sarr = [str(a) for a in d]
print(" ".join(sarr))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
q = int(input())
d = dict()
main = []
rese = []
for i in range(q):
l, r = map(int, input().split())
d[hash((l, r))] = -1
main.append([l, r])
rese.append([l, r])
main.sort()
new_l = main[0][0]
new_r = main[0][1]
d[hash((new_l, new_r))] = 1
flag = False
for i in range(1, q):
if i != 0:
if new_l <= main[i][0] and new_r >= main[i][0]:
new_r = max(main[i][1], new_r)
d[hash((main[i][0], main[i][1]))] = 1
else:
flag = True
d[hash((main[i][0], main[i][1]))] = 2
if flag:
break
if flag:
for i in range(q):
if d[hash((rese[i][0], rese[i][1]))] in [1, 2]:
print(d[hash((rese[i][0], rese[i][1]))], end=" ")
else:
print(2, end=" ")
print()
else:
print("-1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
lr = [((i,) + tuple(map(int, input().split()))) for i in range(n)]
lr.sort(key=lambda k: k[2])
l_min = 10**6
for i in range(n - 1, 0, -1):
l_min = min(l_min, lr[i][1])
div = lr[i - 1][2]
if div < l_min:
ans = [0] * n
for j in range(n):
if j < i:
ans[lr[j][0]] = 1
else:
ans[lr[j][0]] = 2
print(*ans)
break
else:
print(-1)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def check(data):
n = len(data)
s = sorted(zip(data, range(n)))
m = s[0][0][1]
left = set()
for i, r in enumerate(s):
left.add(r[1])
if i == len(s) - 1:
return "-1"
m = max(m, r[0][1])
if s[i + 1][0][0] > m:
break
res = [("1" if j in left else "2") for j in range(n)]
return " ".join(res)
T = int(input())
for i in range(T):
n = int(input())
data = []
for j in range(n):
l, r = map(int, input().split())
data.append((l, r))
print(check(data))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR VAR STRING STRING VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for i in range(0, T):
n = int(input())
L = []
dp = [0] * n
for j in range(0, n):
l, r = map(int, input().split())
L.append((l, r, j))
L = sorted(L)
temp = -1
ed = L[0][1]
for j in range(1, len(L)):
if L[j][0] > ed:
temp = j
break
ed = max(ed, L[j][1])
if temp == -1 or n == 1:
print(-1)
else:
for j in range(0, len(L)):
if j < temp:
dp[L[j][2]] = 1
else:
dp[L[j][2]] = 2
for j in range(0, n):
print(dp[j], end=" ")
print(" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
arr = []
for j in range(n):
arr.append(tuple(map(int, (input() + " " + str(j)).split())))
arr.sort()
grp = [(1) for j in range(n)]
grp[n - 1] = 2
pos = False
highest = -1
for j in range(n - 1):
highest = max(highest, arr[j][1])
if highest < arr[j + 1][0]:
for k in range(j + 1, n):
grp[k] = 2
pos = True
if not pos:
print(-1)
else:
ans = [(0) for j in range(n)]
for j in range(n):
ans[arr[j][2]] = grp[j]
print(" ".join(str(i) for i in ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
data = []
for q in range(n):
x, y = map(int, input().split())
data.append([x, y, q])
data.sort()
ans = [-1] * n
ans[data[0][2]] = 0
pivot = 0
prev = data[0][1]
for q in range(1, n):
if data[q][0] <= prev:
ans[data[q][2]] = ans[data[q - 1][2]]
prev = max(prev, data[q][1])
else:
pivot = (pivot + 1) % 2
ans[data[q][2]] = pivot
prev = data[q][1]
minus_cnt = ans.count(-1)
if minus_cnt != 0:
print(-1)
elif len(set(ans)) == 1:
print(-1)
else:
for q in ans:
print(q + 1, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
n = int(stdin.readline().strip())
arr = []
for i in range(n):
l, r = list(map(int, stdin.readline().split()))
arr.append([l, r, i])
arr = sorted(arr, key=lambda x: (x[0], x[1], x[2]))
mydict = dict()
mydict[arr[0][2]] = 1
mn = arr[0][0]
mx = arr[0][1]
group = 1
for i in range(1, n):
if arr[i][0] <= mx:
mx = max(mx, arr[i][1])
mydict[arr[i][2]] = group
else:
group += 1
mn = arr[i][0]
mx = max(mx, arr[i][1])
mydict[arr[i][2]] = group
if group >= 2:
for i in range(n):
if mydict[i] > 1:
print(2, end=" ")
else:
print(1, end=" ")
else:
print(-1, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
T = int(input())
for _ in range(T):
n = int(input())
snts = []
for i in range(n):
l, r = list(map(int, input().split()))
snts.append([l, r, i])
snts = sorted(snts, key=lambda x: x[0])
res = [1]
rs, v, ids = [snts[0][1], -1], 0, [snts[0][2]]
for i in range(1, n):
l, r, id = snts[i]
ids.append(id)
if l <= rs[v]:
res.append(v + 1)
rs[v] = max(rs[v], r)
else:
res.append(2)
if len(set(res)) == 1:
print("-1")
else:
res = sorted(zip(ids, res), key=lambda x: x[0])
res = [item[1] for item in res]
print(" ".join(map(str, res)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR VAR LIST VAR NUMBER NUMBER NUMBER NUMBER LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
a = []
for i in range(n):
x, y = list(map(int, input().split()))
a.append([x, y, i])
a.sort()
i = 0
m = a[i][1]
b = ["2"] * n
while i < n and m >= a[i][0]:
b[a[i][2]] = "1"
m = max(m, a[i][1])
i += 1
if "2" in b:
print(" ".join(b))
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
q = int(input())
while q > 0:
q = q - 1
L = []
n = int(input())
for i in range(n):
L.append(tuple(map(int, input().split())))
d = {}
ind = 0
for i in L:
if i not in d:
d[i] = []
d[i].append(ind)
ind += 1
S = sorted(L)
r = S[0][1]
i = 1
while i < n:
if S[i][0] > r:
break
r = max(r, S[i][1])
i += 1
if i == n:
print(-1)
else:
while i < n:
d[S[i]].append(-2)
i += 1
for i in L:
if d[i][-1] == -2:
print(2, end=" ")
else:
print(1, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in [0] * int(input()):
n = int(input())
a = []
for i in range(n):
a += zip(map(int, input().split()), (i, n))
a.sort()
g = c = 0
t = [2] * n
for x, i in a:
if i < n:
c += 1
g += c == 1
t[i] -= g % 2
else:
c -= 1
if g < 2:
t = (-1,)
print(*t)
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def sol():
def f(el):
return el[0]
am = int(input())
arr = [0] * am
out = [0] * am
for i in range(am):
arr[i] = list(map(int, input().split())) + [i]
arr.sort(key=f)
lType = 0
endAt = arr[0][1]
count = [1, 0]
out[arr[0][2]] = 1
for i in range(1, am):
if arr[i][0] > endAt:
lType = lType + 1 & 1
count[lType] += 1
out[arr[i][2]] = lType + 1
endAt = max(endAt, arr[i][1])
if count[0] == 0 or count[1] == 0:
print(-1)
return 0
print(*out)
for i in range(int(input())):
sol()
|
FUNC_DEF FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def main():
t = int(input())
for _ in range(t):
n = int(input())
segments = []
for i in range(n):
l, r = map(int, input().split())
segments.append((l, r, i))
segments.sort(key=lambda x: (x[0], -x[1]))
flag = False
ret = [0] * n
ret[segments[0][2]] = 1
max_y = segments[0][1]
for i in range(1, n):
if flag:
ret[segments[i][2]] = 2
else:
cur_seg = segments[i]
if cur_seg[0] > max_y:
ret[cur_seg[2]] = 2
flag = True
else:
ret[cur_seg[2]] = 1
max_y = max(max_y, cur_seg[1])
if not flag:
print(-1)
else:
for i in range(n):
print(ret[i], end=" ")
print("")
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
lis = []
for i in range(n):
a, b = map(int, input().split())
lis.append([a, b, i + 1])
lis.sort()
ans = [2] * (n + 1)
ans[0] = 0
j = lis[0][1]
ans[lis[0][2]] = 1
for i in range(1, n):
a, b, c = lis[i]
if j >= a:
ans[c] = 1
j = max(j, b)
if sum(ans) == n:
print(-1)
else:
print(*ans[1:])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def intersect(seg, e):
X1 = seg[0]
X2 = seg[1]
X3 = e[0]
X4 = e[1]
if max(X1, X2) < min(X3, X4):
return False
return True
t = int(input())
for i in range(t):
n = int(input())
l = [0] * n
group = ["0"] * n
for i in range(n):
l[i] = list(map(int, input().split()))
l[i].append(i)
l.sort()
seg1 = []
seg2 = []
for e in l:
if not seg1:
seg1 = [e[0], e[1]]
group[e[2]] = "1"
elif intersect(seg1, e):
seg1 = [
min(seg1[0], seg1[1], e[0], e[1]),
max(seg1[0], seg1[1], e[0], e[1]),
]
group[e[2]] = "1"
elif not seg2:
seg2 = [e[0], e[1]]
group[e[2]] = "2"
elif intersect(seg2, e):
seg2 = [
min(seg2[0], seg2[1], e[0], e[1]),
max(seg2[0], seg2[1], e[0], e[1]),
]
group[e[2]] = "2"
elif not intersect(seg1, e) and not intersect(seg2, e):
group[e[2]] = "2"
if len(set(group)) == 1:
print(-1)
else:
print(" ".join(group))
|
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin
t = int(input())
while t > 0:
n = int(input())
li = []
for i in range(n):
l, r = [int(x) for x in stdin.readline().split()]
li.append((l, r, i))
li2 = sorted(li)
ans = [2] * n
ans[li2[0][2]] = 1
d = li2[0][1]
count = 0
for i in range(1, len(li2)):
c = li2[i][0]
if c > d:
count += 1
ans[li2[i][2]] = 2
break
else:
ans[li2[i][2]] = 1
d = max(d, li2[i][1])
if count == 0:
print(-1)
else:
print(*ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for tc in range(t):
n = int(input())
l = []
for i in range(n):
a, b = map(int, input().split())
l.append([i, a, b])
l = sorted(l, key=lambda x: x[1])
last = l[0][1]
i = 0
while i < n:
if l[i][1] > last:
break
last = max(last, l[i][2])
i += 1
if i == n:
print(-1)
else:
ind = [2] * n
for j in range(i):
ind[l[j][0]] = 1
for i in ind:
print(i, end=" ")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
for _ in range(int(input())):
n = int(input())
ra = []
mn = [1] * n
for i in range(n):
x, y = map(int, input().split())
ra.append((x, y, i))
ra.sort()
l = ra[0][0]
r = ra[0][1]
g = 1
for i in ra:
if i[0] > r:
g = 2
mn[i[2]] = g
r = max(i[1], r)
print(*mn) if len(set(mn)) > 1 else print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
n = int(input())
for t in range(n):
k = int(input())
samples = []
for i in range(k):
samples.append(tuple(map(int, input().split())))
samples = sorted(enumerate(samples), key=lambda x: x[1])
tick = 1
ans = [1]
group_end = samples[0][1][1]
for si in range(1, len(samples)):
now = samples[si][1]
if now[0] > group_end:
tick = 2
else:
group_end = max(now[1], group_end)
ans.append(1)
if tick == 2:
ans.extend([2] * (len(samples) - si))
break
ans = sorted(zip(samples, ans))
ans = list([x[1] for x in ans])
if 2 not in ans:
print(-1)
else:
print(" ".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
from sys import stdin
inp = lambda: stdin.readline().split()
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
mas = [tuple(map(int, inp())) for i in range(n)]
d = {}
for i, x in enumerate(mas):
if d.get(x) == None:
d[x] = []
d[x].append(i)
lst = sorted(mas)
res, k = [1] * n, 0
res[d[lst[0]].pop()] = 2
k, last = 0, lst[0][1]
for i, x in enumerate(lst[1:]):
if last < x[0]:
k = 1
break
last = max(last, x[1])
res[d[x].pop()] = 2
if k == 0:
print(-1)
else:
print(*res)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for i in range(t):
n = int(input())
llist = []
rlist = []
index = []
groups = []
for j in range(n):
l, r = map(int, input().split())
llist.append(l)
rlist.append(r)
index.append(j)
groups.append(0)
llist, rlist, index = zip(*sorted(zip(llist, rlist, index)))
groups[index[0]] = 1
now = 1
maxx = rlist[0]
for k in range(1, n):
if now == 1:
maxx = max(maxx, rlist[k - 1])
if llist[k] <= maxx:
groups[index[k]] = now
else:
if now == 1:
now += 1
groups[index[k]] = now
if now == 1:
print(-1)
else:
print(*groups)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
L = 0
R = 1
def main():
buf = input()
T = int(buf)
n = []
lr = []
for i in range(T):
buf = input()
n.append(int(buf))
lr.append([])
for j in range(n[i]):
buf = input()
buflist = buf.split()
lr[i].append([int(buflist[0]), int(buflist[1])])
for i in range(T):
lr_s = list(sorted(lr[i]))
threshold = lr_s[0][R]
threshold_final = None
for j in range(1, n[i]):
if threshold < lr_s[j][L]:
threshold_final = threshold
break
elif threshold < lr_s[j][R]:
threshold = lr_s[j][R]
if threshold_final == None:
print(-1)
continue
answer = ""
for j in range(n[i]):
if lr[i][j][L] <= threshold_final:
answer += "1"
else:
answer += "2"
if j < n[i] - 1:
answer += " "
print(answer)
main()
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR STRING VAR STRING IF VAR BIN_OP VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for ti in range(t):
n = int(input())
lri = [None for _ in range(n)]
for _ in range(n):
li, ri = map(int, input().split())
lri[_] = li, ri, _
lri.sort()
t = [None for _ in range(n)]
ct, t[lri[0][2]], eg = 1, 1, lri[0][1]
for i in range(1, n):
if lri[i][0] <= eg:
t[lri[i][2]] = ct
eg = max(eg, lri[i][1])
else:
ct = 3 - ct
t[lri[i][2]] = ct
eg = lri[i][1]
if all(ti == 1 for ti in t):
print(-1)
else:
print(*t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
def answer(n, p):
p.sort(key=lambda x: x[0])
l = [[p[0][0], p[0][1]]]
ans = [2] * n
ans[p[0][2]] = 1
for i in range(1, n):
if p[i][0] <= l[-1][1]:
l[-1][1] = max(l[-1][1], p[i][1])
if len(l) == 1:
ans[p[i][2]] = 1
else:
l.append([p[i][0], p[i][1]])
if len(l) == 1:
return [-1]
else:
return ans
t = int(input())
for i in range(t):
n = int(input())
A = []
for j in range(n):
s, e = map(int, input().split())
A.append([s, e, j])
print(*answer(n, A))
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN LIST NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and xΒ·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 β€ n β€ 105) β the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 β€ ai β€ 109) β sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
|
def datatypes(x, answer):
for i in range(1, n):
if x[i] < 2 * x[i - 1] and x[i] != x[i - 1]:
answer = "YES"
break
print(answer)
n = int(input())
x = list(map(int, input().split()))
x.sort()
answer = "NO"
datatypes(x, answer)
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.