C - LOOKUP

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

英小文字からなる文字列 S,T が与えられるので、 TS の(連続する)部分文字列かどうか判定してください。

なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り YX の(連続する)部分文字列であると言います。

  • 以下の 2 つの操作から 1 つを選択して、その操作を行う。
    • X の先頭の 1 文字を削除する。
    • X の末尾の 1 文字を削除する。

例えば tagvoltage の(連続する)部分文字列ですが、 aceatcoder の(連続する)部分文字列ではありません。

制約

  • S,T は英小文字からなる
  • 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )

入力

入力は以下の形式で標準入力から与えられる。

S
T

出力

TS の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。


入力例 1

voltage
tag

出力例 1

Yes

tagvoltage の(連続する)部分文字列です。


入力例 2

atcoder
ace

出力例 2

No

aceatcoder の(連続する)部分文字列ではありません。


入力例 3

gorilla
gorillagorillagorilla

出力例 3

No

入力例 4

toyotasystems
toyotasystems

出力例 4

Yes

S=T である場合もあります。

Score : 200 points

Problem Statement

You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.

A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.

  • Do one of the following.
    • Delete the first character in X.
    • Delete the last character in X.

For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.

Constraints

  • S and T consist of lowercase English letters.
  • 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)

Input

The input is given from Standard Input in the following format:

S
T

Output

If T is a (contiguous) substring of S, print Yes; otherwise, print No.


Sample Input 1

voltage
tag

Sample Output 1

Yes

tag is a (contiguous) substring of voltage.


Sample Input 2

atcoder
ace

Sample Output 2

No

ace is not a (contiguous) substring of atcoder.


Sample Input 3

gorilla
gorillagorillagorilla

Sample Output 3

No

Sample Input 4

toyotasystems
toyotasystems

Sample Output 4

Yes

It is possible that S=T.

D - Round-Robin Tournament

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

1 から N までの番号が付いた N 人のプレイヤーが総当たり戦をしました。この総当たり戦で行われた試合全てについて、二人の一方が勝ち、もう一方が負けました。

総当たり戦の結果は N 個の長さ N の文字列 S_1,S_2,\ldots,S_N によって以下の形式で与えられます。

  • i\neq j のとき、S_ij 文字目は o, x のいずれかであり、o のときプレイヤー i がプレイヤー j に勝ったことを、x のときプレイヤー i がプレイヤー j に負けたことを意味する。

  • i=j のとき、S_ij 文字目は - である。

総当たり戦で勝った試合数が多いほうが順位が上であり、勝った試合数が同じ場合は、プレイヤーの番号が小さいほうが順位が上となります。 N 人のプレイヤーの番号を順位が高い順に答えてください。

制約

  • 2\leq N\leq 100
  • N は整数
  • S_io, x, - からなる長さ N の文字列
  • S_1,\ldots,S_N は問題文中の形式を満たす

入力

入力は以下の形式で標準入力から与えられる。

N 
S_1
S_2
\vdots
S_N

出力

N 人のプレイヤーの番号を、順位が高い順に空白区切りで出力せよ。


入力例 1

3
-xx
o-x
oo-

出力例 1

3 2 1

プレイヤー 10 勝、プレイヤー 21 勝、プレイヤー 32 勝なので、プレイヤーの番号は順位が高い順に 3,2,1 です。


入力例 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

出力例 2

4 7 3 1 5 2 6

プレイヤー 4 とプレイヤー 7 はどちらも 5 勝ですが、プレイヤー番号が小さいプレイヤー 4 のほうが順位が上になります。

Score : 200 points

Problem Statement

There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.

The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:

  • If i\neq j, the j-th character of S_i is o or x. o means that player i won against player j, and x means that player i lost to player j.

  • If i=j, the j-th character of S_i is -.

The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.

Constraints

  • 2\leq N\leq 100
  • N is an integer.
  • S_i is a string of length N consisting of o, x, and -.
  • S_1,\ldots,S_N conform to the format described in the problem statement.

Input

The input is given from Standard Input in the following format:

N 
S_1
S_2
\vdots
S_N

Output

Print the player numbers of the N players in descending order of rank.


Sample Input 1

3
-xx
o-x
oo-

Sample Output 1

3 2 1

Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.


Sample Input 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

Sample Output 2

4 7 3 1 5 2 6

Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.

E - The Kth Time Query

実行時間制限: 3 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

長さ N の数列 A = (a_1, a_2, \dots, a_N) があります。
以下で説明される Q 個のクエリに答えてください。

  • クエリ i : 整数の組 (x_i, k_i) が与えられます。A の要素を a_1, a_2, \dots と前から順に見ていったときに、数 x_ik_i 回目に登場するのは A の前から何番目の要素を見たときかを出力してください。
    ただし条件を満たす要素が存在しない場合は -1 を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
  • 1 \leq k_i \leq N (1 \leq i \leq Q)
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N Q
a_1 a_2 \dots a_N
x_1 k_1
x_2 k_2
\vdots
x_Q k_Q

出力

Q 行出力せよ。i 行目ではクエリ i に対する答えを出力せよ。


