Created
June 9, 2021 05:30
-
-
Save magurofly/4dd77e4e0041d2d9b6164a1c19f61499 to your computer and use it in GitHub Desktop.
典型061 スタック2本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *main() { | |
const Q = +(yield); | |
const head = [], tail = []; | |
for (let i = 0; i < Q; i++) { | |
const [t, x] = (yield).split(" ").map(Number); | |
if (t == 1) { | |
head.push(x); | |
} else if (t == 2) { | |
tail.push(x); | |
} else if (t == 3) { | |
if (x <= head.length) { | |
console.log(head[head.length - x]); | |
} else { | |
console.log(tail[x - head.length - 1]); | |
} | |
} | |
} | |
} | |
const iter = main(); | |
iter.next(); | |
require("readline").createInterface({input: process.stdin}).on("line", line => iter.next(line)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment