message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,633
12
37,266
Tags: data structures, greedy Correct Solution: ``` import sys as _sys def main(): n, = _read_ints() a = tuple(_read_ints()) m, = _read_ints() queries = (tuple(_read_ints()) for i_query in range(m)) result = process_queries(a, queries) print(*result, sep='\n') def _read_line(): result = ...
output
1
18,633
12
37,267
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,634
12
37,268
Tags: data structures, greedy Correct Solution: ``` from collections import defaultdict import sys as _sys def main(): n, = _read_ints() a = tuple(_read_ints()) m, = _read_ints() queries = (tuple(_read_ints()) for i_query in range(m)) result = process_queries(a, queries) print(*result, sep='\n...
output
1
18,634
12
37,269
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,635
12
37,270
Tags: data structures, greedy Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase class SortedList: def __init__(self, iterable=None, _load=200): """Initialize sorted list instance.""" if iterable is None: ...
output
1
18,635
12
37,271
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,636
12
37,272
Tags: data structures, greedy Correct Solution: ``` class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [values[i:i + _load] for...
output
1
18,636
12
37,273
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,637
12
37,274
Tags: data structures, greedy Correct Solution: ``` WIDTH = 10 def index_tree(n): levels = [ [1]*n ] size = WIDTH while size < n: m, r = n // size, n % size levels.append( [size]*m + ([r] if r > 0 else []) ) size *= WIDTH return levels def dec_index(levels, i): for level ...
output
1
18,637
12
37,275
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,638
12
37,276
Tags: data structures, greedy Correct Solution: ``` import sys class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class Avl...
output
1
18,638
12
37,277
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,639
12
37,278
Tags: data structures, greedy Correct Solution: ``` """ Author - Satwik Tiwari . 18th Feb , 2021 - Thursday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions imp...
output
1
18,639
12
37,279
Provide tags and a correct Python 3 solution for this coding contest problem. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a...
instruction
0
18,640
12
37,280
Tags: data structures, greedy Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------...
output
1
18,640
12
37,281
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems....
instruction
0
18,641
12
37,282
Yes
output
1
18,641
12
37,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems....
instruction
0
18,642
12
37,284
No
output
1
18,642
12
37,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the harder version of the problem. In this version, 1 ≀ n, m ≀ 2β‹…10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems....
instruction
0
18,643
12
37,286
No
output
1
18,643
12
37,287
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,756
12
37,512
Tags: brute force, greedy, implementation Correct Solution: ``` n, q = map(int, input().split()) arr = list(map(int, input().split())) count = sum(arr) answer = "" for _ in range(q): t, kx = map(int, input().split()) if t == 1: arr[kx-1] = 1 - arr[kx-1] if arr[kx-1]: count += 1 ...
output
1
18,756
12
37,513
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,757
12
37,514
Tags: brute force, greedy, implementation Correct Solution: ``` x,y=0,0 n, q = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): if a[i]==0: x+=1 else: y+=1 for i in range(q): t, m = map(int, input().split()) if t == 1: if a[m-1]==1: ...
output
1
18,757
12
37,515
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,758
12
37,516
Tags: brute force, greedy, implementation Correct Solution: ``` n,q=map(int,input().split()) a=list(map(int,input().split())) s=sum(a) for i in range(q): h,k=map(int,input().split()) if h==1: y=a[k-1] if y==1: s-=1 else: s+=1 a[k-1]=1-a[k-1] else: ...
output
1
18,758
12
37,517
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,759
12
37,518
Tags: brute force, greedy, implementation Correct Solution: ``` # cook your dish here n,q = map(int,input().split()) a = [int(x) for x in input().split()] d = {0:0,1:0} for i in a: d[i]+=1 for _ in range(q): x,y = map(int,input().split()) if x==1: y-=1 d[a[y]]-=1 a[y] = 1 - ...
output
1
18,759
12
37,519
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,760
12
37,520
Tags: brute force, greedy, implementation Correct Solution: ``` #author: anshul_129 from sys import stdin, stdout, maxsize from math import sqrt, log, factorial as ft, gcd from collections import defaultdict as D, OrderedDict as OD from bisect import insort n, q = map(int, stdin.readline().strip().split()) #s = stdin...
output
1
18,760
12
37,521
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,761
12
37,522
Tags: brute force, greedy, implementation Correct Solution: ``` import math def getint(): return [int(i) for i in input().split()] def getstr(): return [str(i) for i in input().split()] #-------------------------------------------------------------------------- def solve(): n,q=getint() a=getint() a...
output
1
18,761
12
37,523
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,762
12
37,524
Tags: brute force, greedy, implementation Correct Solution: ``` one = 0 def assign(m): global one if a[m-1] == 1: a[m-1] = 0 one = one-1 else: a[m-1] = 1 one = one+1 def show(n): if n <= one: print("1") else: print("0") n, q = [int(g) for g in input().split()] a = [int(h) for h in input().split()] fo...
output
1
18,762
12
37,525
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. ...
instruction
0
18,763
12
37,526
Tags: brute force, greedy, implementation Correct Solution: ``` #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from sys import stdin,stdout from io import BytesIO, IOBase from collections import deque #sys.setrecursionlimit(10**5) if sys.version_info[0] < 3: f...
output
1
18,763
12
37,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,764
12
37,528
Yes
output
1
18,764
12
37,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,765
12
37,530
Yes
output
1
18,765
12
37,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,766
12
37,532
Yes
output
1
18,766
12
37,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,767
12
37,534
Yes
output
1
18,767
12
37,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,768
12
37,536
No
output
1
18,768
12
37,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,769
12
37,538
No
output
1
18,769
12
37,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,770
12
37,540
No
output
1
18,770
12
37,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k...
instruction
0
18,771
12
37,542
No
output
1
18,771
12
37,543
Provide tags and a correct Python 3 solution for this coding contest problem. This is the hard version of the problem. The only difference is that in this version 1 ≀ q ≀ 10^5. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and len...
instruction
0
18,788
12
37,576
Tags: dp, math Correct Solution: ``` def solve(): MOD = 10**9+7 n = int(input()) c = list(map(int, input().split())) b = [0] + list(map(int, input().split())) q = int(input()) queries = list(map(int, input().split())) maxans = 1 for c1 in c: maxans = maxans * (c1+1) % MOD ans...
output
1
18,788
12
37,577
Provide tags and a correct Python 2 solution for this coding contest problem. You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter in your computer routine. We'll consider the RA...
instruction
0
18,850
12
37,700
Tags: binary search, bitmasks, greedy Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(s...
output
1
18,850
12
37,701
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter i...
instruction
0
18,851
12
37,702
No
output
1
18,851
12
37,703
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter i...
instruction
0
18,852
12
37,704
No
output
1
18,852
12
37,705
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,949
12
37,898
Tags: sortings Correct Solution: ``` na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) temp=a[k-1] for j in b: if j>temp: l=b.index(j) break try: if nb-l>=m: print('YES') else: print('NO'...
output
1
18,949
12
37,899
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,950
12
37,900
Tags: sortings Correct Solution: ``` n,m = map(int,input().split(' ')) a,b = map(int,input().split(' ')) arr1 = [int(i) for i in input().split(' ')] arr2 = [int(i) for i in input().split(' ')] if(arr1[a-1] < arr2[m-b]): print('YES') else: print('NO') ```
output
1
18,950
12
37,901
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,951
12
37,902
Tags: sortings Correct Solution: ``` a,b=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() a=a[:k] b=b[-m:] if(a[-1]>=b[0]): print("NO") else: print("YES") ```
output
1
18,951
12
37,903
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,952
12
37,904
Tags: sortings Correct Solution: ``` n, m = map(int, input().split()) k1, k2 = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if a[k1 - 1] < b[m - k2]: print('YES') else: print('NO') ```
output
1
18,952
12
37,905
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,953
12
37,906
Tags: sortings Correct Solution: ``` #!/usr/bin/env python3 import sys NA, NB = input().split() K, M = input().split() K, M = int(K), int(M) A = list(map(int, input().split())) B = list(map(int, input().split())) if (A[K-1] < B[-M]): print('YES') else: print('NO') ```
output
1
18,953
12
37,907
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,954
12
37,908
Tags: sortings Correct Solution: ``` # (1 ≀ nA, nB  ≀ 10^5) number_array_a , number_array_b = map(int,input().split()) # (1 ≀ k ≀ nA, 1 ≀ m ≀ nB) k , m = map(int,input().split()) # Array A ( - 10^9  ≀  a1  ≀  a2  ≀ ... ≀  anA  ≀  10^9), sorted in non-decreasing order array_a = list(map(int,input().split())) # Array B...
output
1
18,954
12
37,909
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,955
12
37,910
Tags: sortings Correct Solution: ``` input();x,y=map(int,input().split());a=list(map(int,input().split()));b=list(map(int,input().split())) print('YES' if a[:x][-1]<b[::-1][:y][-1] else 'NO') ```
output
1
18,955
12
37,911
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly les...
instruction
0
18,956
12
37,912
Tags: sortings Correct Solution: ``` na, nb = [int(j) for j in input().split()] k, m = [int(j) for j in input().split()] a = [int(j) for j in input().split()] b = [int(j) for j in input().split()] if a[k - 1] < b[nb - m]: print("YES") else: print("NO") ```
output
1
18,956
12
37,913
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,957
12
37,914
Yes
output
1
18,957
12
37,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,958
12
37,916
Yes
output
1
18,958
12
37,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,959
12
37,918
Yes
output
1
18,959
12
37,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,960
12
37,920
Yes
output
1
18,960
12
37,921
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,961
12
37,922
No
output
1
18,961
12
37,923
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,962
12
37,924
No
output
1
18,962
12
37,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,963
12
37,926
No
output
1
18,963
12
37,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any n...
instruction
0
18,964
12
37,928
No
output
1
18,964
12
37,929
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to cal...
instruction
0
19,043
12
38,086
Tags: data structures, math, probabilities, two pointers Correct Solution: ``` # Accepted on Hacker blocks, giving RTE on test case 6 on Codeforces lim = 10**7 last_occ = [ 0 for i in range(lim)] n = int(input()) ans = [0 for i in range(n+1)] arr = [int(i) for i in input().split()] arr.insert(0,0 ) #print("arr",arr)...
output
1
19,043
12
38,087
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to cal...
instruction
0
19,044
12
38,088
Tags: data structures, math, probabilities, two pointers Correct Solution: ``` import sys from collections import defaultdict n = int(sys.stdin.buffer.readline().decode('utf-8')) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) next_dic = defaultdict(list) for i in range(n-1, -1, -1): next_...
output
1
19,044
12
38,089
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to cal...
instruction
0
19,045
12
38,090
Tags: data structures, math, probabilities, two pointers Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) d = {} def push(d, x, i): if x not in d: d[x]=[] d[x].append(i) for i, x in enumerate(a): push(d, x, i) S=0 for arr in d.values(): pre=-1 for i in...
output
1
19,045
12
38,091