入力例 1

6 8
1 1 2 3 1 2
1 1
1 2
1 3
1 4
2 1
2 2
2 3
4 1

出力例 1

1
2
5
-1
3
6
-1
-1

A の中で 1a_1, a_2, a_5 に登場します。よって、クエリ 1 からクエリ 4 の答えは順に 1, 2, 5, -1 となります。


入力例 2

3 2
0 1000000000 999999999
1000000000 1
123456789 1

出力例 2

2
-1

Score : 300 points

Problem Statement

We have a sequence of N numbers: A = (a_1, a_2, \dots, a_N).
Process the Q queries explained below.

  • Query i: You are given a pair of integers (x_i, k_i). Let us look at the elements of A one by one from the beginning: a_1, a_2, \dots Which element will be the k_i-th occurrence of the number x_i?
    Print the index of that element, or -1 if there is no such element.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq a_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq x_i \leq 10^9 (1 \leq i \leq Q)
  • 1 \leq k_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 Q
a_1 a_2 \dots a_N
x_1 k_1
x_2 k_2
\vdots
x_Q k_Q

Output

Print Q lines. The i-th line should contain the answer to Query i.


Sample Input 1

6 8
1 1 2 3 1 2
1 1
1 2
1 3
1 4
2 1
2 2
2 3
4 1

Sample Output 1

1
2
5
-1
3
6
-1
-1

1 occurs in A at a_1, a_2, a_5. Thus, the answers to Query 1 through 4 are 1, 2, 5, -1 in this order.


Sample Input 2

3 2
0 1000000000 999999999
1000000000 1
123456789 1

Sample Output 2

2
-1
F - Invisible Hand

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

りんご市場に N 人の売り手と M 人の買い手がいます。

i 番目の売り手は、A_i 円以上でならりんごを売ってもよいと考えています。

i 番目の買い手は、B_i 円以下でならりんごを買ってもよいと考えています。

次の条件を満たすような最小の整数 X を求めてください。

条件:りんごを X 円で売ってもよいと考える売り手の人数が、りんごを X 円で買ってもよいと考える買い手の人数以上である。

制約

  • 1 \leq N,M \leq 2\times 10^5
  • 1\leq A_i,B_i \leq 10^9
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N M
A_1 \ldots A_N
B_1 \ldots B_M

出力

答えを出力せよ。


入力例 1

3 4
110 90 120
100 80 120 10000

出力例 1

110

りんごを 110 円で売ってもよいと考える売り手は 1,2 番目の 2 人であり、りんごを 110 円で買ってもよいと考える買い手は 3,4 番目の 2 人であるため、110 は条件を満たします。

110 未満の整数が条件を満たすことはないため、これが答えです。


入力例 2

5 2
100000 100000 100000 100000 100000
100 200

出力例 2

201

入力例 3

3 2
100 100 100
80 120

出力例 3

100

Score : 300 points

Problem Statement

There are N sellers and M buyers in an apple market.

The i-th seller may sell an apple for A_i yen or more (yen is the currency in Japan).

The i-th buyer may buy an apple for B_i yen or less.

Find the minimum integer X that satisfies the following condition.

Condition: The number of people who may sell an apple for X yen is greater than or equal to the number of people who may buy an apple for X yen.

Constraints

  • 1 \leq N,M \leq 2\times 10^5
  • 1\leq A_i,B_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
A_1 \ldots A_N
B_1 \ldots B_M

Output

Print the answer.


Sample Input 1

3 4
110 90 120
100 80 120 10000

Sample Output 1

110

Two sellers, the 1-st and 2-nd, may sell an apple for 110 yen; two buyers, the 3-rd and 4-th, may buy an apple for 110 yen. Thus, 110 satisfies the condition.

Since an integer less than 110 does not satisfy the condition, this is the answer.


Sample Input 2

5 2
100000 100000 100000 100000 100000
100 200

Sample Output 2

201

Sample Input 3

3 2
100 100 100
80 120

Sample Output 3

100
G - LOWER

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

英大文字および英小文字からなる長さ N の文字列 S が与えられます。

これから、文字列 S に対して Q 回の操作を行います。 i 番目 (1\leq i\leq Q) の操作は整数 2 つと文字 1 つからなる組 (t _ i,x _ i,c _ i) で表され、それぞれ次のような操作を表します。

  • t _ i=1 のとき、Sx _ 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

はじめ、文字列 SAtCoder です。

  • 1 番目の操作では、4 文字目を i に変更します。変更後の SAtCider です。
  • 2 番目の操作では、すべての小文字を大文字に変更します。変更後の SATCIDER です。
  • 3 番目の操作では、5 文字目を b に変更します。変更後の SATCIbER です。
  • 4 番目の操作では、すべての大文字を小文字に変更します。変更後の Satciber です。
  • 5 番目の操作では、4 文字目を Y に変更します。変更後の SatcYber です。

すべての操作が終わったあとの SatcYber なので、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 to AtCider.
  • 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 to ATCIbER.
  • 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 to atcYber.

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