text stringlengths 759 21.3k | conversation_id int64 1.95k 109k | embedding sequence | cluster int64 17 17 |
|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 β€ li β€ vi β€ ri β€ 3Β·105) β the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
Output
In the first line print a single integer m β the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers β the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
Examples
Input
4
2 8 9
1 4 7
3 6 8
5 8 10
Output
3
1 3 4
Input
6
3 5 16
1 6 11
4 8 12
7 9 16
2 10 14
8 13 15
Output
4
1 2 3 5
Tags: data structures
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
def inp():
return sys.stdin.readline().rstrip()
def mpint():
return map(int, inp().split(' '))
def itg():
return int(inp())
# ############################## import
# 2020/12/17
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the lazy segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self._lazy = [0] * (2 * _size)
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __len__(self):
return self._len
def _push(self, idx):
"""push query on idx to its children"""
# Let the children know of the queries
q, self._lazy[idx] = self._lazy[idx], 0
self._lazy[2 * idx] += q
self._lazy[2 * idx + 1] += q
self.data[2 * idx] += q
self.data[2 * idx + 1] += q
def _update(self, idx):
"""updates the node idx to know of all queries applied to it via its ancestors"""
for i in reversed(range(1, idx.bit_length())):
self._push(idx >> i)
def _build(self, idx):
"""make the changes to idx be known to its ancestors"""
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
idx >>= 1
def add(self, start, stop, value):
"""lazily add value to [start, stop)"""
start = start_copy = start + self._size
stop = stop_copy = stop + self._size
while start < stop:
if start & 1:
self._lazy[start] += value
self.data[start] += value
start += 1
if stop & 1:
stop -= 1
self._lazy[stop] += value
self.data[stop] += value
start >>= 1
stop >>= 1
# Tell all nodes above of the updated area of the updates
self._build(start_copy)
self._build(stop_copy - 1)
def query(self, start, stop, default=None):
"""func of data[start, stop)"""
start += self._size
stop += self._size
# Apply all the lazily stored queries
self._update(start)
self._update(stop - 1)
res = self._default if default is None else default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "LazySegmentTree({})".format(list(map(lambda i: self.query(i, i + 1), range(self._len))))
class SweepLine:
def __init__(self, data=None, inclusive=True):
"""
:param data: [((1, 2), (3, 4)), (left_bottom, right_top), ...]
:param inclusive: include the right bound
"""
if data:
# [((1, 2), (3, 4), 0), ...]
self.data = [(*pair, i) for i, pair in enumerate(data)]
else:
self.data = []
self.discrete_dict = self.restore = None
self.INCLUSIVE = inclusive
def add_rectangle(self, rectangle):
self.data.append((*rectangle, len(self.data)))
def _discrete(self):
st = set()
operations = []
for p1, p2, i in self.data:
st |= {*p1, *p2}
# we want add operation go first, so *= -1
# we calculate the line intersect
operations.append((p1[1], -1, p1[0], p2[0], i)) # add
operations.append((p2[1], 1, p1[0], p2[0], i)) # subtract
self.restore = sorted(st)
self.discrete_dict = dict(zip(self.restore, range(len(st))))
self.operations = sorted(operations)
# print(*self.operations, sep='\n')
def max_intersect(self, get_points=False):
"""
:return intersect, i (ith rectangle)
:return intersect, i, x
"""
if not self.restore:
self._discrete()
d = self.discrete_dict
tree = LazySegmentTree([0] * len(self.restore))
result = 0, None
for y, v, left, right, i in self.operations:
# print(f"left={left}, right={right}")
left, right, v = d[left], d[right], -v
# print(f"dis -> left={left}, right={right}")
tree.add(left, right + self.INCLUSIVE, v)
if v == 1:
intersect = tree.query(left, right + self.INCLUSIVE)
if intersect > result[0]:
result = intersect, i
tree = LazySegmentTree([0] * len(self.restore))
if get_points:
for y, v, left, right, i in self.operations:
left, right, v = d[left], d[right], -v
tree.add(left, right + self.INCLUSIVE, v)
if i == result[1]:
for lf in range(left, right + self.INCLUSIVE):
if tree.query(lf, lf + 1) == result[0]:
return result[0], i, self.restore[lf]
return result
# ############################## main
def main():
n = itg()
data = []
for _ in range(n):
lf, md, rg = mpint()
data.append(((lf, md), (md, rg)))
sweep = SweepLine(data)
ans1, idx, left = sweep.max_intersect(True)
right = data[idx][0][1]
print(ans1)
# print(idx)
# print(f"intersect = {ans1}")
# print(f"left = {left}, right = {right}")
ans2 = []
for i, pair in enumerate(data):
lf, md, rg = pair[0][0], pair[0][1], pair[1][1]
if lf <= left <= md <= right <= rg:
ans2.append(i + 1)
if len(ans2) != ans1:
print(AssertionError, len(ans2))
else:
print(*ans2)
DEBUG = 0
URL = 'https://codeforces.com/contest/377/problem/D'
if __name__ == '__main__':
# 0: normal, 1: runner, 2: interactive, 3: debug
if DEBUG == 1:
import requests
from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
runner = TestCaseRunner(main, URL)
inp = runner.input_stream
print = runner.output_stream
runner.checking()
else:
if DEBUG != 3:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
if DEBUG:
_print = print
def print(*args, **kwargs):
_print(*args, **kwargs)
sys.stdout.flush()
main()
# Please check!
```
| 1,954 | [
0.470703125,
-0.08685302734375,
-0.245361328125,
0.379150390625,
-0.662109375,
-0.8115234375,
0.1968994140625,
0.1478271484375,
0.11572265625,
0.8515625,
0.52734375,
0.194580078125,
0.5361328125,
-0.57177734375,
-0.30517578125,
0.078857421875,
-0.68310546875,
-1.0205078125,
-0.60... | 17 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 β€ li β€ vi β€ ri β€ 3Β·105) β the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
Output
In the first line print a single integer m β the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers β the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
Examples
Input
4
2 8 9
1 4 7
3 6 8
5 8 10
Output
3
1 3 4
Input
6
3 5 16
1 6 11
4 8 12
7 9 16
2 10 14
8 13 15
Output
4
1 2 3 5
Tags: data structures
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
def inp():
return sys.stdin.readline().rstrip()
def mpint():
return map(int, inp().split(' '))
def itg():
return int(inp())
# ############################## import
# 2020/11/17
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the lazy segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self._lazy = [0] * (2 * _size)
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __len__(self):
return self._len
def _push(self, idx):
"""push query on idx to its children"""
# Let the children know of the queries
q, self._lazy[idx] = self._lazy[idx], 0
self._lazy[2 * idx] += q
self._lazy[2 * idx + 1] += q
self.data[2 * idx] += q
self.data[2 * idx + 1] += q
def _update(self, idx):
"""updates the node idx to know of all queries applied to it via its ancestors"""
for i in reversed(range(1, idx.bit_length())):
self._push(idx >> i)
def _build(self, idx):
"""make the changes to idx be known to its ancestors"""
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
idx >>= 1
def add(self, start, stop, value):
"""lazily add value to [start, stop)"""
start = start_copy = start + self._size
stop = stop_copy = stop + self._size
while start < stop:
if start & 1:
self._lazy[start] += value
self.data[start] += value
start += 1
if stop & 1:
stop -= 1
self._lazy[stop] += value
self.data[stop] += value
start >>= 1
stop >>= 1
# Tell all nodes above of the updated area of the updates
self._build(start_copy)
self._build(stop_copy - 1)
def query(self, start, stop, default=None):
"""func of data[start, stop)"""
start += self._size
stop += self._size
# Apply all the lazily stored queries
self._update(start)
self._update(stop - 1)
res = self._default if default is None else default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "LazySegmentTree({})".format(list(map(lambda i: self.query(i, i + 1), range(self._len))))
class SweepLine:
def __init__(self, data=None, inclusive=True):
"""
:param data: [((1, 2), (3, 4)), (left_bottom, right_top), ...]
:param inclusive: include the right bound
"""
if data:
# [((1, 2), (3, 4), 0), ...]
self.data = [(pair[0], pair[1], i) for i, pair in enumerate(data)]
else:
self.data = []
self.discrete_dict = self.restore = None
self.INCLUSIVE = inclusive
def add_rectangle(self, rectangle):
self.data.append((rectangle[0], rectangle[1], len(self.data)))
def _discrete(self):
st = set()
operations = []
for p1, p2, i in self.data:
st |= {p1[0], p1[1], p2[0], p2[1]}
# we want add operation go first, so *= -1
# we calculate the line intersect
operations.append((p1[1], -1, p1[0], p2[0], i)) # add
operations.append((p2[1], 1, p1[0], p2[0], i)) # subtract
self.restore = sorted(st)
self.discrete_dict = dict(zip(self.restore, range(len(st))))
self.operations = sorted(operations)
# print(*self.operations, sep='\n')
def max_intersect(self, get_points=False):
"""
:return intersect, i (ith rectangle)
:return intersect, i, x
"""
if not self.restore:
self._discrete()
d = self.discrete_dict
tree = LazySegmentTree([0] * len(self.restore))
result = 0, None
for y, v, left, right, i in self.operations:
# print(f"left={left}, right={right}")
left, right, v = d[left], d[right], -v
# print(f"dis -> left={left}, right={right}")
tree.add(left, right + self.INCLUSIVE, v)
if v == 1:
intersect = tree.query(left, right + self.INCLUSIVE)
if intersect > result[0]:
result = intersect, i
tree = LazySegmentTree([0] * len(self.restore))
if get_points:
for y, v, left, right, i in self.operations:
left, right, v = d[left], d[right], -v
tree.add(left, right + self.INCLUSIVE, v)
if i == result[1]:
for lf in range(left, right + self.INCLUSIVE):
if tree.query(lf, lf + 1) == result[0]:
return result[0], i, self.restore[lf]
return result
# ############################## main
def main():
n = itg()
data = []
for _ in range(n):
lf, md, rg = mpint()
data.append(((lf, md), (md, rg)))
sweep = SweepLine(data)
ans1, idx, left = sweep.max_intersect(True)
right = data[idx][0][1]
print(ans1)
# print(idx)
# print(f"intersect = {ans1}")
# print(f"left = {left}, right = {right}")
ans2 = []
for i, pair in enumerate(data):
lf, md, rg = pair[0][0], pair[0][1], pair[1][1]
if lf <= left <= md <= right <= rg:
ans2.append(i + 1)
if len(ans2) != ans1:
print(AssertionError, len(ans2))
else:
print(*ans2)
DEBUG = 0
URL = 'https://codeforces.com/contest/377/problem/D'
if __name__ == '__main__':
# 0: normal, 1: runner, 2: interactive, 3: debug
if DEBUG == 1:
import requests
from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
runner = TestCaseRunner(main, URL)
inp = runner.input_stream
print = runner.output_stream
runner.checking()
else:
if DEBUG != 3:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
if DEBUG:
_print = print
def print(*args, **kwargs):
_print(*args, **kwargs)
sys.stdout.flush()
main()
# Please check!
```
| 1,955 | [
0.470703125,
-0.08685302734375,
-0.245361328125,
0.379150390625,
-0.662109375,
-0.8115234375,
0.1968994140625,
0.1478271484375,
0.11572265625,
0.8515625,
0.52734375,
0.194580078125,
0.5361328125,
-0.57177734375,
-0.30517578125,
0.078857421875,
-0.68310546875,
-1.0205078125,
-0.60... | 17 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 β€ li β€ vi β€ ri β€ 3Β·105) β the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
Output
In the first line print a single integer m β the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers β the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
Examples
Input
4
2 8 9
1 4 7
3 6 8
5 8 10
Output
3
1 3 4
Input
6
3 5 16
1 6 11
4 8 12
7 9 16
2 10 14
8 13 15
Output
4
1 2 3 5
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
def inp():
return sys.stdin.readline().rstrip()
def mpint():
return map(int, inp().split(' '))
def itg():
return int(inp())
# ############################## import
# 2020/11/17
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the lazy segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self._lazy = [0] * (2 * _size)
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __len__(self):
return self._len
def _push(self, idx):
"""push query on idx to its children"""
# Let the children know of the queries
q, self._lazy[idx] = self._lazy[idx], 0
self._lazy[2 * idx] += q
self._lazy[2 * idx + 1] += q
self.data[2 * idx] += q
self.data[2 * idx + 1] += q
def _update(self, idx):
"""updates the node idx to know of all queries applied to it via its ancestors"""
for i in reversed(range(1, idx.bit_length())):
self._push(idx >> i)
def _build(self, idx):
"""make the changes to idx be known to its ancestors"""
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) + self._lazy[idx]
idx >>= 1
def add(self, start, stop, value):
"""lazily add value to [start, stop)"""
start = start_copy = start + self._size
stop = stop_copy = stop + self._size
while start < stop:
if start & 1:
self._lazy[start] += value
self.data[start] += value
start += 1
if stop & 1:
stop -= 1
self._lazy[stop] += value
self.data[stop] += value
start >>= 1
stop >>= 1
# Tell all nodes above of the updated area of the updates
self._build(start_copy)
self._build(stop_copy - 1)
def query(self, start, stop, default=None):
"""func of data[start, stop)"""
start += self._size
stop += self._size
# Apply all the lazily stored queries
self._update(start)
self._update(stop - 1)
res = self._default if default is None else default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "LazySegmentTree({})".format(list(map(lambda i: self.query(i, i + 1), range(self._len))))
class SweepLine:
def __init__(self, data=None, inclusive=True):
"""
:param data: [((1, 2), (3, 4)), (left_bottom, right_top), ...]
:param inclusive: include the right bound
"""
if data:
# [((1, 2), (3, 4), 0), ...]
self.data = [(*pair, i) for i, pair in enumerate(data)]
else:
self.data = []
self.discrete_dict = self.restore = None
self.INCLUSIVE = inclusive
def add_rectangle(self, rectangle):
self.data.append((*rectangle, len(self.data)))
def _discrete(self):
st = set()
operations = []
for p1, p2, i in self.data:
st |= {*p1, *p2}
# we want add operation go first, so *= -1
# we calculate the line intersect
operations.append((p1[1], -1, p1[0], p2[0], i)) # add
operations.append((p2[1], 1, p1[0], p2[0], i)) # subtract
self.restore = sorted(st)
self.discrete_dict = dict(zip(st, range(len(st))))
self.operations = sorted(operations)
# print(*self.operations, sep='\n')
def max_intersect(self, get_points=False):
"""
:return intersect, i (ith rectangle)
:return intersect, i, x
"""
if not self.restore:
self._discrete()
d = self.discrete_dict
tree = LazySegmentTree([0] * len(self.restore))
result = 0, None
for y, v, left, right, i in self.operations:
# print(f"left={left}, right={right}")
left, right, v = d[left], d[right], -v
# print(f"dis -> left={left}, right={right}")
tree.add(left, right + self.INCLUSIVE, v)
if v == 1:
intersect = tree.query(left, right + self.INCLUSIVE)
if intersect > result[0]:
result = intersect, i
tree = LazySegmentTree([0] * len(self.restore))
if get_points:
for y, v, left, right, i in self.operations:
left, right, v = d[left], d[right], -v
tree.add(left, right + self.INCLUSIVE, v)
if i == result[1]:
for lf in range(left, right + self.INCLUSIVE):
if tree.query(lf, lf + 1) == result[0]:
return result[0], i, self.restore[lf]
return result
# ############################## main
def main():
n = itg()
data = []
for _ in range(n):
lf, md, rg = mpint()
data.append(((lf, md), (md, rg)))
sweep = SweepLine(data)
ans1, idx, left = sweep.max_intersect(True)
right = data[idx][0][1]
print(ans1)
# print(idx)
# print(f"intersect = {ans1}")
# print(f"left = {left}, right = {right}")
ans2 = []
for i, pair in enumerate(data):
lf, md, rg = pair[0][0], pair[0][1], pair[1][1]
if lf <= left <= md <= right <= rg:
ans2.append(i + 1)
if len(ans2) != ans1:
print(AssertionError, len(ans2))
else:
print(*ans2)
DEBUG = 0
URL = 'https://codeforces.com/contest/377/problem/D'
if __name__ == '__main__':
# 0: normal, 1: runner, 2: interactive, 3: debug
if DEBUG == 1:
import requests
from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
runner = TestCaseRunner(main, URL)
inp = runner.input_stream
print = runner.output_stream
runner.checking()
else:
if DEBUG != 3:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
if DEBUG:
_print = print
def print(*args, **kwargs):
_print(*args, **kwargs)
sys.stdout.flush()
main()
# Please check!
```
No
| 1,956 | [
0.48681640625,
-0.01410675048828125,
-0.265625,
0.31787109375,
-0.8330078125,
-0.6728515625,
0.1287841796875,
0.28076171875,
0.1229248046875,
0.9482421875,
0.4912109375,
0.2445068359375,
0.49658203125,
-0.626953125,
-0.29541015625,
0.032501220703125,
-0.6337890625,
-1.0576171875,
... | 17 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 β€ li β€ vi β€ ri β€ 3Β·105) β the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
Output
In the first line print a single integer m β the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers β the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
Examples
Input
4
2 8 9
1 4 7
3 6 8
5 8 10
Output
3
1 3 4
Input
6
3 5 16
1 6 11
4 8 12
7 9 16
2 10 14
8 13 15
Output
4
1 2 3 5
Submitted Solution:
```
import sys
def swap(a_list, u, v):
a_list[u], a_list[v] = a_list[v], a_list[u]
def update(it, i, l, r, u, v, c):
mid = (l + r) >> 1
left_child = i << 1
right_child = left_child + 1
if l < r:
it[left_child] += t[i]
it[right_child] += t[i]
t[left_child] += t[i]
t[right_child] += t[i]
t[i] = 0
if u <= l and r <= v:
it[i] += c
t[i] += c
return
if u <= mid:
update(it, left_child, l, mid, u, v, c)
if v > mid:
update(it, right_child, mid + 1, r, u, v, c)
it[i] = max(it[left_child], it[right_child])
data_in = [int(i) for i in sys.stdin.read().split()]
n = data_in[0]
a = [[None] * 3 for i in range(n)]
b = [None] * (3 * n)
c = [None] * (3 * n)
left = 0
right = (3 * n) - 1
size = 0
maxC = 0
for i in range(n):
for j in range(3):
a[i][j] = data_in[3 * i + j + 1]
b[size] = (i, 0)
size += 1
b[size] = (i, 2)
swap(b, size, left)
b[right] = (i, 1)
size += 1
left += 1
right -= 1
maxC = max(maxC, a[i][2])
it = [0] * (5 * maxC + 1)
t = [0] * (5 * maxC + 1)
head = [0] * (maxC + 1)
for i in b:
head[a[i[0]][i[1]]] += 1
for i in range(1, maxC + 1):
head[i] += head[i - 1]
for i in b:
c[head[a[i[0]][i[1]]] - 1] = i
head[a[i[0]][i[1]]] -= 1
res = 0
res_lower = 0
for i in c:
id = i[0]
if i[1] == 0:
update(it, 1, 1, maxC, a[id][1], a[id][2], 1)
elif i[1] == 1:
update(it, 1, 1, maxC, a[id][1], a[id][2], -1)
if it[1] > res:
res = it[1]
res_lower = a[id][i[1]]
mark = [False] * n
open_num = 0
for i in c:
id = i[0]
if a[id][1] < res_lower or a[id][0] > res_lower or a[id][2] < res_lower:
continue
if i[1] == 0:
continue
if i[1] == 1:
mark[id] = True
open_num += 1
else:
mark[id] = False
open_num -= 1
if open_num == res:
break
print(res)
res_list = [0] * res
j = 0
for i in range(n):
if mark[i]:
res_list[j] = str(i + 1)
j += 1
print(" ".join(res_list))
```
No
| 1,957 | [
0.58447265625,
0.08294677734375,
-0.333984375,
0.2734375,
-0.7529296875,
-0.7294921875,
0.09454345703125,
0.2078857421875,
0.041290283203125,
0.8623046875,
0.6005859375,
0.08526611328125,
0.470703125,
-0.61083984375,
-0.3974609375,
0.03656005859375,
-0.69970703125,
-0.859375,
-0.... | 17 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game.
Each worker has a certain skill level vi. Besides, each worker doesn't want to work with the one whose skill is very different. In other words, the i-th worker won't work with those whose skill is less than li, and with those whose skill is more than ri.
Pavel understands that the game of his dream isn't too hard to develop, so the worker with any skill will be equally useful. That's why he wants to pick a team of the maximum possible size. Help him pick such team.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of workers Pavel hired.
Each of the following n lines contains three space-separated integers li, vi, ri (1 β€ li β€ vi β€ ri β€ 3Β·105) β the minimum skill value of the workers that the i-th worker can work with, the i-th worker's skill and the maximum skill value of the workers that the i-th worker can work with.
Output
In the first line print a single integer m β the number of workers Pavel must pick for developing the game.
In the next line print m space-separated integers β the numbers of the workers in any order.
If there are multiple optimal solutions, print any of them.
Examples
Input
4
2 8 9
1 4 7
3 6 8
5 8 10
Output
3
1 3 4
Input
6
3 5 16
1 6 11
4 8 12
7 9 16
2 10 14
8 13 15
Output
4
1 2 3 5
Submitted Solution:
```
n=int(input())
lprime, rprime=-1, -1
list1=[]
for i in range(n):
l, s, r=[int(k) for k in input().split()]
if i==0:
lprime=l
rprime=r
else:
if l>lprime: lprime=l
if r<rprime: rprime=r
if lprime<=s<=rprime:
list1.append(i+1)
print(len(list1))
for i in range(len(list1)):
print(list1[i], end=" ")
```
No
| 1,958 | [
0.6005859375,
0.1021728515625,
-0.229248046875,
0.2435302734375,
-0.7783203125,
-0.654296875,
0.0535888671875,
0.0882568359375,
-0.0248260498046875,
0.88037109375,
0.63427734375,
0.08697509765625,
0.327392578125,
-0.60888671875,
-0.381103515625,
0.08502197265625,
-0.77783203125,
-0... | 17 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input
The first line contains number n β the number of techniques that the wrestlers have used (1 β€ n β€ 2Β·105).
The following n lines contain integer numbers ai (|ai| β€ 109, ai β 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
Output
If the first wrestler wins, print string "first", otherwise print "second"
Examples
Input
5
1
2
-3
-4
3
Output
second
Input
3
-1
-2
3
Output
first
Input
2
4
-4
Output
second
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
Tags: implementation
Correct Solution:
```
arr = []
brr = []
for _ in range(int(input())):
n = int(input())
#print(n)
if n > 0:
arr.append(n)
else:
brr.append(-1*n)
#print(arr,brr,n)
if sum(arr) > sum(brr):
print("first")
elif sum(arr) < sum(brr):
print("second")
else:
if arr > brr:
print("first")
elif arr < brr:
print("second")
else:
if n > 0:
print("first")
else:
print("second")
```
| 1,989 | [
0.093017578125,
0.31982421875,
0.07757568359375,
0.450927734375,
-0.49853515625,
-0.484619140625,
-0.247314453125,
-0.0018720626831054688,
0.0287628173828125,
0.53076171875,
0.1514892578125,
0.1793212890625,
0.043487548828125,
-0.611328125,
-0.350341796875,
0.1470947265625,
-0.641601... | 17 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input
The first line contains number n β the number of techniques that the wrestlers have used (1 β€ n β€ 2Β·105).
The following n lines contain integer numbers ai (|ai| β€ 109, ai β 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
Output
If the first wrestler wins, print string "first", otherwise print "second"
Examples
Input
5
1
2
-3
-4
3
Output
second
Input
3
-1
-2
3
Output
first
Input
2
4
-4
Output
second
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
Tags: implementation
Correct Solution:
```
n=int(input())
c1=0
c2=0
c11=[]
c22=[]
ko=0
for i in range(n):
a=int(input())
if a>0:
c1+=a
kk=str(a)
c11.append(a)
ko=1
else:
c2+=abs(a)
kk=str(abs(a))
c22.append(abs(a))
ko=0
if len(c11)<len(c22):
pp=1
elif len(c11)>len(c22):
pp=-1
else:
pp=0
for i in range(min(len(c11),len(c22))):
if c11[i]>c22[i]:
pp=1
break
elif c11[i]<c22[i]:
pp=-1
break
if c1>c2:
print("first")
elif c1<c2:
print("second")
elif c1==c2:
if pp==1:
print("first")
elif pp==-1:
print("second")
elif pp==0:
if ko==0:
print("second")
elif ko==1:
print("first")
```
| 1,990 | [
0.173828125,
0.31396484375,
0.1043701171875,
0.488037109375,
-0.61279296875,
-0.55712890625,
-0.268310546875,
0.0286102294921875,
0.0083160400390625,
0.63232421875,
0.0906982421875,
0.2159423828125,
0.0279998779296875,
-0.50537109375,
-0.31689453125,
0.205078125,
-0.5771484375,
-0.... | 17 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input
The first line contains number n β the number of techniques that the wrestlers have used (1 β€ n β€ 2Β·105).
The following n lines contain integer numbers ai (|ai| β€ 109, ai β 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
Output
If the first wrestler wins, print string "first", otherwise print "second"
Examples
Input
5
1
2
-3
-4
3
Output
second
Input
3
-1
-2
3
Output
first
Input
2
4
-4
Output
second
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
Tags: implementation
Correct Solution:
```
n=int(input())
f=[]
s=[]
fsc=0
ssc=0
for i in range(n):
x=int(input())
if x>0:
f.append(x)
fsc+=x
else:
ssc+=-x
s.append(-x)
if i==n-1:
las=x
if fsc>ssc:
print('first')
elif ssc>fsc:
print('second')
elif f>s:
print('first')
elif f<s:
print('second')
else:
if las>0:
print('first')
else:
print('second')
```
| 1,991 | [
0.1900634765625,
0.281005859375,
0.1737060546875,
0.446044921875,
-0.58740234375,
-0.47119140625,
-0.391845703125,
0.041473388671875,
-0.02984619140625,
0.53125,
0.259033203125,
0.2061767578125,
0.1060791015625,
-0.51318359375,
-0.276123046875,
0.15576171875,
-0.5615234375,
-0.7402... | 17 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input
The first line contains number n β the number of techniques that the wrestlers have used (1 β€ n β€ 2Β·105).
The following n lines contain integer numbers ai (|ai| β€ 109, ai β 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
Output
If the first wrestler wins, print string "first", otherwise print "second"
Examples
Input
5
1
2
-3
-4
3
Output
second
Input
3
-1
-2
3
Output
first
Input
2
4
-4
Output
second
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
Tags: implementation
Correct Solution:
```
n = int(input())
a = []
b = []
x = 0
for i in range(n):
q = int(input())
if q > 0:
x = 1
a.append(q)
else:
x = -1
b.append(-q)
if sum(a) != sum(b):
print('first' if sum(a) > sum(b) else 'second')
elif a != b:
print('first' if a > b else 'second')
else:
print('first' if x > 0 else 'second')
```
| 1,992 | [
0.15869140625,
0.333984375,
0.05865478515625,
0.453857421875,
-0.5947265625,
-0.5224609375,
-0.27734375,
0.08343505859375,
-0.00421905517578125,
0.56494140625,
0.0853271484375,
0.227783203125,
0.04913330078125,
-0.51953125,
-0.380859375,
0.191162109375,
-0.61865234375,
-0.776367187... | 17 |
"Provide tags and a correct Python 3 solution for this coding contest problem.\n\nVasya has become i(...TRUNCATED) | 1,993 | [0.119873046875,0.314208984375,0.07086181640625,0.475341796875,-0.6904296875,-0.517578125,-0.3190917(...TRUNCATED) | 17 |
End of preview. Expand
in Data Studio
- Downloads last month
- 8