description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array Arr of size N such that each element is from the range 0 to 9. Find the minimum possible sum of two numbers formed using the elements of the array. All digits in the given array must be used to form the two numbers.
Example 1:
Input:
N = 6
Arr[] = {6, 8, 4, 5, 2, 3}
Output: 604
Explanation: The minimum sum is formed
by numbers 358 and 246.
Example 2:
Input:
N = 5
Arr[] = {5, 3, 0, 7, 4}
Output: 82
Explanation: The minimum sum is
formed by numbers 35 and 047.
Your Task:
You don't need to read input or print anything. Your task is to complete the function solve() which takes arr[] and n as input parameters and returns the minimum possible sum. As the number can be large, return string presentation of the number without leading zeroes.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{7}
0 ≤ Arr_{i} ≤ 9 | class Solution:
def solve(self, arr, n):
arr.sort()
e = ""
o = ""
for i in range(0, n):
if i % 2 == 0:
e += str(arr[i])
else:
o += str(arr[i])
if e == "":
e = 0
else:
e = int(e)
if o == "":
o = 0
else:
o = int(o)
return e + o | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR |
Given an array Arr of size N such that each element is from the range 0 to 9. Find the minimum possible sum of two numbers formed using the elements of the array. All digits in the given array must be used to form the two numbers.
Example 1:
Input:
N = 6
Arr[] = {6, 8, 4, 5, 2, 3}
Output: 604
Explanation: The minimum sum is formed
by numbers 358 and 246.
Example 2:
Input:
N = 5
Arr[] = {5, 3, 0, 7, 4}
Output: 82
Explanation: The minimum sum is
formed by numbers 35 and 047.
Your Task:
You don't need to read input or print anything. Your task is to complete the function solve() which takes arr[] and n as input parameters and returns the minimum possible sum. As the number can be large, return string presentation of the number without leading zeroes.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{7}
0 ≤ Arr_{i} ≤ 9 | class Solution:
def solve(self, arr, n):
arr.sort()
if n == 1:
return arr[0]
if n == 2:
return arr[0] + arr[1]
s = 0
num1 = arr[0]
while s < n:
if s != 0:
num1 = num1 * 10 + arr[s]
s += 2
num2 = arr[1]
s = 1
while s < n:
if s != 1:
num2 = num2 * 10 + arr[s]
s += 2
return num1 + num2 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | T = int(input())
for _ in range(T):
N, M = list(map(int, input().split()))
P = list(map(int, input().split()))
pairs = []
for _ in range(M):
pairs.append(list(map(int, input().split())))
pairs.sort()
merged_pairs = []
for start, end in pairs:
if not merged_pairs:
merged_pairs.append((start, end))
else:
prevS, prevE = merged_pairs[-1]
if start <= prevE:
merged_pairs.pop()
merged_pairs.append((prevS, max(end, prevE)))
else:
merged_pairs.append((start, end))
for start, end in merged_pairs:
P[start - 1 : end] = sorted(P[start - 1 : end])
possible = True
for i in range(N):
if P[i] != i + 1:
possible = False
break
if possible:
print("Possible")
else:
print("Impossible") | ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | t = int(input())
for i in range(t):
n, m = map(int, input().split())
arr = [int(x) for x in input().split()]
arr3 = []
for j in range(n):
arr3.append(j)
for j in range(m):
x, y = map(int, input().split())
if x < y:
if arr3[x - 1] < y - 1:
arr3[x - 1] = y - 1
elif y > x:
if arr3[y - 1] < x - 1:
arr3[y - 1] = x - 1
j = 0
while j < n:
x = j
if x == arr3[x]:
j += 1
else:
max1 = arr3[x]
flag = 0
while 1:
if flag == 0:
flag = 1
for k in range(x + 1, arr3[x] + 1):
if max1 < arr3[k]:
max1 = arr3[k]
if max1 == arr3[x]:
break
else:
prevmax = arr3[x]
else:
y = max1
for k in range(prevmax, y + 1):
if max1 < arr3[k]:
max1 = arr3[k]
if prevmax == max1:
break
else:
prevmax = y
for k in range(x, max1 + 1):
arr3[k] = max1
j = max1 + 1
count = 0
for j in range(n):
if arr[j] - 1 == j:
count += 1
elif j < arr[j] - 1:
if arr3[j] >= arr[j] - 1:
count += 1
elif arr3[arr[j] - 1] >= j:
count += 1
if count == n:
print("Possible")
else:
print("Impossible") | 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | t = int(input())
for i in range(t):
n, m = map(int, input().split())
l = list(map(int, input().split()))
d = []
for j in range(m):
a, b = map(int, input().split())
d.append([a, b])
d.sort()
c = []
f = 1
x = d[0][0]
y = d[0][1]
for j in d[1:]:
if j[0] <= y:
y = max(y, j[1])
else:
c.append([x - 1, y - 1])
x = j[0]
y = j[1]
c.append([x - 1, y - 1])
m = []
j = 0
for k in c:
while j < k[0]:
m.append(l[j])
j += 1
x = l[k[0] : k[1] + 1]
m += sorted(x)
j = k[1] + 1
while j < n:
m.append(l[j])
j += 1
print("Possible" if m == sorted(l) else "Impossible") | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING STRING |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | def solution(R, L):
R.sort(key=lambda x: x[0])
low = R[0][0]
high = R[0][1]
New = []
for a in R:
if a[0] <= high:
high = max(high, a[1])
else:
temp = [low, high]
New.append(temp)
low = a[0]
high = a[1]
temp = [low, high]
New.append(temp)
for a in New:
for i in range(a[0] - 1, a[1]):
if L[i] < a[0] or L[i] > a[1]:
return "Impossible"
return "Possible"
T = int(input())
for t in range(T):
N, M = map(int, input().split())
L = list(map(int, input().split()))
R = []
a = []
for m in range(M):
a = list(map(int, input().split()))
R.append(a)
print(solution(R, L)) | FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN STRING RETURN STRING 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | T = int(input())
for cases in range(T):
inp = input().split()
N = int(inp[0])
M = int(inp[1])
P = input().split()
for i in range(N):
P[i] = int(P[i])
pairs = []
for i in range(M):
inp = input().split()
pair1 = int(inp[0])
pair2 = int(inp[1])
pair1, pair2 = min(pair1, pair2), max(pair1, pair2)
pairs.append((pair1, pair2))
pairs = sorted(pairs, key=lambda x: x[0])
it = 1
while it < len(pairs):
start1 = pairs[it - 1][0]
last1 = pairs[it - 1][1]
start2 = pairs[it][0]
last2 = pairs[it][1]
if start2 <= last1:
pairs[it - 1] = start1, max(last1, last2)
del pairs[it]
else:
it += 1
for i in range(len(pairs)):
init, fin = pairs[i][0] - 1, pairs[i][1]
P[init:fin] = sorted(P[init:fin])
verdict = "Possible"
for i in range(N):
if P[i] != i + 1:
verdict = "Impossible"
break
print(verdict) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutation on the positions from Lj to Rj, inclusive (the positions are 1-based). You are not limited in the number of turns and you can pick any pair more than once.
The goal is to obtain the permutation P, that is given to you. If it's possible, output "Possible", otherwise output "Impossible" (without quotes).
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the size of the permutation P and the number of pairs described above.
The next line contains N integers - the permutation P.
Each of the following M lines contain pair of integers Li and Ri.
-----Output-----
For each test case, output a single line containing the answer to the corresponding test case.
-----Constraints-----
- 1 ≤ T ≤ 35
- 1 ≤ N, M ≤ 100000
- 1 ≤ Li ≤ Ri ≤ N
-----Example-----
Input:
2
7 4
3 1 2 4 5 7 6
1 2
4 4
6 7
2 3
4 2
2 1 3 4
2 4
2 3
Output:
Possible
Impossible | def search(new, lb, ub, a, b):
while lb <= ub:
mb = lb + (ub - lb) // 2
if new[mb][0] <= a and new[mb][0] <= b and new[mb][1] >= a and new[mb][1] >= b:
return 1
elif new[mb][0] >= a and new[mb][0] >= b:
ub = mb - 1
elif new[mb][1] <= a and new[mb][1] <= b:
lb = mb + 1
else:
return -1
return -1
for t in range(int(input())):
temp = list(map(int, input().split()))
n = temp[0]
m = temp[1]
a = list(map(int, input().split()))
pairs = []
for i in range(m):
temp = list(map(int, input().split()))
temp[0] -= 1
temp[1] -= 1
if temp[0] != temp[1]:
pairs.append(temp[:])
pairs.sort()
if n == 1:
print("Possible")
continue
flag = 0
for i in range(n):
if a[i] != i + 1:
flag = 1
break
if flag == 0:
print("Possible")
continue
if len(pairs) == 0:
print("Impossible")
continue
new = []
new.append(pairs[0][:])
l = len(pairs)
for i in range(1, l):
if pairs[i][0] <= new[-1][1]:
new[-1][1] = max(pairs[i][1], new[-1][1])
else:
new.append(pairs[i][:])
flag = 0
l = len(new)
for i in range(n):
if a[i] == i + 1:
continue
else:
ans = search(new, 0, l - 1, i, a[i] - 1)
if ans == -1:
flag = 1
break
if flag == 1:
print("Impossible")
else:
print("Possible") | FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all q pixels stopped working).
-----Input-----
The first line contains four integer numbers n, m, k, q (1 ≤ n, m ≤ 500, 1 ≤ k ≤ min(n, m), 0 ≤ q ≤ n·m) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels.
Each of next q lines contain three integer numbers x_{i}, y_{i}, t_{i} (1 ≤ x_{i} ≤ n, 1 ≤ y_{i} ≤ m, 0 ≤ t_{ ≤ 10}^9) — coordinates of i-th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once.
We consider that pixel is already broken at moment t_{i}.
-----Output-----
Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these q pixels stopped working.
-----Examples-----
Input
2 3 2 5
2 1 8
2 2 8
1 2 1
1 3 4
2 3 2
Output
8
Input
3 3 2 5
1 2 2
2 2 1
2 3 5
3 2 10
2 1 100
Output
-1 | from sys import stdin, stdout
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end="\n"):
stdout.write(str(a) + end)
def putf(a, sep=" ", end="\n"):
stdout.write(sep.join(map(str, a)) + end)
def isbroken(n, m, mt, k, qu, q):
a = [([1] * m) for i in range(n)]
for i in range(q):
x, y, t = qu[i]
if t <= mt:
a[x - 1][y - 1] = 0
dp = [([0] * (m + 1)) for i in range(n + 1)]
dp[1][1] = a[0][0]
for j in range(2, m + 1):
dp[1][j] = dp[1][j - 1] + a[0][j - 1]
for i in range(2, n + 1):
dp[i][1] = dp[i - 1][1] + a[i - 1][0]
for i in range(2, n + 1):
for j in range(2, m + 1):
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i - 1][j - 1]
for i in range(k, n + 1):
for j in range(k, m + 1):
sm = dp[i][j] - dp[i - k][j] - dp[i][j - k] + dp[i - k][j - k]
if sm == 0:
return 1
return 0
def main():
n, m, k, q = getf()
qu = [getf() for i in range(q)]
l, r = -1, 10**9 + 1
while l + 1 < r:
mt = (l + r) // 2
if isbroken(n, m, mt, k, qu, q):
r = mt
else:
l = mt
if r != 10**9 + 1:
put(r)
else:
put(-1)
main() | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
n = len(arr)
ans = []
arr.sort()
for i in range(n - 3):
if i == 0 or i > 0 and arr[i] != arr[i - 1]:
for j in range(i + 1, n - 2):
if j == i + 1 or j > i + 1 and arr[j] != arr[j - 1]:
left = j + 1
right = n - 1
while left < right:
Sum = arr[i] + arr[j] + arr[left] + arr[right]
if Sum == k:
ans.append((arr[i], arr[j], arr[left], arr[right]))
while left < right and arr[left] == arr[left + 1]:
left += 1
while left < right and arr[right] == arr[right - 1]:
right -= 1
left += 1
right -= 1
elif Sum < k:
left += 1
else:
right -= 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
res = []
for i in range(len(arr) - 3):
if i != 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, len(arr) - 2):
if j != i + 1 and arr[j] == arr[j - 1]:
continue
sumij = arr[i] + arr[j]
low = j + 1
high = len(arr) - 1
while low < high:
sumval = sumij + arr[low] + arr[high]
if sumval == k:
res.append([arr[i], arr[j], arr[low], arr[high]])
low += 1
high -= 1
while low < high and arr[low] == arr[low - 1]:
low += 1
while low < high and arr[high] == arr[high + 1]:
high -= 1
elif sumval > k:
high -= 1
else:
low += 1
return res | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
list1 = set()
arr.sort()
for i in range(n - 3):
for j in range(i + 1, n - 2):
left = j + 1
right = n - 1
while left < right:
quad = arr[i] + arr[j] + arr[left] + arr[right]
if quad == k:
temp = arr[i], arr[j], arr[left], arr[right]
list1.add(temp)
left += 1
elif quad > k:
right -= 1
else:
left += 1
return sorted(list(list1)) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
n = len(arr)
res = []
arr.sort()
for i in range(n - 2):
A = k - arr[i]
for j in range(i + 1, n - 1):
B = A - arr[j]
ans = {}
for ij in range(j + 1, n):
if B - arr[ij] in ans:
N = B - arr[ij]
res.append((arr[i], arr[j], N, arr[ij]))
else:
ans[arr[ij]] = 1
C = list(set(res))
C.sort()
return C | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
n = len(arr)
ans_set = set()
arr.sort()
for i in range(n - 3):
for j in range(i + 1, n - 2):
l = j + 1
r = n - 1
while l < r:
sum = arr[i] + arr[j] + arr[l] + arr[r]
if sum == k:
ans_set.add((arr[i], arr[j], arr[l], arr[r]))
l += 1
r -= 1
elif sum < k:
l += 1
else:
r -= 1
ans_list = list(ans_set)
ans_list.sort()
return ans_list | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
n = len(arr)
arr.sort()
ans = set()
op = []
for i in range(n):
sum3 = k - arr[i]
for j in range(i + 1, n):
sum2 = sum3 - arr[j]
left = j + 1
right = n - 1
while right > left:
if arr[left] + arr[right] > sum2:
right -= 1
elif arr[left] + arr[right] < sum2:
left += 1
else:
ans.add((arr[i], arr[j], arr[left], arr[right]))
left += 1
right -= 1
op = list(ans)
op.sort()
return op | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
if len(arr) < 4:
return -1
arr.sort()
check = set()
for i in range(0, n - 3):
for j in range(i + 1, n - 2):
left = j + 1
right = n - 1
while left < right:
ssum = arr[i] + arr[j] + arr[left] + arr[right]
if ssum > k:
right -= 1
elif ssum == k:
temp = arr[i], arr[j], arr[left], arr[right]
check.add(temp)
left += 1
else:
left += 1
return sorted(list(check)) | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
a = []
for i in range(0, len(arr) - 3):
for j in range(i + 1, len(arr) - 2):
s = k - (arr[i] + arr[j])
start = j + 1
end = len(arr) - 1
while start < end:
t = arr[start] + arr[end]
if t == s:
l = []
l.append(arr[i])
l.append(arr[j])
l.append(arr[start])
l.append(arr[end])
a.append(l)
start += 1
end -= 1
elif t > s:
end -= 1
else:
start += 1
set_list = list(set(map(tuple, a)))
set_list.sort()
return set_list | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
target = k
arr.sort()
ans = []
n = len(arr)
for i in range(n):
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, n):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
o, l = j + 1, n - 1
while o < l:
sum1 = arr[i] + arr[j] + arr[o] + arr[l]
if sum1 > target:
l -= 1
elif sum1 < target:
o += 1
else:
ans.append([arr[i], arr[j], arr[o], arr[l]])
o += 1
l -= 1
while o < l and arr[o] == arr[o - 1]:
o += 1
while k < l and arr[l] == arr[l + 1]:
l -= 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
x = set()
ans = []
for i in range(len(arr) - 3):
for j in range(i + 1, len(arr) - 2):
left = j + 1
right = len(arr) - 1
while left < right:
cur = arr[left] + arr[right] + arr[i] + arr[j]
if cur > k:
right -= 1
elif cur < k:
left += 1
else:
s = ""
s += str(arr[i]) + "."
s += str(arr[j]) + "."
s += str(arr[left]) + "."
s += str(arr[right]) + "."
if s not in x:
t = [arr[i], arr[j], arr[left], arr[right]]
ans.append(t)
x.add(s)
left += 1
return ans | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING IF VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
d = dict()
arr = sorted(arr)
n = len(arr)
for i in range(n - 3):
for j in range(i + 1, n - 2):
left = j + 1
right = n - 1
while left < right:
temp = arr[i] + arr[j] + arr[left] + arr[right]
if temp == k:
key = tuple([arr[i], arr[j], arr[left], arr[right]])
if key not in d:
d[key] = 1
else:
d[key] += 1
left += 1
right -= 1
elif temp < k:
left += 1
else:
right -= 1
return sorted(list(d.keys())) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
n = len(arr)
r = []
for i in range(0, len(arr) - 3):
for j in range(i + 1, len(arr) - 2):
l = j + 1
m = len(arr) - 1
while l < m:
s = arr[i] + arr[j] + arr[l] + arr[m]
if s == k:
x = [arr[i], arr[j], arr[l], arr[m]]
x.sort()
r.append(x)
if s > k:
m -= 1
else:
l += 1
set_list = list(set(map(tuple, r)))
set_list.sort()
return set_list | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
n = len(arr)
lst = []
for i in range(n - 3):
for j in range(i + 1, n - 2):
l, r = j + 1, n - 1
while l < r:
sum4 = arr[i] + arr[j] + arr[l] + arr[r]
if sum4 > k:
r -= 1
elif sum4 < k:
l += 1
elif sum4 == k:
lst.append([arr[i], arr[j], arr[l], arr[r]])
l += 1
r -= 1
lst = list(set(map(tuple, lst)))
lst.sort()
return lst | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, target):
arr.sort()
n = len(arr)
res = []
for i in range(n - 3):
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, n - 2):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
s = j + 1
e = n - 1
while s < e:
if s > j + 1 and arr[s] == arr[s - 1]:
s += 1
continue
if e + 1 < n and arr[e] == arr[e + 1]:
e -= 1
continue
tmp = arr[i] + arr[j] + arr[s] + arr[e]
if tmp == target:
tmpArr = [arr[i], arr[j], arr[s], arr[e]]
res.append(tmpArr)
s += 1
elif tmp > target:
e -= 1
else:
s += 1
return res | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, A, X):
A.sort()
N = len(A)
arr = []
for i in range(N - 3):
if i > 0 and A[i] == A[i - 1]:
continue
for j in range(i + 1, N - 2):
if j > i + 1 and A[j] == A[j - 1]:
continue
k = j + 1
l = n - 1
while k < l:
sum1 = A[i] + A[j] + A[k] + A[l]
if sum1 == X:
ind = [A[i], A[j], A[k], A[l]]
arr.append(ind)
k += 1
l -= 1
while k < l and k > j and A[k] == A[k - 1]:
k += 1
while k < l and l + 1 < N and A[l] == A[l + 1]:
l -= 1
elif sum1 < X:
k += 1
else:
l -= 1
return arr | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | def findFourSum(arr, i, n, curSum, x, l, ans):
if i == n:
if l == 4 and sum(curSum) == x:
ans.append(curSum.copy())
curSum = []
return ans
if l == 4:
if sum(curSum) == x:
ans.append(curSum.copy())
curSum = []
return ans
curSum.append(arr[i])
ans = findFourSum(arr, i + 1, n, curSum, x, l + 1, ans)
curSum.remove(arr[i])
ans = findFourSum(arr, i + 1, n, curSum, x, l, ans)
return ans
class Solution:
def fourSum(self, arr, k):
arr.sort()
i = 0
n = len(arr)
res = []
while i < n:
j = i + 1
while j < n:
l = j + 1
r = n - 1
s = arr[i] + arr[j]
while l < r:
if s + arr[l] + arr[r] == k:
res.append([arr[i], arr[j], arr[l], arr[r]])
l += 1
while l < r and arr[l - 1] == arr[l]:
l += 1
r -= 1
while l < r and arr[r + 1] == arr[r]:
r -= 1
elif s + arr[l] + arr[r] < k:
l += 1
while l < r and arr[l - 1] == arr[l]:
l += 1
else:
r -= 1
while l < r and arr[r + 1] == arr[r]:
r -= 1
j += 1
while j < n and arr[j - 1] == arr[j]:
j += 1
i += 1
while i < n and arr[i - 1] == arr[i]:
i += 1
return res | FUNC_DEF IF VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST RETURN VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST RETURN VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, nums, k):
ans = []
n = len(nums)
if not nums or n == 0:
return []
nums.sort()
i = 0
while i < n:
j = i + 1
while j < n:
twoSumTarget = k - nums[i] - nums[j]
left = j + 1
right = n - 1
while left < right:
current = nums[left] + nums[right]
if current < twoSumTarget:
left += 1
elif current > twoSumTarget:
right -= 1
else:
quad = [nums[i], nums[j], nums[left], nums[right]]
ans.append(quad)
while left < right and nums[left] == quad[2]:
left += 1
while left < right and nums[right] == quad[3]:
right -= 1
while j + 1 < n and nums[j + 1] == nums[j]:
j += 1
j += 1
while i + 1 < n and nums[i + 1] == nums[i]:
i += 1
i += 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def solve(self, idx, arr, k, N, path, ans):
try:
if N == 0:
if sum(path) == k:
temp = tuple(path[:])
ans.add(temp)
return
if idx >= len(arr):
return
path.append(arr[idx])
self.solve(idx + 1, arr, k, N - 1, path, ans)
path.pop()
self.solve(idx + 1, arr, k, N, path, ans)
except Exception as e:
print(e)
def solve(self, idx, arr, k, N, path, ans):
try:
if N == 0:
if sum(path) == k:
temp = tuple(path[:])
ans.add(temp)
return
if idx >= len(arr):
return
for i in range(idx, len(arr)):
path.append(arr[i])
self.solve(i + 1, arr, k, N - 1, path, ans)
path.pop()
except Exception as e:
print(e)
def solve(self, arr, k, ans):
n = len(arr)
for i in range(n - 3):
for j in range(i + 1, n - 2):
left = j + 1
right = n - 1
while left < right:
summ = arr[i] + arr[j] + arr[left] + arr[right]
if summ == k:
ans.add((arr[i], arr[j], arr[left], arr[right]))
left += 1
elif summ > k:
right -= 1
else:
left += 1
def fourSum(self, arr, k):
arr.sort()
ans = set()
self.solve(arr, k, ans)
ans = sorted(ans)
return ans | CLASS_DEF FUNC_DEF IF VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
ml = []
k1 = {}
s = 0
c = 0
arr = sorted(arr)
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
l = j + 1
h = len(arr) - 1
while l < h:
s = arr[i] + arr[j] + arr[l] + arr[h]
if s < k:
l = l + 1
elif s > k:
h = h - 1
else:
c = c + 1
k1[arr[i], arr[j], arr[l], arr[h]] = c
x = arr[l]
y = arr[h]
while l < h and x == arr[l]:
l = l + 1
while l < h and y == arr[h]:
h = h - 1
myKeys = list(k1.keys())
myKeys.sort()
return myKeys | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
li = []
n = len(arr)
if n < 4:
return li
arr.sort()
for i in range(n - 3):
if arr[i] > 0 and arr[i] > k:
break
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, n - 2):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
l = j + 1
r = n - 1
while l < r:
old_l = l
old_r = r
s = arr[i] + arr[j] + arr[l] + arr[r]
if s == k:
p = []
p.append(arr[i])
p.append(arr[j])
p.append(arr[l])
p.append(arr[r])
li.append(p)
while l < r and arr[old_l] == arr[l]:
l += 1
while l < r and arr[r] == arr[old_r]:
r = r - 1
elif s < k:
l = l + 1
else:
r = r - 1
return li | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
res = []
arr.sort()
if len(arr) == 0:
return []
n = len(arr)
for i in range(n):
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, n):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
target = k - (arr[i] + arr[j])
left = j + 1
right = n - 1
while left < right:
targetsum = arr[left] + arr[right]
if targetsum < target:
left += 1
elif targetsum > target:
right -= 1
else:
quad = [arr[i], arr[j], arr[left], arr[right]]
res.append(quad)
while left < right and arr[left] == quad[2]:
left += 1
while left < right and arr[right] == quad[3]:
right -= 1
return res | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, target):
arr.sort()
n = len(arr)
pair_sum = {}
for i in range(n - 1):
for j in range(i + 1, n):
s = arr[i] + arr[j]
if s not in pair_sum:
pair_sum[s] = [(i, j)]
else:
pair_sum[s].append((i, j))
result = set()
for i in range(n - 3):
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, n - 2):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
s = arr[i] + arr[j]
if target - s in pair_sum:
pairs = pair_sum[target - s]
for p in pairs:
if p[0] > j:
result.add((arr[i], arr[j], arr[p[0]], arr[p[1]]))
result = sorted(result)
return result | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
target = k
ans = set()
for i in range(len(arr) - 3):
for j in range(i + 1, len(arr) - 2):
k = j + 1
l = len(arr) - 1
while k < l:
sum = arr[i] + arr[j] + arr[k] + arr[l]
if sum == target:
ans.add((arr[i], arr[j], arr[k], arr[l]))
k += 1
if sum < target:
k += 1
else:
l -= 1
return sorted(ans) | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
n = len(arr)
res = []
for i in range(n - 2):
for j in range(i + 1, n - 1):
l = j + 1
r = n - 1
while l < r:
summ = arr[i] + arr[j] + arr[l] + arr[r]
if summ == k:
li = []
li.append(arr[i])
li.append(arr[j])
li.append(arr[l])
li.append(arr[r])
res.append(li)
l += 1
r -= 1
elif summ < k:
l += 1
else:
r -= 1
setList = list(set(map(tuple, res)))
setList.sort()
return setList | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
result = set()
for i in range(len(arr)):
r = []
for j in range(i + 1, len(arr)):
sum1 = arr[i] + arr[j]
diff = k - sum1
m = j + 1
l = len(arr) - 1
while m < l:
remaining_sum = arr[m] + arr[l]
if remaining_sum > diff:
l -= 1
elif remaining_sum < diff:
m += 1
else:
r.append(arr[i])
r.append(arr[j])
r.append(arr[m])
r.append(arr[l])
result.add((arr[i], arr[j], arr[m], arr[l]))
m += 1
l -= 1
return sorted(result) | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, nums, target):
n = len(nums)
nums.sort()
ans = []
for i in range(n):
if i > 0 and nums[i] == nums[i - 1]:
continue
for j in range(i + 1, n):
if j != i + 1 and nums[j] == nums[j - 1]:
continue
k = j + 1
l = n - 1
while k < l:
sum = nums[i]
sum += nums[j]
sum += nums[k]
sum += nums[l]
if sum == target:
ans.append([nums[i], nums[j], nums[k], nums[l]])
k += 1
l -= 1
while k < l and nums[k] == nums[k - 1]:
k += 1
while k < l and nums[l] == nums[l + 1]:
l -= 1
elif sum < target:
k += 1
else:
l -= 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, nums, target):
nums.sort()
arr = []
quad = []
def kSum(k, start, target):
if k != 2:
for i in range(start, len(nums) - k + 1):
if i > start and nums[i] == nums[i - 1]:
continue
quad.append(nums[i])
kSum(k - 1, i + 1, target - nums[i])
quad.pop()
return
l = start
r = len(nums) - 1
while l < r:
if nums[l] + nums[r] < target:
l += 1
elif nums[l] + nums[r] > target:
r -= 1
else:
t = quad + [nums[l], nums[r]]
arr.append(t)
l += 1
while nums[l] == nums[l - 1] and l < r:
l += 1
kSum(4, 0, target)
return arr | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, arr, k):
arr.sort()
res = []
for i in range(len(arr) - 3):
if i > 0 and arr[i] == arr[i - 1]:
continue
for j in range(i + 1, len(arr) - 2):
if j > i + 1 and arr[j] == arr[j - 1]:
continue
l = j + 1
r = len(arr) - 1
while l < r:
if arr[i] + arr[j] + arr[l] + arr[r] == k:
res.append((arr[i], arr[j], arr[l], arr[r]))
while l < r and arr[l] == arr[l + 1]:
l += 1
while l < r and arr[r] == arr[r - 1]:
r -= 1
l += 1
r -= 1
elif arr[i] + arr[j] + arr[l] + arr[r] > k:
r -= 1
else:
l += 1
return res | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array of integers and another number. Find all the unique quadruple from the given array that sums up to the given number.
Example 1:
Input:
N = 5, K = 3
A[] = {0,0,2,1,1}
Output: 0 0 1 2
Explanation: Sum of 0, 0, 1, 2 is equal
to K.
Example 2:
Input:
N = 7, K = 23
A[] = {10,2,3,4,5,7,8}
Output: 2 3 8 10
2 4 7 10
3 5 7 8
Explanation: Sum of 2, 3, 8, 10 = 23,
sum of 2, 4, 7, 10 = 23 and sum of 3,
5, 7, 8 = 23.
Your Task:
You don't need to read input or print anything. Your task is to complete the function fourSum() which takes the array arr[] and the integer k as its input and returns an array containing all the quadruples in a lexicographical manner. Also note that all the quadruples should be internally sorted, ie for any quadruple [q1, q2, q3, q4] the following should follow: q1 <= q2 <= q3 <= q4. (In the output each quadruple is separate by $. The printing is done by the driver's code)
Expected Time Complexity: O(N^{3}).
Expected Auxiliary Space: O(N^{2}).
Constraints:
1 <= N <= 100
-1000 <= K <= 1000
-100 <= A[] <= 100 | class Solution:
def fourSum(self, a, k):
n = len(a)
ans = []
if n < 4:
return ans
a.sort()
for i in range(0, n - 3):
if a[i] > 0 and a[i] > k:
break
if i > 0 and a[i] == a[i - 1]:
continue
for j in range(i + 1, n - 2):
if j > i + 1 and a[j] == a[j - 1]:
continue
left = j + 1
right = n - 1
while left < right:
old_l = left
old_r = right
sum = a[i] + a[j] + a[left] + a[right]
if sum == k:
ans.append([a[i], a[j], a[left], a[right]])
while left < right and a[left] == a[old_l]:
left += 1
while left < right and a[right] == a[old_r]:
right -= 1
elif sum > k:
right -= 1
else:
left += 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
maxN = 200200
n, k, q = [int(item) for item in stdin.readline().strip().split()]
a = [0] * maxN
b = [0] * maxN
for i in range(n):
l, r = [int(item) for item in stdin.readline().strip().split()]
a[l] += 1
a[r + 1] -= 1
for i in range(1, maxN):
a[i] += a[i - 1]
for i in range(maxN):
if a[i] >= k:
b[i] = 1
b[i] += b[i - 1]
for j in range(q):
u, v = [int(item) for item in stdin.readline().strip().split()]
stdout.write(str(b[v] - b[u - 1]))
stdout.write("\n") | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | def main():
n, m, k = map(int, input().split())
size = int(200000.0 + 5)
cnt = [0] * size
for i in range(n):
x, y = map(int, input().split())
cnt[x] += 1
cnt[y + 1] -= 1
for i in range(1, size):
cnt[i] += cnt[i - 1]
cnt[i - 1] = 1 if cnt[i - 1] >= m else 0
for i in range(1, size):
cnt[i] += cnt[i - 1]
res = ""
for i in range(k):
x, y = map(int, input().split())
res += str(cnt[y] - cnt[x - 1]) + "\n"
print(res)
main() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER 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 VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
n, k, q = map(int, input().split())
start = {}
end = {}
for i in range(n):
x, y = map(int, input().split())
if x not in start:
start[x] = 1
else:
start[x] += 1
if y not in end:
end[y] = 1
else:
end[y] += 1
c = [0] * 200002
if 0 in start:
c[0] += start[0]
if 0 in end:
c[1] -= end[0]
for i in range(1, 200001):
c[i] += c[i - 1]
if i in start:
c[i] += start[i]
if i in end:
c[i + 1] -= end[i]
for i in range(200001):
if c[i] >= k:
c[i] = 1
else:
c[i] = 0
for i in range(1, 200001):
c[i] += c[i - 1]
for i in range(q):
a, b = map(int, input().split())
if a == 0:
print(c[b])
else:
print(c[b] - c[a - 1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF NUMBER VAR VAR NUMBER VAR NUMBER IF NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | input = __import__("sys").stdin.readline
n, k, q = map(int, input().split())
arr = [0] * 200003
for i in range(n):
l, r = map(int, input().split())
arr[l] += 1
arr[r + 1] -= 1
ans = [0] * 200003
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
ans[i] = ans[i - 1] + (1 if arr[i] >= k else 0)
for i in range(q):
l, r = map(int, input().split())
print(ans[r] - ans[l - 1]) | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = [int(x) for x in input().split()]
mainL, x, c = [0] * 200002, 0, 0
for i in range(n):
left, right = [int(x) for x in input().split()]
mainL[left] += 1
mainL[right + 1] -= 1
for i in range(200002):
x += mainL[i]
if x >= k:
c += 1
mainL[i] = c
else:
mainL[i] = c
for i in range(q):
start, end = [int(x) for x in input().split()]
print(mainL[end] - mainL[start - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | a = [int(x) for x in input().split()]
receptek = []
kerdesek = []
for x in range(a[0]):
receptek.append([int(y) for y in input().split()])
for x in range(a[2]):
kerdesek.append([int(y) for y in input().split()])
nagy = 200002
jo = [0] * nagy
for x in range(len(receptek)):
b = receptek[x][0]
c = receptek[x][1]
jo[b] += 1
jo[c + 1] -= 1
for x in range(1, len(jo)):
jo[x] += jo[x - 1]
adm = [0] * nagy
for x in range(1, len(jo)):
if jo[x] >= a[1]:
adm[x] += 1
adm[x] += adm[x - 1]
mo = []
for x in range(len(kerdesek)):
mo.append(adm[kerdesek[x][1]] - adm[kerdesek[x][0] - 1])
for m in mo:
print(m) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | ranges, maps, strs = range, map, str
fout = ""
count = 0
n, k, q = maps(int, input().split())
rangeArr = []
for i in ranges(200002):
rangeArr.append(0)
for recipe in ranges(n):
left, right = maps(int, input().split())
rangeArr[left] += 1
rangeArr[right + 1] -= 1
for recipe in ranges(1, len(rangeArr)):
rangeArr[recipe] += rangeArr[recipe - 1]
if rangeArr[recipe - 1] < k:
rangeArr[recipe - 1] = 0
else:
rangeArr[recipe - 1] = 1
for i in ranges(1, len(rangeArr)):
rangeArr[i] += rangeArr[i - 1]
for question in ranges(q):
left, right = maps(int, input().split())
fout += strs(rangeArr[right] - rangeArr[left - 1]) + "\n"
print(fout) | ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import itertools as it
import sys
c = [0] * 200002
n, k, q = map(int, input().split())
itr = iter(sys.stdin)
for i in range(n):
l, r = map(int, next(itr).split())
c[l] += 1
c[r + 1] -= 1
c = list(it.accumulate(c))
c = list(it.accumulate([int(c[i] >= k) for i in range(len(c))]))
ans = []
for i in range(q):
l, r = map(int, input().split())
ans.append(str(c[r] - c[l - 1]))
print("\n".join(ans)) | IMPORT IMPORT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
nums = [0] * (200000 + 9)
for _ in range(n):
l, r = map(int, input().split())
nums[l] += 1
nums[r + 1] -= 1
for i in range(1, len(nums)):
nums[i] = nums[i] + nums[i - 1]
if nums[0] >= k:
nums[0] = 1
else:
nums[0] = 0
for i in range(1, len(nums)):
if nums[i] >= k:
nums[i] = nums[i - 1] + 1
else:
nums[i] = nums[i - 1]
for _ in range(q):
count = 0
l, r = map(int, input().split())
count = nums[r] - nums[l - 1]
print(count) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
c = [0] * 200002
p = [0] * 200002
for i in range(n):
a, b = map(int, input().split())
p[a] += 1
p[b + 1] -= 1
for i in range(1, 200002):
p[i] += p[i - 1]
c[i] = c[i - 1] + (p[i] >= k)
l = []
for i in range(q):
a, b = map(int, input().split())
print(c[b] - c[a - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | numberofRecipes, min_numberofRecipes, numberofQuestions = map(int, input().split())
recipes = [0] * 200009
for i in range(numberofRecipes):
low, high = map(int, input().split())
recipes[low] += 1
recipes[high + 1] -= 1
for i in range(1, len(recipes)):
recipes[i] += recipes[i - 1]
for i in range(1, len(recipes)):
if recipes[i] >= min_numberofRecipes:
recipes[i] = 1 + recipes[i - 1]
else:
recipes[i] = recipes[i - 1]
for i in range(numberofQuestions):
a, b = map(int, input().split())
print(recipes[b] - recipes[a - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin
inp = stdin.readline
n, k, q = map(int, inp().split())
temps = [0] * 200005
for i in range(n):
l, r = map(int, inp().split())
temps[l] += 1
temps[r + 1] -= 1
cur_sum = 0
cur_max = 0
for i in range(200005):
cur_sum += temps[i]
if cur_sum >= k:
cur_max += 1
temps[i] = cur_max
for i in range(q):
a, b = map(int, inp().split())
print(temps[b] - temps[a - 1]) | ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
Ri = lambda: [int(x) for x in sys.stdin.readline().split()]
ri = lambda: sys.stdin.readline().strip()
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
INF = 10**18
MOD = 10**9 + 7
n, k, q = Ri()
arr = [0] * (200000 + 2)
for i in range(n):
a, b = Ri()
arr[a] += 1
arr[b + 1] -= 1
for i in range(1, len(arr)):
arr[i] = arr[i - 1] + arr[i]
for i in range(1, len(arr)):
arr[i] = 1 if arr[i] >= k else 0
for i in range(1, len(arr)):
arr[i] = arr[i - 1] + arr[i]
for _ in range(q):
a, b = Ri()
print(arr[b] - arr[a - 1]) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
def main():
n, k, q = list(map(int, sys.stdin.readline().split()))
maxtemp = 200001
deltatemp_plus = [0] * maxtemp
deltatemp_minus = [0] * maxtemp
for i in range(n):
li, ri = list(map(int, sys.stdin.readline().split()))
deltatemp_plus[li] += 1
deltatemp_minus[ri] += 1
temp = [0] * maxtemp
cumsum = 0
for i in range(maxtemp):
cumsum += deltatemp_plus[i]
temp[i] = cumsum
cumsum -= deltatemp_minus[i]
goodtemp = [0] * maxtemp
goodtemp[0] = 1 if temp[0] >= k else 0
for i in range(1, maxtemp):
adder = 1 if temp[i] >= k else 0
goodtemp[i] = goodtemp[i - 1] + adder
for iq in range(q):
ai, bi = list(map(int, sys.stdin.readline().split()))
if ai == 0:
result = goodtemp[bi]
else:
result = goodtemp[bi] - goodtemp[ai - 1]
sys.stdout.write(str(result) + "\n")
main() | IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
n, k, q = rinput()
nums = [0] * 200002
for _ in range(n):
l, r = rinput()
nums[l] += 1
nums[r + 1] -= 1
for i in range(200001):
if i != 0:
nums[i] = nums[i] + nums[i - 1]
nums = [(1 if n >= k else 0) for n in nums]
for i in range(200001):
if i != 0:
nums[i] = nums[i] + nums[i - 1]
ans = []
for _ in range(q):
l, r = rinput()
ans.append(nums[r] - nums[l - 1])
for a in ans:
print(a) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
from itertools import accumulate
def main():
n, k, q = list(map(int, sys.stdin.readline().split()))
ary = [0] * 2000001
num_valid = [0] * 2000001
max_temp = -1
for __ in range(n):
s, t = list(map(int, sys.stdin.readline().split()))
ary[s - 1] += 1
ary[t] -= 1
tot = 0
for indx in range(len(num_valid) - 1):
tot += ary[indx]
num_valid[indx + 1] = num_valid[indx] + (tot >= k)
for __ in range(q):
s, t = list(map(int, sys.stdin.readline().split()))
print(num_valid[t] - num_valid[s - 1])
def __starting_point():
main()
__starting_point() | IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
n, k, q = map(int, stdin.readline().rstrip().split())
c = [0] * 200002
for i in range(n):
a, b = map(int, input().split(" "))
c[a] += 1
c[b + 1] -= 1
for i in range(1, len(c)):
c[i] = c[i] + c[i - 1]
for i in range(0, len(c)):
c[i] = 1 if c[i] >= k else 0
for i in range(1, len(c)):
c[i] = c[i] + c[i - 1]
for i in range(q):
a, b = map(int, stdin.readline().rstrip().split())
stdout.write(str(c[b] - c[a - 1]) + "\n") | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
n, k, q = map(int, stdin.readline().split())
length = 2 * 10**5 + 2
a = [(0) for i in range(length)]
for i in range(n):
l, r = map(int, stdin.readline().split())
a[l - 1] += 1
a[r] -= 1
for i in range(1, length):
a[i] += a[i - 1]
for i in range(length):
if a[i] >= k:
a[i] = 1
else:
a[i] = 0
for i in range(1, length):
a[i] += a[i - 1]
for i in range(q):
l, r = map(int, stdin.readline().split())
if l - 2 < 0:
stdout.write(str(a[r - 1]) + "\n")
else:
stdout.write(str(a[r - 1] - a[l - 2]) + "\n") | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
MN = 200005
inp = stdin.readline().split()
n = int(inp[0])
k = int(inp[1])
q = int(inp[2])
dod = [0] * MN
pref = [0] * MN
cnt = 0
for i in range(0, n):
inp = stdin.readline().split()
dod[int(inp[0])] += 1
dod[int(inp[1]) + 1] -= 1
for i in range(1, MN):
cnt += dod[i]
pref[i] = pref[i - 1]
if cnt >= k:
pref[i] += 1
for i in range(0, q):
inp = stdin.readline().split()
stdout.write(str(pref[int(inp[1])] - pref[int(inp[0]) - 1]) + "\n") | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = list(map(int, input().split()))
MAX_TEMP = 200000 + 10
temps = [(0) for x in range(MAX_TEMP)]
for i in range(n):
l, r = list(map(int, input().split()))
temps[l] += 1
temps[r + 1] -= 1
sums = [(0) for x in range(MAX_TEMP)]
count = 0
for i in range(1, MAX_TEMP):
count += temps[i]
if count >= k:
sums[i] = 1
sums[i] += sums[i - 1]
answers = []
for i in range(q):
a, b = list(map(int, input().split()))
answers.append(sums[b] - sums[a - 1])
for ans in answers:
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from itertools import accumulate
n, s, q = map(int, input().split())
prefix_ranges = [0] * 200002
for i in range(n):
x, y = map(int, input().split())
prefix_ranges[x] += 1
prefix_ranges[y + 1] -= 1
prefix_ranges = list(accumulate(prefix_ranges))
prefix_ranges = list(
accumulate([(prefix_ranges[i] >= s) for i in range(len(prefix_ranges))])
)
ans = [0] * q
for i in range(q):
x, y = map(int, input().split())
ans[i] = prefix_ranges[y] - prefix_ranges[x - 1]
for i in range(q):
print(ans[i]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
a = [0] * 200007
c = [0] * 200007
for i in range(0, n):
l, r = list(map(int, input().split()))
a[r + 1] -= 1
a[l] += 1
for i in range(1, 200007):
a[i] += a[i - 1]
if a[i] >= k:
c[i] = 1
c[i] += c[i - 1]
while q > 0:
l, r = list(map(int, input().split()))
print(c[r] - c[l - 1])
q -= 1 | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
n, k, q = map(int, sys.stdin.readline().strip().split(" "))
minR, maxR = 10**9, -(10**9)
tmp = 0
re = []
for i in range(n):
l, r = map(int, sys.stdin.readline().strip().split(" "))
minR = min(minR, l)
maxR = max(maxR, r)
re.append((l, r))
interval = [(0) for _ in range(maxR - minR + 2)]
for r in re:
interval[r[0] - minR] += 1
interval[r[1] - minR + 1] -= 1
L = len(interval)
for i in range(1, L):
interval[i] += interval[i - 1]
res = [(0) for _ in range(L + 1)]
for i in range(L):
if interval[i] >= k:
res[i + 1] = 1
for i in range(1, L + 1):
res[i] += res[i - 1]
for i in range(q):
l, r = map(int, sys.stdin.readline().strip().split(" "))
if r < minR or l > maxR:
print(0)
continue
print(res[min(r + 1 - minR, L)] - res[max(0, l - minR)]) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
MAX = 200000
a = [0] * (MAX + 1)
n, mn, nQ = map(int, stdin.readline().split())
for _ in range(n):
l, r = map(lambda x: int(x) - 1, stdin.readline().split())
a[l] += 1
a[r + 1] -= 1
psums = [0]
d = 0
for i in range(MAX):
d += a[i]
a[i] = d
a[i] = 0 if a[i] < mn else 1
psums.append(psums[-1] + a[i])
sumRange = lambda l, r: psums[r + 1] - psums[l]
for _ in range(nQ):
l, r = map(lambda x: int(x) - 1, stdin.readline().split())
stdout.write("%d\n" % sumRange(l, r)) | ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from itertools import accumulate
MAX = 200002
n, k, q = map(int, input().split())
info = [0] * MAX
for i in range(n):
l, r = map(int, input().split())
info[l] += 1
info[r + 1] -= 1
acc = 0
for ind, diff in enumerate(info):
acc += diff
if acc >= k:
info[ind] = 1
else:
info[ind] = 0
pref = list(accumulate(info))
ans = []
for i in range(q):
l, r = map(int, input().split())
ans.append(str(pref[r] - pref[l - 1]))
print("\n".join(ans)) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
qs = [list(map(int, input().split())) for i in range(q)]
def answer(q):
a, b = q
if a == 1:
print(l3[b - 1])
else:
print(l3[b - 1] - l3[a - 2])
l2 = [0] * 200000
l3 = [0] * 200000
adds = [0] * 200000
mins = [0] * 200000
for r in l:
adds[r[0] - 1] += 1
mins[r[1] - 1] += 1
l2[0] = adds[0] - mins[0]
if adds[0] >= k:
l3[0] = 1
for i in range(1, 200000):
l2[i] = l2[i - 1] + adds[i]
if l2[i] >= k:
l3[i] = 1
l2[i] -= mins[i]
for i in range(1, 200000):
l3[i] = l3[i - 1] + l3[i]
for q in qs:
answer(q) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
n, k, q = map(int, sys.stdin.readline().split())
check = [0] * 200012
for i in range(n):
l, r = map(int, sys.stdin.readline().split())
check[l] += 1
check[r + 1] -= 1
for i in range(200001):
check[i + 1] += check[i]
if check[i] >= k:
check[i] = 1
else:
check[i] = 0
for i in range(200000):
check[i + 1] += check[i]
for i in range(q):
count = 0
a, b = map(int, sys.stdin.readline().split())
sys.stdout.write(str(check[b] - check[a - 1]) + "\n") | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
l = [0] * 200001
for i in range(n):
li, ri = map(int, input().split())
l[li - 1] += 1
l[ri] -= 1
l1 = []
if l[0] >= k:
l1.append(1)
else:
l1.append(0)
la = []
lb = []
for i in range(q):
a, b = map(int, input().split())
la.append(a)
lb.append(b)
d = max(lb)
for i in range(1, d + 1):
l[i] = l[i] + l[i - 1]
if l[i] >= k:
l1.append(l1[len(l1) - 1] + 1)
else:
l1.append(l1[len(l1) - 1])
for j in range(q):
a, b = la[j], lb[j]
if a == 1:
print(l1[b - 1])
else:
print(l1[b - 1] - l1[a - 2]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
l = list(map(int, input().split()))
r = l[0]
k = l[1]
q = l[2]
count = [0] * 200002
for i in range(r):
l1 = list(map(int, input().split()))
count[l1[0]] += 1
count[l1[1] + 1] -= 1
check = [0] * 200002
for i in range(1, 200002):
count[i] += count[i - 1]
for i in range(200001):
if count[i] >= k:
check[i] = 1
for i in range(1, 200002):
check[i] += check[i - 1]
for i in range(q):
l1 = list(map(int, input().split()))
print(check[l1[1]] - check[l1[0] - 1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | N = 200002
f = [0] * N
ans = [0] * N
res = []
n, k, q = map(int, input().split(" "))
while n:
l, r = map(int, input().split(" "))
f[l] += 1
f[r + 1] -= 1
n -= 1
for i in range(1, N):
f[i] += f[i - 1]
ans[i] += ans[i - 1] + (f[i] >= k)
while q:
l, r = map(int, input().split(" "))
res.append(ans[r] - ans[l - 1])
q -= 1
print(*res, sep="\n") | ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
def prefix_sum(arr):
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
n, k, q = map(int, input().split())
maxi = 0
arr = []
for _ in range(n):
a, b = map(int, input().split())
arr.append([a, b])
maxi = max(maxi, a, b)
diff = [0] * (maxi + 2)
for i in range(n):
diff[arr[i][0]] += 1
diff[arr[i][1] + 1] -= 1
prefix_sum(diff)
count_two = [0] * (maxi + 2)
for i in range(1, maxi + 2):
if diff[i] >= k:
count_two[i] = 1 + count_two[i - 1]
else:
count_two[i] = count_two[i - 1]
for i in range(q):
a, b = map(int, input().split())
if a - 1 < 0:
a = 0
elif a > maxi:
a = maxi + 1
print(max(0, count_two[min(maxi, b)] - count_two[max(0, a - 1)])) | IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
n, k, q = [int(i) for i in stdin.readline().split()]
sm = [0] * 200001
st = [0] * 200001
nd = [0] * 200001
for i in range(n):
l, r = [int(i) for i in stdin.readline().split()]
st[l] += 1
nd[r] += 1
b = 0
for t in range(1, 200001):
b += st[t]
sm[t] = sm[t - 1]
if b >= k:
sm[t] += 1
b -= nd[t]
for i in range(q):
l, r = [int(i) for i in stdin.readline().split()]
stdout.write(str(sm[r] - sm[l - 1]))
stdout.write("\n") | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
def read_ints():
return list(map(int, stdin.readline().split()))
n, k, q = read_ints()
MAX_TEMP = 200000 + 10
temps = [(0) for x in range(MAX_TEMP)]
for i in range(n):
l, r = read_ints()
temps[l] += 1
temps[r + 1] -= 1
sums = [(0) for x in range(MAX_TEMP)]
count = 0
for i in range(1, MAX_TEMP):
count += temps[i]
if count >= k:
sums[i] = 1
sums[i] += sums[i - 1]
for i in range(q):
a, b = read_ints()
print(sums[b] - sums[a - 1]) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
def prefix_sums(array):
res = [array[0]]
for v in array[1:]:
res.append(res[-1] + v)
return res
class FastIntervalSummer:
def __init__(self, array):
self._prefix_sums = [0] + prefix_sums(array)
def interval_sum(self, l, r):
return self._prefix_sums[r + 1] - self._prefix_sums[l]
def read_ints(line):
return list(map(int, line.split()))
lines = sys.stdin.read().strip().split("\n")
n, k, q = read_ints(lines[0])
lines = lines[1:]
recipies = [read_ints(line) for line in lines[:n]]
lines = lines[n:]
queries = [read_ints(line) for line in lines]
max_t = max(map(max, recipies))
diff_recipies = [0] * (max_t + 2)
for l, r in recipies:
diff_recipies[l] += 1
diff_recipies[r + 1] -= 1
t_to_num_recipies = prefix_sums(diff_recipies)
t_to_admissible = [(1 if n_recipies >= k else 0) for n_recipies in t_to_num_recipies]
t_to_admissible_ps = FastIntervalSummer(t_to_admissible)
for l, r in queries:
l = min(l, len(t_to_admissible) - 1)
r = min(r, len(t_to_admissible) - 1)
print(t_to_admissible_ps.interval_sum(l, r)) | IMPORT FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = list(map(int, input().split()))
recipes = [0] * (200000 + 2)
res = []
for _ in range(n):
l, r = list(map(int, input().split()))
recipes[l] += 1
recipes[r + 1] -= 1
for i in range(1, len(recipes)):
recipes[i] += recipes[i - 1]
for i in range(1, len(recipes)):
recipes[i] = 1 if recipes[i] >= k else 0
recipes[i] += recipes[i - 1]
for _ in range(q):
a, b = list(map(int, input().split()))
res.append(recipes[b] - recipes[a - 1])
print("\n".join(map(str, res))) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | recipes, min_recipes, questions = map(int, input().split())
recipes_temp = [0] * 200002
for _ in range(recipes):
l, r = map(int, input().split())
recipes_temp[l] += 1
recipes_temp[r + 1] -= 1
for i in range(1, 200002):
recipes_temp[i] = recipes_temp[i - 1] + recipes_temp[i]
for i in range(1, 200002):
recipes_temp[i] = 1 if recipes_temp[i] >= min_recipes else 0
for i in range(1, 200002):
recipes_temp[i] = recipes_temp[i - 1] + recipes_temp[i]
resp = list()
for _ in range(questions):
l, r = map(int, input().split())
resp.append(recipes_temp[r] - recipes_temp[l - 1])
print(*resp, sep="\n") | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
recipe_in = []
for i in range(n):
l, r = map(int, input().split())
recipe_in.append((l, r))
query_in = []
for i in range(q):
l, r = map(int, input().split())
query_in.append((l, r))
MAX = 200000 + 10
recipes = [(0) for i in range(MAX)]
for recipe in recipe_in:
l, r = recipe
recipes[l] += 1
recipes[r + 1] -= 1
for i in range(1, MAX):
recipes[i] += recipes[i - 1]
cnts = [(0) for i in range(MAX)]
for i in range(MAX):
if recipes[i] >= k:
cnts[i] += 1
for i in range(1, MAX):
cnts[i] += cnts[i - 1]
for query in query_in:
l, r = query
ans = cnts[r] - cnts[l - 1]
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 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 ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | M = 200002
arr = [0] * M
n, k, q = list(map(int, input().split()))
narr = [list(map(int, input().split())) for _ in range(n)]
qarr = [list(map(int, input().split())) for _ in range(q)]
for i, j in narr:
arr[i] += 1
arr[j + 1] += -1
for i in range(1, M):
arr[i] = arr[i] + arr[i - 1]
arr = [(1 if i >= k else 0) for i in arr]
for i in range(1, M):
arr[i] = arr[i] + arr[i - 1]
for qs, qd in qarr:
print(arr[qd] - arr[qs - 1]) | ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
max_degree = 2 * 10**5 + 2
suggest_v = [0] * max_degree
for i in range(0, n):
l, r = map(int, input().split())
suggest_v[l] += 1
suggest_v[r + 1] -= 1
qq = []
for i in range(0, q):
a, b = map(int, input().split())
qq.append([a, b])
for i in range(1, max_degree):
suggest_v[i] += suggest_v[i - 1]
for i in range(0, max_degree):
suggest_v[i] = int(suggest_v[i] >= k)
for i in range(1, max_degree):
suggest_v[i] += suggest_v[i - 1]
for i in range(0, q):
a = qq[i][0]
b = qq[i][1]
print(suggest_v[b] - suggest_v[a - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER 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 VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER 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 LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
a = [0] * 200002
b = [0] * 200002
c = [0] * 200002
s = 0
for i in range(n):
l, r = map(int, input().split())
a[l] = a[l] + 1
a[r + 1] = a[r + 1] - 1
for i in range(1, 200002):
s = s + a[i]
if s >= k:
b[i] = 1
for i in range(1, 200002):
c[i] = c[i - 1] + b[i]
for i in range(q):
l, r = map(int, input().split())
print(c[r] - c[l - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin
def main():
test = stdin.readlines()
n, k, q = map(int, test[0].split())
recipes = [0] * 200003
for i in range(1, n + 1):
li, ri = map(int, test[i].split())
recipes[li] += 1
recipes[ri + 1] -= 1
rec = [0]
for e in recipes:
rec.append(rec[-1] + e)
for i, e in enumerate(rec):
if e < k:
rec[i] = 0
else:
rec[i] = 1
sugg = [0]
for e in rec:
sugg.append(sugg[-1] + e)
ans = 0
out = []
for i in range(1 + n, n + q + 1):
li, ri = map(int, test[i].split())
ans = sugg[ri + 2] - sugg[li + 1]
out.append(ans)
print("\n".join(map(str, out)))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
def rint():
return list(map(int, stdin.readline().split()))
n, k, q = rint()
r = [(0) for i in range(200001)]
l = [(0) for i in range(200001)]
for i in range(n):
ll, rr = rint()
r[rr] += 1
l[ll] += 1
f = [(0) for i in range(200001)]
for i in range(1, 200001):
f[i] = f[i - 1] + l[i] - r[i - 1]
ss = [(0) for i in range(200002)]
for i in range(200000, 0, -1):
if f[i] >= k:
ss[i] = ss[i + 1] + 1
else:
ss[i] = ss[i + 1]
for i in range(q):
ll, rr = rint()
print(ss[ll] - ss[rr + 1]) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
m = [0] * 200001
a = 0
for i in range(n):
a, b = map(int, input().split())
m[a - 1] += 1
m[b] -= 1
mk = []
for i in range(q):
mk.append(list(map(int, input().split())))
a = 0
pre = []
for i in range(200001):
a = a + m[i]
if a >= k:
pre.append(1)
else:
pre.append(0)
pre2 = []
a = 0
pre2.append(0)
for i in range(200001):
a = a + pre[i]
pre2.append(a)
for i in range(q):
out = pre2[mk[i][1]] - pre2[mk[i][0] - 1]
print(out) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | def main():
n, k, q = list(map(int, input().split()))
l, res = [0] * 200002, []
for _ in range(n):
a, b = list(map(int, input().split()))
l[a] += 1
l[b + 1] -= 1
a = 0
for i, b in enumerate(l):
a += b
l[i] = a >= k
a = 0
for i, b in enumerate(l):
if b:
a += 1
l[i] = a
for _ in range(q):
a, b = list(map(int, input().split()))
res.append(l[b] - l[a - 1])
print("\n".join(map(str, res)))
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
n, k, q = read_int_line()
c = [0] * 200010
for i in range(n):
li, ri = read_int_line()
c[li] += 1
c[ri + 1] -= 1
summ = 0
for i in range(len(c)):
summ += c[i]
c[i] = summ
for i in range(len(c)):
if c[i] >= k:
c[i] = 1
else:
c[i] = 0
summ = 0
for i in range(len(c)):
summ += c[i]
c[i] = summ
for i in range(q):
a, b = read_int_line()
print(c[b] - c[a - 1]) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | def main():
n_k_q_list = list(map(int, str(input()).split()))
n = n_k_q_list[0]
k = n_k_q_list[1]
q = n_k_q_list[2]
temp_list = []
queries = []
min_temp = 200001
max_temp = 0
for i in range(n):
temp_list.append(tuple(map(int, str(input()).split())))
if temp_list[i][0] < min_temp:
min_temp = temp_list[i][0]
if temp_list[i][1] > max_temp:
max_temp = temp_list[i][1]
size = max_temp - min_temp + 1
temp_marker = [(0) for i in range(size)]
for i in range(n):
temp_marker[temp_list[i][0] - min_temp] += 1
if temp_list[i][1] - min_temp + 1 <= size - 1:
temp_marker[temp_list[i][1] - min_temp + 1] -= 1
admissible_temp_freq = get_admissible_temp_freq(temp_marker, size, k)
ans_list = []
for i in range(q):
queries.append(tuple(map(int, str(input()).split())))
start_idx = queries[i][0] - min_temp
end_idx = queries[i][1] - min_temp
if start_idx < 0:
start_idx = 0
if end_idx > size - 1:
end_idx = size - 1
if start_idx > size - 1 or end_idx < 0:
ans_list.append(0)
continue
if start_idx - 1 >= 0:
ans_list.append(
admissible_temp_freq[end_idx] - admissible_temp_freq[start_idx - 1]
)
else:
ans_list.append(admissible_temp_freq[end_idx])
for i in range(q):
print(ans_list[i])
def get_admissible_temp_freq(given_arr, size, k=0):
prefix = [given_arr[0]]
admissible_temps_freq = []
freq = 0
if given_arr[0] >= k:
freq += 1
admissible_temps_freq.append(freq)
for i in range(1, size):
prefix.append(prefix[i - 1] + given_arr[i])
if prefix[i] >= k:
freq += 1
admissible_temps_freq.append(freq)
return admissible_temps_freq
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR 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 FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = lambda: sys.stdin.readline()
MOD = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: list(map(int, input().split()))
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
n, k, q = f()
lsf = [0] * 200009
ldp = [0] * 200009
for _ in range(n):
a, b = f()
lsf[a] += 1
lsf[b + 1] -= 1
for i in range(1, 200007):
lsf[i] += lsf[i - 1]
ldp[i] = ldp[i - 1] + (lsf[i] >= k) * 1
for _ in range(q):
a, b = f()
sys.stdout.write(str(ldp[b] - ldp[a - 1]) + "\n") | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
n, k, q = map(int, input().split())
recommended = [0] * 200002
for _ in range(n):
a, b = map(int, input().split())
recommended[a] += 1
recommended[b + 1] -= 1
cum = 0
for i in range(200002):
cum += recommended[i]
recommended[i] = cum
prefix_sum = [0]
for i in range(1, 200002):
if recommended[i] >= k:
prefix_sum.append(prefix_sum[-1] + 1)
else:
prefix_sum.append(prefix_sum[-1])
for _ in range(q):
a, b = map(int, input().split())
print(prefix_sum[b] - prefix_sum[a - 1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | def solve():
n, k, q = map(int, input().split())
pre = [0] * 200002
for i in range(0, n):
l, r = map(int, input().split())
pre[l] += 1
pre[r + 1] -= 1
for i in range(1, 200002):
pre[i] = pre[i] + pre[i - 1]
cnt = [0] * 200002
for i in range(0, 200002):
if i == 0:
if pre[i] >= k:
cnt[0] = 1
elif pre[i] >= k:
cnt[i] = cnt[i - 1] + 1
else:
cnt[i] = cnt[i - 1]
for i in range(0, q):
l, r = map(int, input().split())
print(cnt[r] - cnt[l - 1])
solve() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from itertools import accumulate
nums, temp, out = [0] * 200002, 0, []
n, k, q = map(int, input().split(" "))
for i in range(n):
l, r = map(int, input().split(" "))
nums[l] += 1
nums[r + 1] -= 1
for i in range(1, 200002):
temp += nums[i]
nums[i] = temp >= k
for i in range(1, 200002):
nums[i] += nums[i - 1]
for i in range(q):
a, b = map(int, input().split(" "))
out.append(str(nums[b] - nums[a - 1]))
print("\n".join(out)) | ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | def prefix_sum(a):
b = [a[0]]
n = len(a)
for i in range(1, n, 1):
b.append(b[i - 1] + a[i])
return b
def pre_process(a, k):
n = len(a)
for i in range(1, n, 1):
if a[i] >= k:
a[i] = 1
else:
a[i] = 0
return a
def main():
n, k, q = input().split(" ")
n, k, q = [int(x) for x in [n, k, q]]
c = [(0) for i in range(200002)]
for i in range(n):
temp = [int(j) for j in input().split(" ")]
c[temp[0]] += 1
c[temp[1] + 1] -= 1
c = prefix_sum(c)[:]
sol = pre_process(c, k)
sol = prefix_sum(sol)[:]
res = []
for i in range(q):
temp = [int(j) for j in input().split(" ")]
a = temp[0]
b = temp[1]
res.append(sol[b] - sol[a - 1])
for i in res:
print(i)
main() | FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR LIST VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
nl = "\n"
input = sys.stdin.readline
print = sys.stdout.write
c = [0] * 200003
n, k, q = [int(x) for x in input().split()]
for i in range(n):
l, r = [int(x) for x in input().split()]
c[l] += 1
c[r + 1] -= 1
clen = len(c)
for i in range(1, clen):
c[i] += c[i - 1]
for i in range(clen):
c[i] = c[i] >= k
for i in range(1, clen):
c[i] += c[i - 1]
for i in range(q):
a, b = [int(x) for x in input().split()]
print(str(c[b] - c[a - 1]) + nl) | IMPORT ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
rec = [(0) for i in range(200005)]
ques = []
for i in range(n):
l, r = map(int, input().split())
rec[l] += 1
rec[r + 1] -= 1
for i in range(1, len(rec)):
rec[i] += rec[i - 1]
for i in range(1, len(rec)):
if rec[i] >= k:
rec[i] = 1
else:
rec[i] = 0
rec[i] += rec[i - 1]
for i in range(q):
l, r = map(int, input().split())
ques.append(rec[r] - rec[l - 1])
ques = map(str, ques)
print("\n".join(ques)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER 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 BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
l = [0] * (2 * 10**5 + 2)
for _ in range(n):
a, b = map(int, input().split())
l[a] += 1
l[b + 1] -= 1
prefix = []
temp = 0
for i in l:
temp += i
prefix.append(temp)
ar = [0] * (2 * 10**5 + 2)
for i in range(2 * 10**5 + 2):
if prefix[i] >= k:
ar[i] = 1
prefixarray = []
temp = 0
for i in ar:
temp += i
prefixarray.append(temp)
for i in range(q):
a, b = map(int, input().split())
print(prefixarray[b] - prefixarray[a - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
class FastInput:
def __init__(self, file=sys.stdin):
self._lines = file.read().strip().split("\n")
self._index = 0
def next_line(self):
ret = self._lines[self._index]
self._index += 1
return ret
def line_of_ints(self):
return list(map(int, self.next_line().split()))
def prefix_sums(array):
res = [array[0]]
for v in array[1:]:
res.append(res[-1] + v)
return res
class FastIntervalSummer:
def __init__(self, array):
self._prefix_sums = [0] + prefix_sums(array)
def interval_sum(self, l, r):
return self._prefix_sums[r + 1] - self._prefix_sums[l]
data = FastInput()
n, k, q = data.line_of_ints()
recipies = [data.line_of_ints() for _ in range(n)]
queries = [data.line_of_ints() for _ in range(q)]
max_t = max(map(max, recipies))
diff_recipies = [0] * (max_t + 2)
for l, r in recipies:
diff_recipies[l] += 1
diff_recipies[r + 1] -= 1
t_to_num_recipies = prefix_sums(diff_recipies)
t_to_admissible = [(1 if n_recipies >= k else 0) for n_recipies in t_to_num_recipies]
t_to_admissible_ps = FastIntervalSummer(t_to_admissible)
for l, r in queries:
l = min(l, len(t_to_admissible) - 1)
r = min(r, len(t_to_admissible) - 1)
print(t_to_admissible_ps.interval_sum(l, r)) | IMPORT CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
def ii():
return int(stdin.readline())
def mi():
return map(int, stdin.readline().split())
def li():
return list(mi())
def si():
return stdin.readline()
n, k, q = mi()
l1 = [0] * 200002
pf = [0] * 200002
for _ in range(n):
a, b = mi()
l1[a] += 1
l1[b + 1] -= 1
pf[0] = l1[0]
for i in range(1, 200002):
pf[i] = pf[i - 1] + l1[i]
for i in range(200002):
if pf[i] >= k:
pf[i] = 1
else:
pf[i] = 0
for i in range(1, 200002):
pf[i] += pf[i - 1]
for _ in range(q):
a, b = mi()
print(pf[b] - pf[a - 1]) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | from sys import stdin, stdout
readline = stdin.readline
write = stdout.write
n, k, q = map(int, readline().split())
A = [(0) for _ in range(200002)]
for i in range(n):
l, r = map(int, readline().split())
A[l] += 1
A[r + 1] -= 1
for i in range(1, 200002):
A[i] += A[i - 1]
for i in range(1, 200002):
A[i] = 1 if A[i] >= k else 0
for i in range(1, 200002):
A[i] += A[i - 1]
for i in range(q):
a, b = map(int, readline().split())
write(str(A[b] - A[a - 1]) + "\n") | ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
n, k, q = list(map(int, input().split()))
leng = 200002
c = [0] * leng
pre_s = [0] * leng
for i in range(n):
a, b = list(map(int, input().split()))
c[a] += 1
c[b + 1] -= 1
for i in range(1, leng):
c[i] += c[i - 1]
pre_s[i] = pre_s[i - 1] + (c[i] >= k)
for i in range(q):
a, b = list(map(int, input().split()))
print(pre_s[b] - pre_s[a - 1]) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | a = [(0) for i in range(2 * 10**5 + 1)]
x = []
x = input().split()
x[0] = int(x[0])
x[1] = int(x[1])
x[2] = int(x[2])
for i in range(x[0]):
y = []
y = input().split()
a[int(y[0]) - 1] += 1
a[int(y[1])] -= 1
ps = []
sum = 0
for i in range(2 * 10**5 + 1):
sum += a[i]
if sum >= x[1]:
ps.append(1)
else:
ps.append(0)
ps1 = [(0) for i in range(2 * 10**5 + 1)]
ps1[0] = ps[0]
for i in range(1, 2 * 10**5):
ps1[i] = ps1[i - 1] + ps[i]
sol = []
for i in range(x[2]):
y = []
y = input().split()
if int(y[0]) > 0:
sol.append(ps1[int(y[1]) - 1] - ps1[int(y[0]) - 2])
else:
sol.append(ps1[int(y[1]) - 1])
for i in range(x[2]):
print(sol[i]) | ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | n, k, q = map(int, input().split())
numRec_temp_i = [(0) for i in range(200001)]
for i in range(n):
l, r = map(int, input().split())
numRec_temp_i[l] += 1
if r < 200000:
numRec_temp_i[r + 1] -= 1
for i in range(1, 200001):
numRec_temp_i[i] += numRec_temp_i[i - 1]
for i in range(1, 200001):
if numRec_temp_i[i] >= k:
numRec_temp_i[i] = 1 + numRec_temp_i[i - 1]
else:
numRec_temp_i[i] = numRec_temp_i[i - 1]
z = []
for i in range(q):
a, b = map(int, input().split())
z.append(str(numRec_temp_i[b] - numRec_temp_i[a - 1]))
print("\n".join(z)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | import sys
input = sys.stdin.readline
print = sys.stdout.write
n, k, q = map(int, input().split())
ar = [0] * (200000 + 2)
def f(l, r):
ar[l] += 1
ar[r + 1] -= 1
for x in range(n):
a, b = map(int, input().split())
f(a, b)
for x in range(1, 200000 + 1):
ar[x] += ar[x - 1]
for x in range(1, 200000 + 1):
ar[x] = ar[x] >= k
for x in range(1, 200000 + 1):
ar[x] += ar[x - 1]
for el in range(q):
a, b = map(int, input().split())
print(str(ar[b] - ar[a - 1]) + "\n") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FUNC_DEF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING |
To stay woke and attentive during classes, Karen needs some coffee! [Image]
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between l_{i} and r_{i} degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least k recipes recommend it.
Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?
-----Input-----
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next n lines describe the recipes. Specifically, the i-th line among these contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between l_{i} and r_{i} degrees, inclusive.
The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.
-----Output-----
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
-----Examples-----
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
-----Note-----
In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | recipes, admisionNums, questions = list(map(int, input().split()))
recipeList = []
questionList = []
partialSum = [0] * 200002
preSum = [0] * 200002
partialSum2 = [0] * 200002
preSum2 = [0] * 200002
counter = 0
for i in range(recipes):
recipeList.append(list(map(int, input().split())))
for i in range(questions):
questionList.append(list(map(int, input().split())))
for i in range(recipes):
partialSum[recipeList[i][0]] += 1
partialSum[recipeList[i][1] + 1] -= 1
preSum[0] = partialSum[0]
for i in range(1, 200002):
preSum[i] = preSum[i - 1] + partialSum[i]
for i in range(200002):
if preSum[i] >= admisionNums:
partialSum2[i] = 1
else:
partialSum2[i] = 0
preSum2[0] = partialSum2[0]
for i in range(1, 200002):
preSum2[i] = preSum2[i - 1] + partialSum2[i]
for question in questionList:
print(preSum2[question[1]] - preSum2[question[0] - 1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.