Skip to content

Instantly share code, notes, and snippets.

@magurofly
Created June 9, 2021 05:30
Show Gist options
  • Save magurofly/4dd77e4e0041d2d9b6164a1c19f61499 to your computer and use it in GitHub Desktop.
Save magurofly/4dd77e4e0041d2d9b6164a1c19f61499 to your computer and use it in GitHub Desktop.
典型061 スタック2本
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