実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
AtCoder 国の暦では、1 年は 1 月から M 月までの M ヶ月からなり、どの月も 1 日から D 日までの D 日からなります。
AtCoder 国の暦で y 年 m 月 d 日の翌日は何年何月何日であるか求めてください。
制約
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
M D y m d
出力
AtCoder 国の暦で y 年 m 月 d 日の翌日が y' 年 m' 月 d' 日であるとき、y',m',d' をこの順に空白区切りで出力せよ。
入力例 1
12 30 2023 12 30
出力例 1
2024 1 1
AtCoder 国の暦では 1 年は 12 ヶ月であり、どの月も 30 日からなります。 よって、2023 年 12 月 30 日の翌日は 2024 年 1 月 1 日になります。
入力例 2
36 72 6789 23 45
出力例 2
6789 23 46
AtCoder 国の暦では 1 年は 36 ヶ月であり、どの月も 72 日からなります。 よって、6789 年 23 月 45 日の翌日は 6789 年 23 月 46 日になります。
入力例 3
12 30 2012 6 20
出力例 3
2012 6 21
Score : 100 points
Problem Statement
In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.
What day follows year y, month m, day d in this calendar?
Constraints
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- All input values are integers.
Input
The input is given from Standard Input in the following format:
M D y m d
Output
If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.
Sample Input 1
12 30 2023 12 30
Sample Output 1
2024 1 1
In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days. Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.
Sample Input 2
36 72 6789 23 45
Sample Output 2
6789 23 46
In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days. Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.
Sample Input 3
12 30 2012 6 20
Sample Output 3
2012 6 21
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
横一列に 4 つのマスが並んでいます。
各文字が 0 または 1 である長さ 4 の文字列 S が与えられます。
S の i 文字目が 1 であるとき、左から i 番目のマスには 1 人の人がおり、
S の i 文字目が 0 であるとき、左から i 番目のマスには人がいません。
全ての人が一斉に、1 つ右隣のマスへ移動します。この移動により、もともと右端のマスにいた人は消えます。
移動後の各マスに人がいるかどうかを、S と同様のルールで文字列として出力してください。
制約
- S は
0,1のみからなる長さ 4 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
長さ 4 の文字列であって、移動後、左から i 番目のマスに人がいるならば i 文字目が 1、いないならば 0 であるようなものを出力せよ。
入力例 1
1011
出力例 1
0101
移動により、左から 1 番目のマスにいた人は左から 2 番目のマスに、
左から 3 番目のマスにいた人は左から 4 番目のマスに移動し、
左から 4 番目のマス(右端のマス)にいた人は消えます。
入力例 2
0000
出力例 2
0000
入力例 3
1111
出力例 3
0111
Score : 100 points
Problem Statement
There are 4 squares lined up horizontally.
You are given a string S of length 4 consisting of 0 and 1.
If the i-th character of S is 1, there is a person in the i-th square from the left;
if the i-th character of S is 0, there is no person in the i-th square from the left.
Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.
Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)
Constraints
- S is a string of length 4 consisting of
0and1.
Input
Input is given from Standard Input in the following format:
S
Output
Print a string of length 4 such that the i-th character is 1 if there will be a person in the i-th square from the left after the move, and 0 otherwise.
Sample Input 1
1011
Sample Output 1
0101
After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.
Sample Input 2
0000
Sample Output 2
0000
Sample Input 3
1111
Sample Output 3
0111
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。
- N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?
制約
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T
\text{test}_1
\text{test}_2
\vdots
\text{test}_T
各テストケースは以下の形式で与えられる。
N A_1 A_2 \dots A_N
出力
T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。
入力例 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
出力例 1
2 1 5 0
この入力は 4 個のテストケースが含まれています。
入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。
Score : 200 points
Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.
- We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?
Constraints
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T
\text{test}_1
\text{test}_2
\vdots
\text{test}_T
Each test case is in the following format:
N A_1 A_2 \dots A_N
Output
Print T lines. The i-th line should contain the answer for the i-th test case.
Sample Input 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
Sample Output 1
2 1 5 0
This input contains four test cases.
The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
縦 A 行、横 B 列のマスからなるタイルを縦 N 行、横 N 列に並べてできた、縦 (A\times N) 行、横 (B\times N) 列のマス目 X があります。
1\leq i,j \leq N について、上から i 行目、左から j 列目のタイルをタイル (i,j) とします。
X の各マスは以下のように塗られています。
- 各タイルは白いタイルまたは黒いタイルである。
- 白いタイルのすべてのマスは白で塗られ、黒いタイルのすべてのマスは黒で塗られている。
- タイル (1,1) は白いタイルである。
- 辺で隣接する 2 つのタイルは異なる色のタイルである。ただし、タイル (a,b) とタイル (c,d) が辺で隣接するとは、|a-c|+|b-d|=1 ( |x| を x の絶対値とする)であることを言う。
マス目 X を出力の形式に従って出力してください。
制約
- 1 \leq N,A,B \leq 10
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A B
出力
次の条件をみたす (A\times N) 個の文字列 S_1,\ldots,S_{A\times N} を改行区切りで出力せよ。
- S_1,\ldots,S_{A\times N} はそれぞれ長さ (B\times N) の
.または#からなる文字列である。 - 各 i,j (1 \leq i \leq A\times N,1 \leq j \leq B\times N) に対し、マス目 X の上から i 行目かつ左から j 列目のマスが白で塗られているならば S_i の j 文字目は
.であり、黒く塗られているならば#である。
入力例 1
4 3 2
出力例 1
..##..## ..##..## ..##..## ##..##.. ##..##.. ##..##.. ..##..## ..##..## ..##..## ##..##.. ##..##.. ##..##..
入力例 2
5 1 5
出力例 2
.....#####.....#####..... #####.....#####.....##### .....#####.....#####..... #####.....#####.....##### .....#####.....#####.....
入力例 3
4 4 1
出力例 3
.#.# .#.# .#.# .#.# #.#. #.#. #.#. #.#. .#.# .#.# .#.# .#.# #.#. #.#. #.#. #.#.
入力例 4
1 4 4
出力例 4
.... .... .... ....
Score : 200 points
Problem Statement
Tiles are aligned in N horizontal rows and N vertical columns. Each tile has a grid with A horizontal rows and B vertical columns. On the whole, the tiles form a grid X with (A\times N) horizontal rows and (B\times N) vertical columns.
For 1\leq i,j \leq N, Tile (i,j) denotes the tile at the i-th row from the top and the j-th column from the left.
Each square of X is painted as follows.
- Each tile is either a white tile or a black tile.
- Every square in a white tile is painted white; every square in a black tile is painted black.
- Tile (1,1) is a white tile.
- Two tiles sharing a side have different colors. Here, Tile (a,b) and Tile (c,d) are said to be sharing a side if and only if |a-c|+|b-d|=1 (where |x| denotes the absolute value of x).
Print the grid X in the format specified in the Output section.
Constraints
- 1 \leq N,A,B \leq 10
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print (A\times N) strings S_1,\ldots,S_{A\times N} that satisfy the following condition, with newlines in between.
- Each of S_1,\ldots,S_{A\times N} is a string of length (B\times N) consisting of
.and#. - For each i and j (1 \leq i \leq A\times N,1 \leq j \leq B\times N), the j-th character of S_i is
.if the square at the i-th row from the top and j-th column from the left in grid X is painted white; the character is#if the square is painted black.
Sample Input 1
4 3 2
Sample Output 1
..##..## ..##..## ..##..## ##..##.. ##..##.. ##..##.. ..##..## ..##..## ..##..## ##..##.. ##..##.. ##..##..
Sample Input 2
5 1 5
Sample Output 2
.....#####.....#####..... #####.....#####.....##### .....#####.....#####..... #####.....#####.....##### .....#####.....#####.....
Sample Input 3
4 4 1
Sample Output 3
.#.# .#.# .#.# .#.# #.#. #.#. #.#. #.#. .#.# .#.# .#.# .#.# #.#. #.#. #.#. #.#.
Sample Input 4
1 4 4
Sample Output 4
.... .... .... ....
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる 2 つの文字列 S, T が与えられます。 次の操作を好きな回数( 0 回でも良い)行うことで、S を T と一致させることができるかを判定してください。
S において同じ文字が 2 文字連続しているところの間に、その文字と同じ文字を 1 つ挿入する。 すなわち、下記の 3 つの手順からなる操作を行う。
- 現在の S の長さを N とし、S = S_1S_2\ldots S_N とする。
- 1 以上 N-1 以下の整数 i であって、S_i = S_{i+1} を満たすものを 1 つ選択する。(ただし、そのような i が存在しない場合は、何もせずに手順 3.をスキップして操作を終了する。)
- S の i 文字目と i+1 文字目の間に文字 S_i(= S_{i+1}) を 1 つ挿入する。その結果、S は長さ N+1 の文字列 S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N となる。
制約
- S と T はそれぞれ英小文字からなる長さ 2 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S を T と一致させることができる場合は Yes を、そうでない場合は No を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
abbaac abbbbaaac
出力例 1
Yes
下記の 3 回の操作によって、S = abbaac を T = abbbbaaac に一致させることができます。
- まず、S の 2 文字目と 3 文字目の間に
bを挿入する。その結果、S =abbbaacとなる。 - 次に、再び S の 2 文字目と 3 文字目の間に
bを挿入する。その結果、S =abbbbaacとなる。 - 最後に、S の 6 文字目と 7 文字目の間に
aを挿入する。その結果、S =abbbbaaacとなる。
よって、Yes を出力します。
入力例 2
xyzz xyyzz
出力例 2
No
どのように操作を行っても、 S = xyzz を T = xyyzz に一致させることはできません。
よって、No を出力します。
Score : 300 points
Problem Statement
You are given two strings S and T. Determine whether it is possible to make S equal T by performing the following operation some number of times (possibly zero).
Between two consecutive equal characters in S, insert a character equal to these characters. That is, take the following three steps.
- Let N be the current length of S, and S = S_1S_2\ldots S_N.
- Choose an integer i between 1 and N-1 (inclusive) such that S_i = S_{i+1}. (If there is no such i, do nothing and terminate the operation now, skipping step 3.)
- Insert a single copy of the character S_i(= S_{i+1}) between the i-th and (i+1)-th characters of S. Now, S is a string of length N+1: S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N.
Constraints
- Each of S and T is a string of length between 2 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S T
Output
If it is possible to make S equal T, print Yes; otherwise, print No.
Note that the judge is case-sensitive.
Sample Input 1
abbaac abbbbaaac
Sample Output 1
Yes
You can make S = abbaac equal T = abbbbaaac by the following three operations.
- First, insert
bbetween the 2-nd and 3-rd characters of S. Now, S =abbbaac. - Next, insert
bagain between the 2-nd and 3-rd characters of S. Now, S =abbbbaac. - Lastly, insert
abetween the 6-th and 7-th characters of S. Now, S =abbbbaaac.
Thus, Yes should be printed.
Sample Input 2
xyzz xyyzz
Sample Output 2
No
No sequence of operations makes S = xyzz equal T = xyyzz.
Thus, No should be printed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の狭義単調増加列 A=(A _ 1,A _ 2,\ldots,A _ N) と、長さ M の狭義単調増加列 B=(B _ 1,B _ 2,\ldots,B _ M) が与えられます。 ここで、すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j が成り立っています。
長さ N+M の狭義単調増加列 C=(C _ 1,C _ 2,\ldots,C _ {N+M}) を、次の操作を行った結果得られる列として定めます。
- C を A と B を連結した列とする。厳密には、i=1,2,\ldots,N について C _ i=A _ i とし、i=N+1,N+2,\ldots,N+M について C _ i=B _ {i-N} とする。
- C を昇順にソートする。
A _ 1,A _ 2,\ldots,A _ N と B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるか求めてください。 より厳密には、まず i=1,2,\ldots,N について C _ k=A _ i を満たす k を順に求めたのち、j=1,2,\ldots,M について C _ k=B _ j を満たす k を順に求めてください。
制約
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
出力
答えを 2 行で出力せよ。
1 行目には A _ 1,A _ 2,\ldots,A _ N がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
2 行目には B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
入力例 1
4 3 3 14 15 92 6 53 58
出力例 1
1 3 4 7 2 5 6
C は (3,6,14,15,53,58,92) となります。 A=(3,14,15,92) の要素はそれぞれ 1,3,4,7 番目にあり、B=(6,53,58) の要素はそれぞれ 2,5,6 番目にあります。
入力例 2
4 4 1 2 3 4 100 200 300 400
出力例 2
1 2 3 4 5 6 7 8
入力例 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
出力例 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
Score : 300 points
Problem Statement
You are given strictly increasing sequences of length N and M: A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B _ 1,B _ 2,\ldots,B _ M). Here, A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
Let C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+M that results from the following procedure.
- Let C be the concatenation of A and B. Formally, let C _ i=A _ i for i=1,2,\ldots,N, and C _ i=B _ {i-N} for i=N+1,N+2,\ldots,N+M.
- Sort C in ascending order.
For each of A _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M, find its position in C. More formally, for each i=1,2,\ldots,N, find k such that C _ k=A _ i, and for each j=1,2,\ldots,M, find k such that C _ k=B _ j.
Constraints
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
Output
Print the answer in two lines.
The first line should contain the positions of A _ 1,A _ 2,\ldots,A _ N in C, with spaces in between.
The second line should contain the positions of B _ 1,B _ 2,\ldots,B _ M in C, with spaces in between.
Sample Input 1
4 3 3 14 15 92 6 53 58
Sample Output 1
1 3 4 7 2 5 6
C will be (3,6,14,15,53,58,92). Here, the 1-st, 3-rd, 4-th, 7-th elements are from A=(3,14,15,92), and the 2-nd, 5-th, 6-th elements are from B=(6,53,58).
Sample Input 2
4 4 1 2 3 4 100 200 300 400
Sample Output 2
1 2 3 4 5 6 7 8
Sample Input 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
Sample Output 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
以下の条件を満たす整数 k を「 250 に似た数」と呼びます。
- k が素数 p<q を使って k=p \times q^3 と表される。
N 以下の「 250 に似た数」は全部でいくつありますか?
制約
- N は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
250
出力例 1
2
- 54 = 2 \times 3^3 なので、「 250 に似た数」です。
- 250 = 2 \times 5^3 なので、「 250 に似た数」です。
250 以下の「 250 に似た数」は、以上の 2 つです。
入力例 2
1
出力例 2
0
入力例 3
123456789012345
出力例 3
226863
Score : 400 points
Problem Statement
Let us regard an integer k as "similar to 250" if the following condition is satisfied:
- k is represented as k=p \times q^3 with primes p<q.
How many integers less than or equal to N are "similar to 250"?
Constraints
- N is an integer between 1 and 10^{18} (inclusive)
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
250
Sample Output 1
2
- 54 = 2 \times 3^3 is "similar to 250".
- 250 = 2 \times 5^3 is "similar to 250".
The two integers above are all the integers "similar to 250".
Sample Input 2
1
Sample Output 2
0
Sample Input 3
123456789012345
Sample Output 3
226863
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
変数 X と、X の値を変更する N 種類の操作があります。操作 i は整数の組 (T_i,A_i) で表され、意味は次の通りです。
- T_i=1 のとき、X の値を X\ {\rm and}\ A_i に置き換える。
- T_i=2 のとき、X の値を X\ {\rm or}\ A_i に置き換える。
- T_i=3 のとき、X の値を X\ {\rm xor}\ A_i に置き換える。
変数 X を値 C で初期化した状態から、以下の処理を順に実行してください。
- 操作 1 を行い、操作後の X の値を出力する。
- 続けて、操作 1,2 を順に行い、操作後の X の値を出力する。
- 続けて、操作 1,2,3 を順に行い、操作後の X の値を出力する。
- \vdots
- 続けて、操作 1,2,\ldots,N を順に行い、操作後の X の値を出力する。
{\rm and}, {\rm or}, {\rm xor} とは
非負整数 A, B の {\rm and}, {\rm or}, {\rm xor} は、以下のように定義されます。- A\ {\rm and}\ B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1、そうでなければ 0 である。
- A\ {\rm or}\ B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち少なくとも一方が 1 であれば 1、そうでなければ 0 である。
- A\ {\rm xor}\ B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうちちょうど一方が 1 であれば 1、そうでなければ 0 である。
制約
- 1 \leq N \leq 2\times 10^5
- 1\leq T_i \leq 3
- 0\leq A_i \lt 2^{30}
- 0\leq C \lt 2^{30}
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N C T_1 A_1 T_2 A_2 \vdots T_N A_N
出力
問題文中の指示に従って N 行出力せよ。
入力例 1
3 10 3 3 2 5 1 12
出力例 1
9 15 12
最初、X の値は 10 です。
- 操作 1 を行うと X の値は 9 になります。
- 続けて操作 1 を行うと X の値は 10 になり、さらに操作 2 を行うと 15 になります。
- 続けて操作 1 を行うと X の値は 12 になり、さらに操作 2 を行うと 13 に、さらに続けて操作 3 を行うと 12 になります。
入力例 2
9 12 1 1 2 2 3 3 1 4 2 5 3 6 1 7 2 8 3 9
出力例 2
0 2 1 0 5 3 3 11 2
Score : 500 points
Problem Statement
We have a variable X and N kinds of operations that change the value of X. Operation i is represented as a pair of integers (T_i,A_i), and is the following operation:
- if T_i=1, it replaces the value of X with X\ {\rm and}\ A_i;
- if T_i=2, it replaces the value of X with X\ {\rm or}\ A_i;
- if T_i=3, it replaces the value of X with X\ {\rm xor}\ A_i.
Initialize X with the value of C and execute the following procedures in order:
- Perform Operation 1, and then print the resulting value of X.
- Next, perform Operation 1, 2 in this order, and then print the value of X.
- Next, perform Operation 1, 2, 3 in this order, and then print the value of X.
- \vdots
- Next, perform Operation 1, 2, \ldots, N in this order, and then print the value of X.
What are {\rm and}, {\rm or}, {\rm xor}?
The {\rm and}, {\rm or}, {\rm xor} of non-negative integers A and B are defined as follows:
- When A\ {\rm and}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if both of the digits in that place of A and B are 1, and 0 otherwise.
- When A\ {\rm or}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if at least one of the digits in that place of A and B is 1, and 0 otherwise.
- When A\ {\rm xor}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if exactly one of the digits in that place of A and B is 1, and 0 otherwise.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1\leq T_i \leq 3
- 0\leq A_i \lt 2^{30}
- 0\leq C \lt 2^{30}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N C T_1 A_1 T_2 A_2 \vdots T_N A_N
Output
Print N lines, as specified in the Problem Statement.
Sample Input 1
3 10 3 3 2 5 1 12
Sample Output 1
9 15 12
The initial value of X is 10.
- Operation 1 changes X to 9.
- Next, Operation 1 changes X to 10, and then Operation 2 changes it to 15.
- Next, Operation 1 changes X to 12, and then Operation 2 changes it to 13, and then Operation 3 changes it to 12.
Sample Input 2
9 12 1 1 2 2 3 3 1 4 2 5 3 6 1 7 2 8 3 9
Sample Output 2
0 2 1 0 5 3 3 11 2
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
1 から N までの番号が振られた N 個の都市と、それらの間を運行する M 本のバスがあります。i\ (1 \leq i \leq M) 本目のバスは時刻 S_i+0.5 に都市 A_i を出発し、時刻 T_i+0.5 に都市 B_i に到着します。
さて、これら N 個の都市の間を高橋くんが移動します。高橋くんは、時刻 t に都市 p にいるとき、以下のように行動します。
- 時刻 t 以降(時刻 t ちょうどを含む)に都市 p を出発するバスが存在するなら、そのようなバスのうち最も出発時刻が早いものに乗り、他の都市に移動する。
- そのようなバスが存在しないなら、何もせず都市 p に居続ける。
高橋くんは上記の行動を 2. の状態になるまで繰り返します。M 本のバスの出発時刻は互いに異なることが保証されるため、高橋くんが乗るバスは常に一意に定まります。また、バスの乗り換えにかかる時間は無視することができます。
それでは本題に入りましょう。Q 個のクエリに答えてください。i\ (1 \leq i \leq Q) 個目のクエリの内容は以下の通りです。
- 高橋くんが時刻 X_i に都市 Y_i から行動を開始するとき、時刻 Z_i にはどの都市にいるか、あるいはどのバスに乗っているか。
制約
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq Q \leq 10^5
- 1 \leq A_i,B_i \leq N\ (1 \leq i \leq M)
- A_i \neq B_i\ (1 \leq i \leq M)
- 1 \leq S_i \lt T_i \leq 10^9\ (1 \leq i \leq M)
- S_i \neq S_j\ (i \neq j)
- 1 \leq X_i \lt Z_i \leq 10^9\ (1 \leq i \leq Q)
- 1 \leq Y_i \leq N\ (1 \leq i \leq Q)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M Q
A_1 B_1 S_1 T_1
A_2 B_2 S_2 T_2
\hspace{1.8cm}\vdots
A_M B_M S_M T_M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\hspace{1.2cm}\vdots
X_Q Y_Q Z_Q
出力
Q 行に渡って出力せよ。i 行目には、 i 個目のクエリに対する答えを以下の指示にしたがって出力すること。
- 高橋くんが時刻 Z_i にいずれかのバスに乗っているならば、そのバスの始点、終点となる都市の番号をこの順に空白区切りで出力する。
- そうでない、すなわち高橋くんが時刻 Z_i にいずれかの都市にいるならば、その都市の番号を出力する。
入力例 1
3 2 3 1 2 1 3 2 3 3 5 1 1 5 2 2 3 1 3 2
出力例 1
2 3 2 3
1 つ目のクエリにおいて、高橋くんは以下の通りに動きます。
- はじめ、都市 1 に時刻 1 にいる。
- 時刻 1.5 に都市 1 を出発するバスに乗り、時刻 3.5 に都市 2 に到着する。
- 時刻 3.5 に都市 2 を出発するバスに乗り、時刻 5.5 に都市 3 に到着する。
- 時刻 5.5 以降に都市 3 を出発するバスは存在しないため、都市 3 に(永遠に)居続ける。
時刻 5 において、高橋くんは都市 2 を出発して都市 3 に到着するバスに乗っています。そのため、「出力」の項に書かれている通り、2, 3 を空白区切りで出力します。
入力例 2
8 10 10 4 3 329982133 872113932 6 8 101082040 756263297 4 7 515073851 793074419 8 7 899017043 941751547 5 7 295510441 597348810 7 2 688716395 890599546 6 1 414221915 748470452 6 4 810915860 904512496 3 1 497469654 973509612 4 1 307142272 872178157 374358788 4 509276232 243448834 6 585993193 156350864 4 682491610 131643541 8 836902943 152874385 6 495945159 382276121 1 481368090 552433623 2 884584430 580376205 2 639442239 108790644 7 879874292 883275610 1 994982498
出力例 2
4 6 1 4 1 8 6 1 1 2 2 7 2 1
Score : 500 points
Problem Statement
There are N cities numbered 1 through N, and M buses that go between these cities. The i-th bus (1 \leq i \leq M) departs from City A_i at time S_i+0.5 and arrive at City B_i at time T_i+0.5.
Takahashi will travel between these N cities. When he is in City p at time t, he will do the following.
- If there is a bus that departs from City p not earlier than time t, take the bus that departs the earliest among those buses to get to another city.
- If there is no such bus, do nothing and stay in City p.
Takahashi repeats doing the above until there is no bus to take. It is guaranteed that all M buses depart at different times, so the bus to take is always uniquely determined. Additionally, the time needed to change buses is negligible.
Here is your task: process Q queries, the i-th (1 \leq i \leq Q) of which is as follows.
- If Takahashi begins his travel in City Y_i at time X_i, in which city or on which bus will he be at time Z_i?
Constraints
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq Q \leq 10^5
- 1 \leq A_i,B_i \leq N\ (1 \leq i \leq M)
- A_i \neq B_i\ (1 \leq i \leq M)
- 1 \leq S_i \lt T_i \leq 10^9\ (1 \leq i \leq M)
- S_i \neq S_j\ (i \neq j)
- 1 \leq X_i \lt Z_i \leq 10^9\ (1 \leq i \leq Q)
- 1 \leq Y_i \leq N\ (1 \leq i \leq Q)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M Q
A_1 B_1 S_1 T_1
A_2 B_2 S_2 T_2
\hspace{1.8cm}\vdots
A_M B_M S_M T_M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\hspace{1.2cm}\vdots
X_Q Y_Q Z_Q
Output
Print Q lines. The i-th line should contain the response to the i-th query as follows.
- If Takashi is on some bus at time Z_i, print two integers representing the city from which the bus departs and the city at which the bus arrives, in this order, with a space between them.
- Otherwise, that is, if Takahashi is in some city at time Z_i, print an integer representing that city.
Sample Input 1
3 2 3 1 2 1 3 2 3 3 5 1 1 5 2 2 3 1 3 2
Sample Output 1
2 3 2 3
In the first query, Takahashi will travel as follows.
- Start in City 1 at time 1.
- Take the bus that departs from City 1 at time 1.5 and arrives at City 2 at time 3.5.
- Take the bus that departs from City 2 at time 3.5 and arrives at City 3 at time 5.5.
- Since no bus departs from City 3 at time 5.5 or later, stay in City 3 (forever).
At time 5, he will be on the bus that departs from City 2 and arrives at City 3. Thus, as specified in the Output section, we should print 2 and 3 with a space between them.
Sample Input 2
8 10 10 4 3 329982133 872113932 6 8 101082040 756263297 4 7 515073851 793074419 8 7 899017043 941751547 5 7 295510441 597348810 7 2 688716395 890599546 6 1 414221915 748470452 6 4 810915860 904512496 3 1 497469654 973509612 4 1 307142272 872178157 374358788 4 509276232 243448834 6 585993193 156350864 4 682491610 131643541 8 836902943 152874385 6 495945159 382276121 1 481368090 552433623 2 884584430 580376205 2 639442239 108790644 7 879874292 883275610 1 994982498
Sample Output 2
4 6 1 4 1 8 6 1 1 2 2 7 2 1