結果
問題 | No.1778 括弧列クエリ / Bracketed Sequence Query |
ユーザー | yudedako |
提出日時 | 2022-01-28 22:48:56 |
言語 | Scala(Beta) (3.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,239 bytes |
コンパイル時間 | 16,571 ms |
コンパイル使用メモリ | 254,012 KB |
実行使用メモリ | 129,024 KB |
最終ジャッジ日時 | 2023-08-28 21:24:43 |
合計ジャッジ時間 | 44,329 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | AC | 1,275 ms
67,680 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 1,576 ms
68,888 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
import java.io.BufferedReader import scala.annotation.tailrec import scala.collection.{immutable, mutable} import scala.io.StdIn.readLine import scala.math.* import scala.annotation.tailrec import scala.io.{BufferedSource, StdIn} def readLine()(using reader: BufferedReader): String = reader.readLine() @main def main = given reader: BufferedReader = scala.io.Source.stdin.bufferedReader() val Array(n, q) = readLine().split(' ').map(_.toInt) val s = readLine() val queries = Array.fill(q){ val Array(x, y) = readLine().split(' ').map(_.toInt - 1) min(x, y) -> max(x, y) } val stack = mutable.ArrayDeque[Int]() val pair = Array.fill(n){-1} for (c, i) <- s.zipWithIndex do c match case '(' => stack.addOne(i) case ')' => val h = stack.removeLast() pair(i) = h pair(h) = i val result = Array.fill(q){"-1"} val set = mutable.TreeSet[Int]() var last = 0 for ((x, y), i) <- queries.zipWithIndex.sortBy(_._1) do while last <= x do if s(last) == '(' then set.addOne(pair(last)) last += 1 set.minAfter(y) match case Some(right) => result(i) = s"${pair(right) + 1} ${right + 1}" case None => println( result.mkString("\n") )