Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
10 以上の正整数のうち、十進数表記したときに先頭の桁(最も大きい位)の数字がそれ以外のどの桁の数字よりも真に大きくなるようなものを ヘビ数 とよびます。 例えば、31 や 201 はヘビ数ですが、35 や 202 はヘビ数ではありません。
L 以上 R 以下のヘビ数が何個あるか求めてください。
制約
- 10\leq L \leq R \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
L R
出力
答えを出力せよ。
入力例 1
97 210
出力例 1
6
97 以上 210 以下のヘビ数は、97,98,100,200,201,210 の 6 個です。
入力例 2
1000 9999
出力例 2
2025
入力例 3
252509054433933519 760713016476190692
出力例 3
221852052834757
Score : 350 points
Problem Statement
A positive integer not less than 10 whose top digit (the most significant digit) in decimal representation is strictly larger than every other digit in that number is called a Snake number. For example, 31 and 201 are Snake numbers, but 35 and 202 are not.
Find how many Snake numbers exist between L and R, inclusive.
Constraints
- 10 \leq L \leq R \leq 10^{18}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
L R
Output
Print the answer.
Sample Input 1
97 210
Sample Output 1
6
The Snake numbers between 97 and 210, inclusive, are 97, 98, 100, 200, 201, and 210: there are six.
Sample Input 2
1000 9999
Sample Output 2
2025
Sample Input 3
252509054433933519 760713016476190692
Sample Output 3
221852052834757
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1 から N までの番号がついた N 個のドミノがあります。ドミノ i の大きさは S_i です。
いくつかのドミノを左右一列に並べたあとにドミノを倒すことを考えます。ドミノ i が右に向けて倒れる時、ドミノ i のすぐ右に置かれているドミノの大きさが 2 S_i 以下ならばそのドミノも右に向けて倒れます。
あなたは 2 個以上のドミノを選んで左右一列に並べることにしました。ただし、ドミノの並べ方は次の条件を満たす必要があります。
- 一番左のドミノはドミノ 1 である。
- 一番右のドミノはドミノ N である。
- ドミノ 1 のみを右に向けて倒した時に、最終的にドミノ N も右に向けて倒れる。
条件を満たすドミノの並べ方は存在しますか?また、存在する場合は最小で何個のドミノを並べる必要がありますか?
T 個のテストケースが与えられるので、それぞれについて問題を解いてください。
制約
- 1 \leq T \leq 10^5
- 2 \leq N \leq 2 \times 10^5
- 1 \leq S_i \leq 10^9
- 全てのテストケースに対する N の総和は 2 \times 10^5 以下
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。ここで \mathrm{case}_i は i 番目のテストケースを意味する。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
各テストケースは以下の形式で与えられる。
N S_1 S_2 \dots S_N
出力
T 行出力せよ。i 行目には i 番目のテストケースの答えを出力せよ。
各テストケースでは、条件を満たすドミノの並べ方が存在しない場合は -1 を、存在する場合は並べるドミノの最小個数を出力せよ。
入力例 1
3 4 1 3 2 5 2 1 100 10 298077099 766294630 440423914 59187620 725560241 585990757 965580536 623321126 550925214 917827435
出力例 1
4 -1 3
1 番目のテストケースについて、ドミノを左から順にドミノ 1, ドミノ 3, ドミノ 2, ドミノ 4 の順に並べることで問題文の条件を満たすことができます。特に 3 番目の条件については、ドミノ 1 のみを右に向けて倒した時に以下の順にドミノが倒れます。
- ドミノ 1 の右にはドミノ 3 が置かれている。ドミノ 3 の大きさ S_3 = 2 は S_1 \times 2 = 1 \times 2 = 2 以下であるから、ドミノ 3 も右に向けて倒れる。
- ドミノ 3 の右にはドミノ 2 が置かれている。ドミノ 2 の大きさ S_2 = 3 は S_3 \times 2 = 2 \times 2 = 4 以下であるから、ドミノ 2 も右に向けて倒れる。
- ドミノ 2 の右にはドミノ 4 が置かれている。ドミノ 4 の大きさ S_4 = 5 は S_2 \times 2 = 3 \times 2 = 6 以下であるから、ドミノ 4 も右に向けて倒れる。
3 個以下のドミノを並べて問題文の条件を達成することはできないので、答えは 4 個です。
Score : 300 points
Problem Statement
There are N dominoes numbered from 1 to N. The size of domino i is S_i.
Consider arranging some dominoes in a line from left to right and then toppling them. When domino i falls to the right, if the size of the domino placed immediately to the right of domino i is at most 2 S_i, then that domino also falls to the right.
You decided to choose two or more dominoes and arrange them in a line from left to right. The arrangement of dominoes must satisfy the following conditions:
- The leftmost domino is domino 1.
- The rightmost domino is domino N.
- When only domino 1 is toppled to the right, domino N eventually falls to the right as well.
Does an arrangement of dominoes satisfying the conditions exist? If it exists, what is the minimum number of dominoes that need to be arranged?
You are given T test cases, solve the problem for each of them.
Constraints
- 1 \leq T \leq 10^5
- 2 \leq N \leq 2 \times 10^5
- 1 \leq S_i \leq 10^9
- The sum of N over all test cases is at most 2 \times 10^5.
- All input values are integers.
Input
The input is given from Standard Input in the following format, where \mathrm{case}_i means the i-th test case:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case is given in the following format:
N S_1 S_2 \dots S_N
Output
Output T lines. The i-th line should contain the answer for the i-th test case.
For each test case, if there is no arrangement of dominoes satisfying the conditions, output -1; otherwise, output the minimum number of dominoes to arrange.
Sample Input 1
3 4 1 3 2 5 2 1 100 10 298077099 766294630 440423914 59187620 725560241 585990757 965580536 623321126 550925214 917827435
Sample Output 1
4 -1 3
For the 1st test case, arranging the dominoes from left to right in the order domino 1, domino 3, domino 2, domino 4 satisfies the conditions in the problem statement. Specifically, for the 3rd condition, when only domino 1 is toppled to the right, the dominoes fall in the following order:
- Domino 3 is placed to the right of domino 1. Since the size of domino 3, S_3 = 2, is not greater than S_1 \times 2 = 1 \times 2 = 2, domino 3 also falls to the right.
- Domino 2 is placed to the right of domino 3. Since the size of domino 2, S_2 = 3, is not greater than S_3 \times 2 = 2 \times 2 = 4, domino 2 also falls to the right.
- Domino 4 is placed to the right of domino 2. Since the size of domino 4, S_4 = 5, is not greater than S_2 \times 2 = 3 \times 2 = 6, domino 4 also falls to the right.
It is impossible to achieve the conditions in the problem statement by arranging 3 or fewer dominoes, so the answer is 4.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
正整数 N, M, K が与えられます。ここで、N と M は異なります。
正の整数であって、N と M のうち ちょうど一方のみ で割り切れる数のうち小さい方から K 番目のものを出力してください。
制約
- 1\leq N, M\leq 10^8
- 1\leq K\leq 10^{10}
- N\neq M
- N, M, K は整数
入力
入力は以下の形式で標準入力から与えられる。
N M K
出力
N と M のうちちょうど一方のみで割り切れる正整数のうち小さい方から K 番目のものを出力せよ。
入力例 1
2 3 5
出力例 1
9
2 と 3 のうちちょうど一方のみで割り切れる正整数は小さい方から順に 2,3,4,8,9,10,\ldots です。
ここで、6 は 2 と 3 の両方で割り切れるため条件をみたさないことに注意してください。
条件をみたす正整数のうち小さい方から 5 番目の数は 9 であるため、9 を出力します。
入力例 2
1 2 3
出力例 2
5
条件をみたす数は小さい方から順に 1,3,5,7,\ldots です。
入力例 3
100000000 99999999 10000000000
出力例 3
500000002500000000
Score: 400 points
Problem Statement
You are given three positive integers N, M, and K. Here, N and M are different.
Print the K-th smallest positive integer divisible by exactly one of N and M.
Constraints
- 1 \leq N, M \leq 10^8
- 1 \leq K \leq 10^{10}
- N \neq M
- N, M, and K are integers.
Input
The input is given from Standard Input in the following format:
N M K
Output
Print the K-th smallest positive integer divisible by exactly one of N and M.
Sample Input 1
2 3 5
Sample Output 1
9
The positive integers divisible by exactly one of 2 and 3 are 2, 3, 4, 8, 9, 10, \ldots in ascending order.
Note that 6 is not included because it is divisible by both 2 and 3.
The fifth smallest positive integer that satisfies the condition is 9, so we print 9.
Sample Input 2
1 2 3
Sample Output 2
5
The numbers that satisfy the condition are 1, 3, 5, 7, \ldots in ascending order.
Sample Input 3
100000000 99999999 10000000000
Sample Output 3
500000002500000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
そうめん流しのイベントに N 人の人が集まりました。人は一列に並んでおり、先頭から順に 1 から N の番号がついています。
そうめん流しでは次の出来事が M 回起こります。
- 時刻 T_i に 量 W_i のそうめんを流す。列の先頭にいる人がその全てを得る(誰も列に並んでいない場合は、誰もそのそうめんを得ない)。その人はいったん列から外れ、時刻 T_i+S_i に列の元の位置に戻ってくる。
時刻 X に列に戻ってくる人は、時刻 X には列に並んでいるとみなします。
M 回の出来事が全て行われたあと、それぞれの人が合計でどれだけそうめんを得ることができたか答えてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 <T_1 <\ldots < T_M \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq W_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M T_1 W_1 S_1 \vdots T_M W_M S_M
出力
N 行出力せよ。 i 行目には人 i が得たそうめんの量を出力せよ。
入力例 1
3 5 1 1 3 2 10 100 4 100 10000 10 1000 1000000000 100 1000000000 1
出力例 1
101 10 1000
次のように進行します。
- 時刻 1 に量 1 のそうめんが流される。列には人 1,2,3 が並んでおり、先頭の人 1 がそうめんを得て列から外れる。
- 時刻 2 に量 10 のそうめんが流される。列には人 2,3 が並んでおり、先頭の人 2 がそうめんを得て列から外れる。
- 時刻 4 に人 1 が列に戻ってくる。
- 時刻 4 に量 100 のそうめんが流される。列には人 1,3 が並んでおり、先頭の人 1 がそうめんを得て列から外れる。
- 時刻 10 に量 1000 のそうめんが流される。列には人 3 が並んでおり、先頭の人 3 がそうめんを得て列から外れる。
- 時刻 100 に量 1000000000 のそうめんが流される。列には誰も並んでいないため、誰もこのそうめんを得ない。
- 時刻 102 に人 2 が列に戻ってくる。
- 時刻 10004 に人 1 が列に戻ってくる。
- 時刻 1000000010 に人 3 が列に戻ってくる。
それぞれの人が得たそうめんの量の合計は、101,10,1000 です。
入力例 2
3 1 1 1 1
出力例 2
1 0 0
入力例 3
1 8 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
出力例 3
15
Score : 475 points
Problem Statement
There are N people gathered for an event called Flowing Noodles. The people are lined up in a row, numbered 1 to N in order from front to back.
During the event, the following occurrence happens M times:
- At time T_i, a quantity W_i of noodles is flown down. The person at the front of the row gets all of it (if no one is in the row, no one gets it). That person then steps out of the row and returns to their original position in the row at time T_i+S_i.
A person who returns to the row at time X is considered to be in the row at time X.
After all the M occurrences, report the total amount of noodles each person has got.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 <T_1 <\ldots < T_M \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq W_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M T_1 W_1 S_1 \vdots T_M W_M S_M
Output
Print N lines. The i-th line should contain the amount of noodles person i has got.
Sample Input 1
3 5 1 1 3 2 10 100 4 100 10000 10 1000 1000000000 100 1000000000 1
Sample Output 1
101 10 1000
The event proceeds as follows:
- At time 1, a quantity 1 of noodles is flown down. People 1, 2, and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 2, a quantity 10 of noodles is flown down. People 2 and 3 are in the row, and the person at the front, person 2, gets the noodles and steps out of the row.
- At time 4, person 1 returns to the row.
- At time 4, a quantity 100 of noodles is flown down. People 1 and 3 are in the row, and the person at the front, person 1, gets the noodles and steps out of the row.
- At time 10, a quantity 1000 of noodles is flown down. Only person 3 is in the row, and the person at the front, person 3, gets the noodles and steps out of the row.
- At time 100, a quantity 1000000000 of noodles is flown down. No one is in the row, so no one gets these noodles.
- At time 102, person 2 returns to the row.
- At time 10004, person 1 returns to the row.
- At time 1000000010, person 3 returns to the row.
The total amounts of noodles people 1, 2, and 3 have got are 101, 10, and 1000, respectively.
Sample Input 2
3 1 1 1 1
Sample Output 2
1 0 0
Sample Input 3
1 8 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
Sample Output 3
15
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N) が与えられます。
Q 個のクエリが与えられるので、与えられた順に処理してください。各クエリは以下の 2 種類のいずれかです。
- タイプ 1 :
1 p xの形式で与えられる。 A_p の値を x に変更する。 - タイプ 2 :
2 l rの形式で与えられる。 (A_l, A_{l+1}, \ldots, A_r) において 2 番目に大きい値の個数を出力する。より厳密には、l \leq i \leq r を満たす整数 i であって、A_l, A_{l+1}, \ldots, A_r のうち A_i より大きい値がちょうど 1 種類であるものの個数を出力する。
制約
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- タイプ 1 のクエリにおいて、1 \leq p \leq N
- タイプ 1 のクエリにおいて、1 \leq x \leq 10^9
- タイプ 2 のクエリにおいて、1 \leq l \leq r \leq N
- タイプ 2 のクエリが 1 つ以上存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
A_1 A_2 \ldots A_N
\text{query}_{1}
\vdots
\text{query}_{Q}
ただし、\text{query}_{i} は i 個目のクエリであり、以下のいずれかの形式で与えられる。
1 p x
2 l r
出力
タイプ 2 のクエリの個数を q として、q 行出力せよ。 i 行目には i 個目のタイプ 2 のクエリに対する答えを出力せよ。
入力例 1
5 4 3 3 1 4 5 2 1 3 2 5 5 1 3 3 2 2 4
出力例 1
1 0 2
はじめ、A = (3, 3, 1, 4, 5) です。
1 個目のクエリでは、(3, 3, 1) において 2 番目に大きい値は 1 であり、3, 3, 1 の中に 1 は 1 個あるので 1 を出力します。
2 個目のクエリでは、(5) において 2 番目に大きい値は存在しないので 0 を出力します。
3 個目のクエリでは、A = (3, 3, 3, 4, 5) となります。
4 個目のクエリでは、(3, 3, 4) において 2 番目に大きい値は 3 であり、3, 3, 4 の中に 3 は 2 個あるので 2 を出力します。
入力例 2
1 1 1000000000 2 1 1
出力例 2
0
入力例 3
8 9 2 4 4 3 9 1 1 2 1 5 4 2 7 7 2 2 6 1 4 4 2 2 5 2 2 7 1 1 1 1 8 1 2 1 8
出力例 3
0 1 0 2 4
Score: 525 points
Problem Statement
You are given a sequence A = (A_1, A_2, \ldots, A_N) of length N.
Process Q queries in the order they are given. Each query is of one of the following two types:
- Type 1: Given in the form
1 p x. Change the value of A_p to x. - Type 2: Given in the form
2 l r. print the number of occurrences of the second largest value in (A_l, A_{l+1}, \ldots, A_r). More precisely, print the number of integers i satisfying l \leq i \leq r such that there is exactly one distinct value greater than A_i among A_l, A_{l+1}, \ldots, A_r.
Constraints
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- For type-1 queries, 1 \leq p \leq N.
- For type-1 queries, 1 \leq x \leq 10^9.
- For type-2 queries, 1 \leq l \leq r \leq N.
- There is at least one type-2 query.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
A_1 A_2 \ldots A_N
\text{query}_{1}
\vdots
\text{query}_{Q}
Here, \text{query}_{i} is the i-th query and given in one of the following formats:
1 p x
2 l r
Output
Let q be the number of type-2 queries. Print q lines. The i-th line should contain the response to the i-th type-2 query.
Sample Input 1
5 4 3 3 1 4 5 2 1 3 2 5 5 1 3 3 2 2 4
Sample Output 1
1 0 2
Initially, A = (3, 3, 1, 4, 5).
For the first query, the second largest value in (3, 3, 1) is 1, which appears once in 3, 3, 1, so print 1.
For the second query, there is no second largest value in (5), so print 0.
The third query makes A = (3, 3, 3, 4, 5).
For the fourth query, the second largest value in (3, 3, 4), is 3, which appears twice in 3, 3, 4, so print 2.
Sample Input 2
1 1 1000000000 2 1 1
Sample Output 2
0
Sample Input 3
8 9 2 4 4 3 9 1 1 2 1 5 4 2 7 7 2 2 6 1 4 4 2 2 5 2 2 7 1 1 1 1 8 1 2 1 8
Sample Output 3
0 1 0 2 4