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. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and...
instruction
0
99,618
12
199,236
Tags: brute force, math, number theory Correct Solution: ``` from sys import * from math import * from sys import stdin,stdout from collections import * int_arr = lambda : list(map(int,stdin.readline().strip().split())) str_arr = lambda :list(map(str,stdin.readline().split())) get_str = lambda : map(str,stdin.readline...
output
1
99,618
12
199,237
Provide tags and a correct Python 3 solution for this coding contest problem. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and...
instruction
0
99,619
12
199,238
Tags: brute force, math, number theory Correct Solution: ``` import sys input=sys.stdin.readline for _ in range(int(input())): # n=int(input()) n,x,y=[int(j) for j in input().split()] ans=[] mini=min(x,y) y=max(x,y) x=mini # if n==2: # ans.append(x) # ans.append(y) # elif...
output
1
99,619
12
199,239
Provide tags and a correct Python 3 solution for this coding contest problem. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and...
instruction
0
99,620
12
199,240
Tags: brute force, math, number theory Correct Solution: ``` for _ in range(int(input())): n, x, y = map(int, input().split()) a_n_max = float('inf') d_max = 0 for n1 in range(2, n+1): d = (y - x)/(n1 - 1) if d % 1 == 0: for pos in range(n, n1-1, -1): a1 ...
output
1
99,620
12
199,241
Provide tags and a correct Python 3 solution for this coding contest problem. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and...
instruction
0
99,621
12
199,242
Tags: brute force, math, number theory Correct Solution: ``` t = int(input()) while t>0: n,x,y = list(map(int,input().split())) min_val = 1e5 min_diff = 0 for xpos in range(0,n-1): for ypos in range(xpos+1,n): l = ypos-xpos if (y-x) % l > 0 : continue diff = (y-x)/l max_item ...
output
1
99,621
12
199,243
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,622
12
199,244
Yes
output
1
99,622
12
199,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,623
12
199,246
Yes
output
1
99,623
12
199,247
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,624
12
199,248
Yes
output
1
99,624
12
199,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,625
12
199,250
Yes
output
1
99,625
12
199,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,626
12
199,252
No
output
1
99,626
12
199,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,627
12
199,254
No
output
1
99,627
12
199,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,628
12
199,256
No
output
1
99,628
12
199,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integ...
instruction
0
99,629
12
199,258
No
output
1
99,629
12
199,259
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,679
12
199,358
Tags: hashing, implementation, math Correct Solution: ``` for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) d={} ans=0 tmp=0 for i in range(n): if arr[i] in d: tmp+=d[arr[i]] else: d[arr[i]]=0 d[arr[i]]+=i+1 an...
output
1
99,679
12
199,359
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,680
12
199,360
Tags: hashing, implementation, math Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import defaultdict def main(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split...
output
1
99,680
12
199,361
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,681
12
199,362
Tags: hashing, implementation, math Correct Solution: ``` import bisect import collections import copy import functools import heapq import itertools import math import sys import string import random from typing import List sys.setrecursionlimit(99999) for _ in range(int(input())): n = int(input()) arr = lis...
output
1
99,681
12
199,363
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,682
12
199,364
Tags: hashing, implementation, math Correct Solution: ``` import math for t in range(int(input())): n=int(input()) #n,k=map(int,input().split()) a=list(map(int,input().split())) dp=[0 for i in range(n+1)] store={} for i in range(1,n+1): dp[i]=dp[i-1] if a[i-1] in store: ...
output
1
99,682
12
199,365
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,683
12
199,366
Tags: hashing, implementation, math Correct Solution: ``` import sys input=sys.stdin.readline from collections import * a=int(input()) for i in range(a): s=int(input()) z=list(map(int,input().split())) al=defaultdict(list) for i in range(len(z)): al[z[i]].append(i+1) total=0 for...
output
1
99,683
12
199,367
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,684
12
199,368
Tags: hashing, implementation, math Correct Solution: ``` from sys import stdin,stdout from collections import defaultdict from itertools import accumulate nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) for _ in range(nmbr()): n=nmbr() a=lst() g=defaultdict(list) for i in rang...
output
1
99,684
12
199,369
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,685
12
199,370
Tags: hashing, implementation, math Correct Solution: ``` def fun(n,ls): dp=[0 for i in range(n)] dct={i:0 for i in ls} ans=0 for i in range(n): if(i>0): dp[i]=dp[i-1] if(ls[i] in dct): dp[i]+=dct.get(ls[i]) dct[ls[i]]+=i+1 ans+=dp[i] print(ans...
output
1
99,685
12
199,371
Provide tags and a correct Python 3 solution for this coding contest problem. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. The set of unordered pairs of indexes with same...
instruction
0
99,686
12
199,372
Tags: hashing, implementation, math Correct Solution: ``` #!/usr/bin/env pypy from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip ...
output
1
99,686
12
199,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,687
12
199,374
Yes
output
1
99,687
12
199,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,688
12
199,376
Yes
output
1
99,688
12
199,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,689
12
199,378
Yes
output
1
99,689
12
199,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,690
12
199,380
Yes
output
1
99,690
12
199,381
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,691
12
199,382
No
output
1
99,691
12
199,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,692
12
199,384
No
output
1
99,692
12
199,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,693
12
199,386
No
output
1
99,693
12
199,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The weight of a sequence is defined as the number of unordered pairs of indexes (i,j) (here i < j) with same value (a_{i} = a_{j}). For example, the weight of sequence a = [1, 1, 2, 2, 1] is 4. ...
instruction
0
99,694
12
199,388
No
output
1
99,694
12
199,389
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,877
12
199,754
Tags: combinatorics, sortings, two pointers Correct Solution: ``` from sys import stdin def main(): n, k = map(int, stdin.readline().split()) ar = list(map(int, stdin.readline().split())) lk = {ar[i] - 1: i for i in range(n)} pair = [-1 for _ in range(n)] for _ in range(k): x, y = map(int,...
output
1
99,877
12
199,755
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,878
12
199,756
Tags: combinatorics, sortings, two pointers Correct Solution: ``` def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().spl...
output
1
99,878
12
199,757
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,879
12
199,758
Tags: combinatorics, sortings, two pointers Correct Solution: ``` def f(): sizes = input().split(' ') n, m = int(sizes[0]), int(sizes[1]) permStr = input().split(' ') pairsStr = [input() for i in range(m)] indexes = [0 for i in range(n+1)] for i in range(n): indexes[int(permStr[i])] = ...
output
1
99,879
12
199,759
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,880
12
199,760
Tags: combinatorics, sortings, two pointers Correct Solution: ``` """ 652C - Π’Ρ€Π°ΠΆΠ΄Π΅Π±Π½Ρ‹Π΅ ΠΏΠ°Ρ€Ρ‹ http://codeforces.com/problemset/problem/652/C ΠŸΡ€Π΅Π΄ΠΏΠΎΠ΄ΡΡ‡ΠΈΡ‚Π°Π΅ΠΌ сначала для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ числа x Π΅Π³ΠΎ ΠΏΠΎΠ·ΠΈΡ†ΠΈΡŽ posx Π² пСрСстановкС. Π­Ρ‚ΠΎ Π»Π΅Π³ΠΊΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Π·Π° Π»ΠΈΠ½Π΅ΠΉΠ½ΠΎΠ΅ врСмя. Π’Π΅ΠΏΠ΅Ρ€ΡŒ рассмотрим Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ Π²Ρ€Π°ΠΆΠ΄Π΅Π±Π½ΡƒΡŽ ΠΏΠ°Ρ€Ρƒ (a, b) (ΠΌΠΎΠΆΠ½ΠΎ ΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ, ...
output
1
99,880
12
199,761
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,881
12
199,762
Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys # TLE without n, m = map(int, input().split()) pos = [None] * (n + 1) for i, a in enumerate(map(int, input().split())): pos[a] = i z = [300005] * (n + 1) for pr in sys.stdin.read().splitlines(): x, y = map(int, pr.split()) if pos...
output
1
99,881
12
199,763
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,882
12
199,764
Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys # TLE without n, m = map(int, input().split()) pos = [None] * (n + 1) for i, a in enumerate(map(int, input().split())): pos[a] = i z = [300005] * (n + 1) for pr in sys.stdin.read().splitlines(): x, y = map(int, pr.split()) if pos...
output
1
99,882
12
199,765
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,883
12
199,766
Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) index = [0]*(n+1) ng = [-1]*n for i, x in enumerate(a): index[x] = i for x, y in ((map(int, lin...
output
1
99,883
12
199,767
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) that do not contain any foe pairs. So you shouldn'...
instruction
0
99,884
12
199,768
Tags: combinatorics, sortings, two pointers Correct Solution: ``` #!/usr/bin/env python3 from __future__ import division, print_function def solver(): import sys blob = sys.stdin.read().split() it = map(int, blob) n, m = next(it), next(it) revp = [0, ] * (n+1) for i in range(n): revp...
output
1
99,884
12
199,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,885
12
199,770
Yes
output
1
99,885
12
199,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,886
12
199,772
Yes
output
1
99,886
12
199,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,887
12
199,774
Yes
output
1
99,887
12
199,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,888
12
199,776
Yes
output
1
99,888
12
199,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,889
12
199,778
No
output
1
99,889
12
199,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,890
12
199,780
No
output
1
99,890
12
199,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,891
12
199,782
No
output
1
99,891
12
199,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≀ ai, bi ≀ n, ai β‰  bi). Your task is to count the number of different intervals (x, y) (1 ≀ x ≀ y ≀ n) tha...
instruction
0
99,892
12
199,784
No
output
1
99,892
12
199,785
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,925
12
199,850
Tags: data structures, dsu Correct Solution: ``` #!/usr/bin/python3 size = int(input()) num = list(map(int, input().split())) rem = reversed(list(map(lambda x: int(x) - 1, input().split()))) chunks = [None] * size res = [-1] * size ans = [0] * size ms = -1 def addChunk(n): chunks[n] = [n, num[n]] return n def...
output
1
99,925
12
199,851
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,926
12
199,852
Tags: data structures, dsu Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Dec 9 16:14:34 2016 @author: kostiantyn.omelianchuk """ from sys import stdin, stdout lines = stdin.readlines() n = int(lines[0]) a = [int(x) for x in lines[1].split()] b = [int(x) for x in lines[2].s...
output
1
99,926
12
199,853
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,927
12
199,854
Tags: data structures, dsu Correct Solution: ``` import sys MAX = 100005 arr = MAX * [0] pre = MAX * [0] ix = MAX * [0] sun = MAX * [0] ans = MAX * [0] vis = MAX * [False] mx = 0 def find(x): if x == pre[x]: return x pre[x] = find(pre[x]) return pre[x] def unite(x, y): dx = find(x) dy ...
output
1
99,927
12
199,855
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,928
12
199,856
Tags: data structures, dsu Correct Solution: ``` import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n def root(self, x): p = x while not self.par[p]<0: p = self.par[p] while x...
output
1
99,928
12
199,857
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,929
12
199,858
Tags: data structures, dsu Correct Solution: ``` class DSU: def __init__(self, n): self.par = list(range(n)) self.arr = list(map(int, input().split())) self.siz = [1] * n self.sht = [0] * n self.max = 0 def find(self, n): nn = n while nn != self.par[nn]: ...
output
1
99,929
12
199,859
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array ar...
instruction
0
99,930
12
199,860
Tags: data structures, dsu Correct Solution: ``` def main(): n, aa = int(input()), [0, *map(int, input().split()), 0] l, clusters, mx = list(map(int, input().split())), [0] * (n + 2), 0 for i in range(n - 1, -1, -1): a = clusters[a] = l[i] l[i] = mx for i in a - 1, a + 1: ...
output
1
99,930
12
199,861