Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22
のような指数表記や、 0523
のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22
, for example, or unnecessary leading zeros such as 0523
are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字、,
、"
からなる長さ N の文字列 S が与えられます。S に含まれる "
の個数は偶数であることが保証されています。
S に含まれる "
の個数を 2K 個とすると、各 i=1,2,\ldots,K について 2i-1 番目の "
から 2i 番目の "
までの文字のことを 括られた文字 と呼びます。
あなたの仕事は、 S に含まれる ,
のうち、括られた文字 でないもの を .
で置き換えて得られる文字列を答えることです。
制約
- N は 1 以上 2\times 10^5 以下の整数
- S は英小文字、
,
、"
からなる長さ N の文字列 - S に含まれる
"
の個数は偶数
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
8 "a,b"c,d
出力例 1
"a,b"c.d
S のうち "a,b"
が括られた文字であり、c,d
は括られた文字ではありません。
S に含まれる ,
のうち、括られた文字でないのは S の左から 7 番目の文字なので、7 番目の文字を .
で置き換えたものが答えとなります。
入力例 2
5 ,,,,,
出力例 2
.....
入力例 3
20 a,"t,"c,"o,"d,"e,"r,
出力例 3
a."t,"c."o,"d."e,"r.
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters, ,
, and "
. It is guaranteed that S contains an even number of "
.
Let 2K be the number of "
in S. For each i=1,2,\ldots,K, the characters from the (2i-1)-th "
through the (2i)-th "
are said to be enclosed.
Your task is to replace each ,
in S that is not an enclosed character with .
and print the resulting string.
Constraints
- N is an integer between 1 and 2\times 10^5, inclusive.
- S is a string of length N consisting of lowercase English letters,
,
, and"
. - S contains an even number of
"
.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
8 "a,b"c,d
Sample Output 1
"a,b"c.d
In S, "a,b"
are enclosed characters, and c,d
are not.
The ,
in S that is not an enclosed character is the seventh character from the left in S, so replace that character with .
to get the answer.
Sample Input 2
5 ,,,,,
Sample Output 2
.....
Sample Input 3
20 a,"t,"c,"o,"d,"e,"r,
Sample Output 3
a."t,"c."o,"d."e,"r.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
英大文字および英小文字からなる長さ N の文字列 S が与えられます。
これから、文字列 S に対して Q 回の操作を行います。 i 番目 (1\leq i\leq Q) の操作は整数 2 つと文字 1 つからなる組 (t _ i,x _ i,c _ i) で表され、それぞれ次のような操作を表します。
- t _ i=1 のとき、S の x _ i 文字目を c _ i に変更する。
- t _ i=2 のとき、S に含まれる大文字すべてをそれぞれ小文字に変更する(x _ i,c _ i は操作に使用しない)。
- t _ i=3 のとき、S に含まれる小文字すべてをそれぞれ大文字に変更する(x _ i,c _ i は操作に使用しない)。
Q 回の操作がすべて終わったあとの S を出力してください。
制約
- 1\leq N\leq5\times10^5
- S は英大文字および英小文字からなる長さ N の文字列
- 1\leq Q\leq5\times10^5
- 1\leq t _ i\leq3\ (1\leq i\leq Q)
- t _ i=1 ならば 1\leq x _ i\leq N\ (1\leq i\leq Q)
- c _ i は英大文字もしくは英小文字
- t _ i\neq 1 ならば x _ i=0 かつ c _ i=
'a'
- N,Q,t _ i,x _ i はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S Q t _ 1 x _ 1 c _ 1 t _ 2 x _ 2 c _ 2 \vdots t _ Q x _ Q c _ Q
出力
答えを 1 行で出力せよ。
入力例 1
7 AtCoder 5 1 4 i 3 0 a 1 5 b 2 0 a 1 4 Y
出力例 1
atcYber
はじめ、文字列 S は AtCoder
です。
- 1 番目の操作では、4 文字目を
i
に変更します。変更後の S はAtCider
です。 - 2 番目の操作では、すべての小文字を大文字に変更します。変更後の S は
ATCIDER
です。 - 3 番目の操作では、5 文字目を
b
に変更します。変更後の S はATCIbER
です。 - 4 番目の操作では、すべての大文字を小文字に変更します。変更後の S は
atciber
です。 - 5 番目の操作では、4 文字目を
Y
に変更します。変更後の S はatcYber
です。
すべての操作が終わったあとの S は atcYber
なので、atcYber
と出力してください。
入力例 2
35 TheQuickBrownFoxJumpsOverTheLazyDog 10 2 0 a 1 19 G 1 13 m 1 2 E 1 21 F 2 0 a 1 27 b 3 0 a 3 0 a 1 15 i
出力例 2
TEEQUICKBROWMFiXJUGPFOVERTBELAZYDOG
Score : 400 points
Problem Statement
You are given a string S of length N consisting of uppercase and lowercase English letters.
Let us perform Q operations on the string S. The i-th operation (1\leq i\leq Q) is represented by a tuple (t _ i,x _ i,c _ i) of two integers and one character, as follows.
- If t _ i=1, change the x _ i-th character of S to c _ i.
- If t _ i=2, convert all uppercase letters in S to lowercase (do not use x _ i,c _ i for this operation).
- If t _ i=3, convert all lowercase letters in S to uppercase (do not use x _ i,c _ i for this operation).
Print the S after the Q operations.
Constraints
- 1\leq N\leq5\times10^5
- S is a string of length N consisting of uppercase and lowercase English letters.
- 1\leq Q\leq5\times10^5
- 1\leq t _ i\leq3\ (1\leq i\leq Q)
- If t _ i=1, then 1\leq x _ i\leq N\ (1\leq i\leq Q).
- c _ i is an uppercase or lowercase English letter.
- If t _ i\neq 1, then x _ i=0 and c _ i=
'a'
. - N,Q,t _ i,x _ i are all integers.
Input
The input is given from Standard Input in the following format:
N S Q t _ 1 x _ 1 c _ 1 t _ 2 x _ 2 c _ 2 \vdots t _ Q x _ Q c _ Q
Output
Print the answer in a single line.
Sample Input 1
7 AtCoder 5 1 4 i 3 0 a 1 5 b 2 0 a 1 4 Y
Sample Output 1
atcYber
Initially, the string S is AtCoder
.
- The first operation changes the 4-th character to
i
, changing S toAtCider
. - The second operation converts all lowercase letters to uppercase, changing S to
ATCIDER
. - The third operation changes the 5-th character to
b
, changing S toATCIbER
. - The fourth operation converts all uppercase letters to lowercase, changing S to
atciber
. - The fifth operation changes the 4-th character to
Y
, changing S toatcYber
.
After the operations, the string S is atcYber
, so print atcYber
.
Sample Input 2
35 TheQuickBrownFoxJumpsOverTheLazyDog 10 2 0 a 1 19 G 1 13 m 1 2 E 1 21 F 2 0 a 1 27 b 3 0 a 3 0 a 1 15 i
Sample Output 2
TEEQUICKBROWMFiXJUGPFOVERTBELAZYDOG
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の整数列 A = (a_1,\ldots,a_N) と B = (b_1,\ldots,b_N) が与えられます。
i=1,...,Q に対し、次の形式のクエリに答えてください。
- A の先頭 x_i 項 (a_1,\ldots,a_{x_i}) に含まれる値の集合と B の先頭 y_i 項 (b_1,\ldots,b_{y_i}) に含まれる値の集合が等しいならば
Yes
と、そうでなければNo
と出力せよ。
制約
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq a_i,b_i \leq 10^9
- 1 \leq x_i,y_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N b_1 \ldots b_N Q x_1 y_1 \vdots x_Q y_Q
出力
Q 行出力せよ。 i 行目には、i 番目のクエリに対する出力をせよ。
入力例 1
5 1 2 3 4 5 1 2 2 4 3 7 1 1 2 2 2 3 3 3 4 4 4 5 5 5
出力例 1
Yes Yes Yes No No Yes No
集合は各値が含まれるかどうかのみに注目した概念であることに気を付けてください。
3 番目のクエリにおいて、A の先頭 2 項には 1 と 2 が 1 個ずつ、B の先頭 3 項には 1 が 1 個と 2 が 2 個含まれます。しかし、それぞれに含まれる値の集合はどちらも \{ 1,2 \} となり、一致します。
また、6 番目のクエリにおいては各値が現れる順番が異なりますが、やはり集合としては一致します。
Score : 500 points
Problem Statement
You are given integer sequences A = (a_1,\ldots,a_N) and B = (b_1,\ldots,b_N), each of length N.
For i=1,...,Q, answer the query in the following format.
- If the set of values contained in the first x_i terms of A, (a_1,\ldots,a_{x_i}), and the set of values contained in the first y_i terms of B, (b_1,\ldots,b_{y_i}), are equal, then print
Yes
; otherwise, printNo
.
Constraints
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq a_i,b_i \leq 10^9
- 1 \leq x_i,y_i \leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 \ldots a_N b_1 \ldots b_N Q x_1 y_1 \vdots x_Q y_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query.
Sample Input 1
5 1 2 3 4 5 1 2 2 4 3 7 1 1 2 2 2 3 3 3 4 4 4 5 5 5
Sample Output 1
Yes Yes Yes No No Yes No
Note that sets are a concept where it matters only whether each value is contained or not.
For the 3-rd query, the first 2 terms of A contain one 1 and one 2, while the first 3 terms of B contain one 1 and two 2's. However, the sets of values contained in the segments are both \{ 1,2 \}, which are equal.
Also, for the 6-th query, the values appear in different orders, but they are still equal as sets.
Time Limit: 6 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 次元空間上の 2 点 x=(x_1, x_2, \dots, x_N), y = (y_1, y_2, \dots, y_N) のマンハッタン距離 d(x,y) は次の式で定義されます。
また、座標成分 x_1, x_2, \dots, x_N がすべて整数であるような点 x=(x_1, x_2, \dots, x_N) を格子点と呼びます。
N 次元空間上の格子点 p=(p_1, p_2, \dots, p_N), q = (q_1, q_2, \dots, q_N) が与えられます。
d(p,r) \leq D かつ d(q,r) \leq D であるような格子点 r としてあり得るものは全部で何個ありますか?答えを 998244353 で割ったあまりを求めてください。
制約
- 1 \leq N \leq 100
- 0 \leq D \leq 1000
- -1000 \leq p_i, q_i \leq 1000
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D p_1 p_2 \dots p_N q_1 q_2 \dots q_N
出力
答えを出力せよ。
入力例 1
1 5 0 3
出力例 1
8
N=1 の場合は 1 次元空間、すなわち数直線上の点に関する問題になります。
条件を満たす点は -2,-1,0,1,2,3,4,5 の 8 個です。
入力例 2
3 10 2 6 5 2 1 2
出力例 2
632
入力例 3
10 100 3 1 4 1 5 9 2 6 5 3 2 7 1 8 2 8 1 8 2 8
出力例 3
145428186
Score : 500 points
Problem Statement
In an N-dimensional space, the Manhattan distance d(x,y) between two points x=(x_1, x_2, \dots, x_N) and y = (y_1, y_2, \dots, y_N) is defined by:
A point x=(x_1, x_2, \dots, x_N) is said to be a lattice point if the components x_1, x_2, \dots, x_N are all integers.
You are given lattice points p=(p_1, p_2, \dots, p_N) and q = (q_1, q_2, \dots, q_N) in an N-dimensional space.
How many lattice points r satisfy d(p,r) \leq D and d(q,r) \leq D? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 100
- 0 \leq D \leq 1000
- -1000 \leq p_i, q_i \leq 1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N D p_1 p_2 \dots p_N q_1 q_2 \dots q_N
Output
Print the answer.
Sample Input 1
1 5 0 3
Sample Output 1
8
When N=1, we consider points in a one-dimensional space, that is, on a number line.
8 lattice points satisfy the conditions: -2,-1,0,1,2,3,4,5.
Sample Input 2
3 10 2 6 5 2 1 2
Sample Output 2
632
Sample Input 3
10 100 3 1 4 1 5 9 2 6 5 3 2 7 1 8 2 8 1 8 2 8
Sample Output 3
145428186