task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Score : 600 points Problem Statement We have N colored balls arranged in a row from left to right; the color of the i -th ball from the left is c_i . You are given Q queries. The i -th query is as follows: how many different colors do the l_i -th through r_i -th balls from the left have? Constraints 1\leq N,Q \leq 5 \times 10^5 1\leq c_i \leq N 1\leq l_i \leq r_i \leq N All values in input are integers. Input Input is given from Standard Input in the following format: N Q c_1 c_2 \cdots c_N l_1 r_1 l_2 r_2 : l_Q r_Q Output Print Q lines. The i -th line should contain the response to the i -th query. Sample Input 1 4 3 1 2 1 3 1 3 2 4 3 3 Sample Output 1 2 3 1 The 1 -st, 2 -nd, and 3 -rd balls from the left have the colors 1 , 2 , and 1 - two different colors. The 2 -st, 3 -rd, and 4 -th balls from the left have the colors 2 , 1 , and 3 - three different colors. The 3 -rd ball from the left has the color 1 - just one color. Sample Input 2 10 10 2 5 6 5 2 1 7 9 7 2 5 5 2 4 6 7 2 2 7 8 7 9 1 8 6 9 8 10 6 8 Sample Output 2 1 2 2 1 2 2 6 3 3 3
39,239
D: 貪欲が最適? 物語 1 , 5 , 10 , 50 , 100 , 500 円玉がある日本では、ある金額を支払う時、大きい金額の硬貨をできるだけ多く使うという方法で支払うと、硬貨の枚数を最小化できることが知られている。 硬貨の金額が日本とは異なる場合、貪欲に支払うと必ずしも最小化できるとは限らない。 貪欲に支払うのが最適になるために、硬貨の金額が満たすべき条件は何なのだろうか。 問題 TAB 君は上のことが気になったので、まずは硬貨が 1 , A , B の 3 種類しかない場合について考えることにした。 A , B が与えられるので、貪欲に支払った場合枚数が最小にならないような金額のうち、最小のものを出力せよ。 また、どんな金額でも貪欲法が最適な場合は、 -1 を出力せよ。 入力形式 A B 制約 1 < A \leq 10^5 A < B \leq 10^9 入力例 1 4 6 出力例 1 8 8 円を貪欲に支払うと、 6 + 1 \times 2 で支払うことになり、合計 3 枚必要だが、 4 \times 2 で合計 2 枚で支払うことができる。 入力例 2 2 1000000000 出力例 2 -1 どんな金額であっても貪欲に支払うのが最適である。
39,240
Score : 100 points Problem Statement Takahashi loves takoyaki - a ball-shaped snack. With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make. How long does it take to make N takoyaki? Constraints 1 \leq N,X,T \leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: N X T Output Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki. Sample Input 1 20 12 6 Sample Output 1 12 He can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes. Note that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute. Sample Input 2 1000 1 1000 Sample Output 2 1000000 It seems to take a long time to make this kind of takoyaki.
39,241
Problem C: Ball Problem $N$個のボールがあり、各ボールには色と価値が決められている。 ボールの色は$1$から$C$まで$C$種類存在し、各色ごとに選べるボールの数の上限が決められている。 ボールを全体で高々$M$個選ぶとき、得られる価値の合計を最大化せよ。 Input 入力は以下の形式で与えられる。 $N$ $M$ $C$ $l_1$ $l_2$ ... $l_C$ $c_1$ $w_1$ $c_2$ $w_2$ ... $c_N$ $w_N$ 入力はすべて整数で与えられる。 1行目に$N$, $M$, $C$が空白区切りで与えられる。 2行目に色$i$の選べるボールの数の上限$l_i$($1 \leq i \leq C$)が空白区切りで与えられる。 3行目以降の$N$行にボール$i$の色$c_i$と価値$w_i$($1 \leq i \leq N$)が空白区切りで与えられる。 Constraints 入力は以下の条件を満たす。 $1 \leq M \leq N \leq 10^5 $ $1 \leq C \leq 10^5 $ $0 \leq l_i \leq N $ $1 \leq c_i \leq C $ $1 \leq w_i \leq 1000 $ Output 得られる価値の最大値を1行に出力せよ。 Sample Input 1 3 3 2 1 1 1 1 1 100 2 10 Sample Output 1 110 2番目と3番目のボールを選ぶのが最適である。 Sample Input 2 3 3 3 1 0 1 1 1 2 100 3 1 Sample Output 2 2 ある色のボールが一個も選べない場合もある。 Sample Input 3 22 7 26 11 14 15 3 11 7 16 17 1 4 2 19 4 14 16 16 3 13 17 12 7 11 2 20 12 22 6 10 1 3 13 1 16 5 4 1 20 7 18 4 26 6 9 1 12 2 21 1 21 7 18 1 14 5 24 5 6 1 3 1 2 5 21 2 7 6 10 9 15 7 Sample Output 3 52
39,242
Score : 1700 points Problem Statement Snuke has an integer sequence A whose length is N . He likes permutations of (1, 2, ..., N) , P , that satisfy the following condition: P_i \leq A_i for all i ( 1 \leq i \leq N ). Snuke is interested in the inversion numbers of such permutations. Find the sum of the inversion numbers over all permutations that satisfy the condition. Since this can be extremely large, compute the sum modulo 10^9+7 . Notes The inversion number of a sequence Z whose length N is the number of pairs of integers i and j ( 1 \leq i < j \leq N ) such that Z_i > Z_j . Constraints 1 \leq N \leq 2 \times 10^5 1 \leq A_i \leq N ( 1 \leq i \leq N ) All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the sum of the inversion numbers over all permutations that satisfy the condition. Sample Input 1 3 2 3 3 Sample Output 1 4 There are four permutations that satisfy the condition: (1,2,3) , (1,3,2) , (2,1,3) and (2,3,1) . The inversion numbers of these permutations are 0 , 1 , 1 and 2 , respectively, for a total of 4 . Sample Input 2 6 4 2 5 1 6 3 Sample Output 2 7 Only one permutation (4,2,5,1,6,3) satisfies the condition. The inversion number of this permutation is 7 , so the answer is 7 . Sample Input 3 5 4 4 4 4 4 Sample Output 3 0 No permutation satisfies the condition. Sample Input 4 30 22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23 Sample Output 4 848414012
39,243
Score : 900 points Problem Statement Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece. For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly. Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist. Constraints 2 \le N \le 1000 Input Input is given from Standard Input in the following format: N Output If the required domino placement doesn't exist, print a single integer -1 . Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be . (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters. Sample Input 1 6 Sample Output 1 aabb.. b..zz. ba.... .a..aa ..a..b ..a..b The quality of every row and every column is 2. Sample Input 2 2 Sample Output 2 -1
39,244
Problem H: Viva Confetti Do you know confetti ? They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath. A handful of various sized confetti have been dropped on a table. Given their positions and sizes, can you tell us how many of them you can see? The following figure represents the disc configuration for the first sample input, where the bottom disc is still visible. Input The input is composed of a number of configurations of the following form. n x 1 y 1 z 1 x 2 y 2 z 2 . . . x n y n z n The first line in a configuration is the number of discs in the configuration (a positive integer not more than 100), followed by one Ine descriptions of each disc: coordinates of its center and radius, expressed as real numbers in decimal notation, with up to 12 digits after the decimal point. The imprecision margin is ±5 × 10 -13 . That is, it is guaranteed that variations of less than ±5 × 10 -13 on input values do not change which discs are visible. Coordinates of all points contained in discs are between -10 and 10. Confetti are listed in their stacking order, x 1 y 1 r 1 being the bottom one and x n y n r n the top one. You are observing from the top. The end of the input is marked by a zero on a single line. Output For each configuration you should output the number of visible confetti on a single line. Sample Input 3 0 0 0.5 -0.9 0 1.00000000001 0.9 0 1.00000000001 5 0 1 0.5 1 1 1.00000000001 0 2 1.00000000001 -1 1 1.00000000001 0 -0.00001 1.00000000001 5 0 1 0.5 1 1 1.00000000001 0 2 1.00000000001 -1 1 1.00000000001 0 0 1.00000000001 2 0 0 1.0000001 0 0 1 2 0 0 1 0.00000001 0 1 0 Output for the Sample Input 3 5 4 2 2
39,245
Score : 100 points Problem Statement You are given three words s_1 , s_2 and s_3 , each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words. Constraints s_1 , s_2 and s_3 are composed of lowercase English letters. 1 ≤ |s_i| ≤ 10 (1≤i≤3) Input Input is given from Standard Input in the following format: s_1 s_2 s_3 Output Print the answer. Sample Input 1 atcoder beginner contest Sample Output 1 ABC The initial letters of atcoder , beginner and contest are a , b and c . Uppercase and concatenate them to obtain ABC . Sample Input 2 resident register number Sample Output 2 RRN Sample Input 3 k nearest neighbor Sample Output 3 KNN Sample Input 4 async layered coding Sample Output 4 ALC
39,246