Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions data_structure/deque/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
12 changes: 12 additions & 0 deletions data_structure/deque/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
11
0 2
1 5
0 3
4 0
4 1
4 2
2
4 0
4 1
3
4 0
84 changes: 84 additions & 0 deletions data_structure/deque/gen/max_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "random.h"
#include "../params.h"
#include <cstdio>
#include <vector>

using namespace std;

void out(vector<int> T, Random &gen) {
int Q = T.size();
printf("%d\n", Q);
int n = 0;
for (int t : T) {
if (t == 0 || t == 1) {
int x = gen.uniform<int>(MIN_X, MAX_X);
printf("%d %d\n", t, x);
++n;
} else if (t == 2 || t == 3) {
printf("%d\n", t);
--n;
} else if (t == 4) {
int i = gen.uniform<int>(0, n - 1);
printf("%d %d\n", t, i);
} else {
assert(false);
}
}
}

int main(int, char *argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
int Q = MAX_Q;

int prob[5];
if (seed <= 2) {
prob[0] = prob[1] = prob[2] = prob[3] = prob[4] = 20;
} else if (seed == 3) {
prob[0] = 96;
prob[1] = prob[2] = prob[3] = prob[4] = 1;
} else if (seed == 4) {
prob[1] = 96;
prob[0] = prob[2] = prob[3] = prob[4] = 1;
} else if (seed == 5) {
prob[2] = 96;
prob[0] = prob[1] = prob[3] = prob[4] = 1;
} else if (seed == 6) {
prob[3] = 96;
prob[0] = prob[1] = prob[2] = prob[4] = 1;
} else if (seed == 7) {
prob[4] = 96;
prob[0] = prob[1] = prob[2] = prob[3] = 1;
} else if (seed == 8) {
prob[0] = prob[1] = prob[4] = 32;
prob[2] = prob[3] = 2;
} else {
while (1) {
prob[0] = gen.uniform<int>(0, 100);
prob[1] = gen.uniform<int>(0, 100);
prob[2] = gen.uniform<int>(0, 100);
prob[3] = gen.uniform<int>(0, 100);
prob[4] = gen.uniform<int>(0, 100);
if (prob[0] + prob[1] + prob[2] + prob[3] + prob[4] > 0) break;
}
}

vector<int> S;
for (int k = 0; k < 5; ++k) {
for (int i = 0; i < prob[k]; ++i) S.push_back(k);
}

vector<int> T(Q);
int n = 0;
for (int q = 0; q < Q; ++q) {
int idx = gen.uniform<int>(0, int(S.size()) - 1);
int t = S[idx];
if (n == 0) t = gen.uniform<int>(0, 1);
T[q] = t;
if (t == 0 || t == 1) ++n;
if (t == 2 || t == 3) --n;
}

out(T, gen);
return 0;
}
46 changes: 46 additions & 0 deletions data_structure/deque/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "random.h"
#include "../params.h"
#include <cstdio>
#include <vector>

using namespace std;

void out(vector<int> T, Random &gen) {
int Q = T.size();
printf("%d\n", Q);
int n = 0;
for (int t : T) {
if (t == 0 || t == 1) {
int x = gen.uniform<int>(MIN_X, MAX_X);
printf("%d %d\n", t, x);
++n;
}
if (t == 2 || t == 3) {
printf("%d\n", t);
--n;
}
if (t == 4) {
int i = gen.uniform<int>(0, n - 1);
printf("%d %d\n", t, i);
}
}
}

int main(int, char *argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
int Q = gen.uniform<int>(MIN_Q, MAX_Q);

vector<int> T(Q);

int n = 0;
for (int q = 0; q < Q; ++q) {
int t = gen.uniform<int>(0, 4);
if (n == 0) t = gen.uniform<int>(0, 1);
T[q] = t;
if (t == 0 || t == 1) ++n;
if (t == 2 || t == 3) --n;
}
out(T, gen);
return 0;
}
46 changes: 46 additions & 0 deletions data_structure/deque/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "random.h"
#include "../params.h"
#include <cstdio>
#include <vector>

using namespace std;

void out(vector<int> T, Random &gen) {
int Q = T.size();
printf("%d\n", Q);
int n = 0;
for (int t : T) {
if (t == 0 || t == 1) {
int x = gen.uniform<int>(MIN_X, MAX_X);
printf("%d %d\n", t, x);
++n;
}
if (t == 2 || t == 3) {
printf("%d\n", t);
--n;
}
if (t == 4) {
int i = gen.uniform<int>(0, n - 1);
printf("%d %d\n", t, i);
}
}
}

int main(int, char *argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
int Q = (seed % 10) + 1;

vector<int> T(Q);

int n = 0;
for (int q = 0; q < Q; ++q) {
int t = gen.uniform<int>(0, 4);
if (n == 0) t = gen.uniform<int>(0, 1);
T[q] = t;
if (t == 0 || t == 1) ++n;
if (t == 2 || t == 3) --n;
}
out(T, gen);
return 0;
}
74 changes: 74 additions & 0 deletions data_structure/deque/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"example_00.in": "02a78bc2ddd3c988778cfd9bc83eedea882663fbdf92778f8673ec570f91ba1a",
"example_00.out": "01efd104608a71c50663da3be9e23062551ab36dafb4c90ab0da0d6152a5569c",
"max_random_00.in": "810b0cb29fd918d41d805759bd11535db7cfac75c52fda554860d969c6ddf7bd",
"max_random_00.out": "57de60f987ad465c2b4434c3c9abecd4578027e4177e64d07ea801823305b337",
"max_random_01.in": "5a78ff23d5a4d26e897e837f4240cf3f9f9f75b88886d1e79f08fb81585bf8ec",
"max_random_01.out": "55635c104aad195baea0a852f870064e340a59af56f5fef3d6d01ef8c358d07b",
"max_random_02.in": "111b45ce8ce4e33813adad9395bb45e73ea51bf81bfe4add480265eb463b66b6",
"max_random_02.out": "0c6e8e2fc4397082d1ff2462bacb3a7577e2f45d282f5654fa439f2a2717fc0a",
"max_random_03.in": "3095049f97187f0fbb3d9b2942473ca86b2ccea7e44016ee044493a1f7a5f893",
"max_random_03.out": "183b8ace606740725c4d56c02d7b93ac643c4c691e70528be73c0081855034d6",
"max_random_04.in": "06cf0c948a391d2c96161ab3462029bbd638b018634faa88eef7124b01bc4385",
"max_random_04.out": "bd7a831dc40e2236379aa391f6391fbc993d8301ff189a38cb53212f905fd7a6",
"max_random_05.in": "9362db590736e82d7a2ed3c8b4e60fab38d742a05595ae5436c69abaab139d18",
"max_random_05.out": "6c860866924db29f571315b994a5f2022f81cc2142ffddcc86d658d28736e317",
"max_random_06.in": "da699071774609c4fb18e1d761b31013fa7f3828929e7a8451fc326abce121b0",
"max_random_06.out": "8a10e295e73efe714a4d749bf719f138fe0f764ac14abb61e6ebf94e7ab7544b",
"max_random_07.in": "f2f28da65011360a2474644f4ab8725623cf2f0cd7619be395170ffe922e70f4",
"max_random_07.out": "b14983205640d75a4fac428b4fd8e429300e40a032640d1b47db49bb0bd9523a",
"max_random_08.in": "b84cd6ffdc3ae0e2a23bfcc1d8cfcda93e9c221cf9d948bd0c684e46e635cd10",
"max_random_08.out": "cc9b5c146aae44aa0e6acae3bae7676f1288bcc978550e00ac10bbe26473bc85",
"max_random_09.in": "84e16b32b5b58e99c00c10f5446fd70ec32bea44fefdd68e97afccd3b593febe",
"max_random_09.out": "92fe34d23a3d88f534799aff1133a44e8a0a2c58bfae6b157b4b766c479216d8",
"max_random_10.in": "7a5098b649e27fcd8830f325890f2a3ebd9ef434ffae7eabb3c0a97b5f5e3c24",
"max_random_10.out": "4aa03f3920f68c8f4b588ad1b8439e4434e62a46779f79c53fa2d4014e0873c0",
"max_random_11.in": "6f319502c2c9856a1b52ac4cbc37c7bb6cef946d257e89a4d2e43207d049de9f",
"max_random_11.out": "a16238eb983f8fc1a4dad1d212d441671447962baa76c2f601d2c3bac8630495",
"max_random_12.in": "afab88716c98bfbd1933ba0bafbe5d2e21af5ddb9699279a56b6e1af33868652",
"max_random_12.out": "eabb265257b3ea5c61180e3f40760c746422b8a76b6eee5944d94988d3c4d092",
"max_random_13.in": "9ebfcd2a39adba169da3fffb2a22faa2a17411927d6fb828a0c6275b0769d95b",
"max_random_13.out": "0d9308dc253b79475a4cb747dddc91e361ef94d677fa64cbfed8278663c1d01a",
"max_random_14.in": "ede23168ca787534b39810590a2ca3d88666abb7f56175bcc2194b0797f0e8a3",
"max_random_14.out": "316465522975274dc94434a5f317bebb1ec6927fadfa696f1eb4571c714c4699",
"max_random_15.in": "86e35cc8bbda1973478709fbd8b6fcd4e0b60efaddff195c46195ec268f8d4e1",
"max_random_15.out": "7592079928d25a2c54ddf3c65bdfcad8ed8ccfd8ebcd26fb05f183201fe58a75",
"max_random_16.in": "f92896df158b8f2a555e5a8c2b85dc17841365aabece05fd37ea641634fc6118",
"max_random_16.out": "b6991f61b5442ed4b69fed602ede2dd39e4fc0848073f5541921f15a15f51d41",
"max_random_17.in": "cd021216129b857282bc09cc4f593c9c2141f7b6b3951e199b33837b3e39c41e",
"max_random_17.out": "0a5bbb6c9d0ef6e32e2d962bc76544ef72ca01a19bc20ed12554c0bb41e52717",
"max_random_18.in": "279cbaffd497929bed2d4134272a5e4077ff1f87053f18671e856d1e46fe7e95",
"max_random_18.out": "3daf8ac8fdf5ea2a62b61ca8bb700e2cb5445e4baf1cb68d7e37505bc90ba2c2",
"max_random_19.in": "565f3c10142757be7d0b1afbe8ffb6e05dbe1a4b0f862845c96b38141c477fc7",
"max_random_19.out": "e7eff97f830b152e02a3b4034803e276be826d5dfd47c9bf53eb78a9d8090a83",
"random_00.in": "4e99c619bb43664c4e7e8f68524580a9c355ef79d02e9a564fc11ed9f21d28d7",
"random_00.out": "fe1d6ad836b833a9388b11a9251b51fe74094a6a8378642ec5918644b0b4fdb0",
"random_01.in": "be06fec2e8d9786b90322335148c02168c63c1b683dd4e5a3268122b8fa5fea6",
"random_01.out": "373233bdd3b517a9f791d037511c01361e4ffb1cc33cbe6e08a36cfe5bf7b084",
"random_02.in": "c7d1553861236300dc81c2c4653281ad22bd5e1f58ac09db71211ad264f49b8c",
"random_02.out": "c813c11c51f20b53d6d0aa60b7c0c0ae05ed78bd74665f71f2366fe835feefb6",
"random_03.in": "dd6d1c808109482003153a65519ced91f7331e9f62592a3193a8380f6f6feb4b",
"random_03.out": "e9be79299551b1ef7e4d3192b4010335aca763d530088aa2a107384c328f3d82",
"random_04.in": "12971a4027c63a1cb2aa51592b939075a6f2847613bd18a6fe458565cfd90960",
"random_04.out": "f395353fec22e08370026087c322214c607c065f30d279897ebb29466920f07a",
"small_00.in": "a2309aab5258791623dc9adab5ff3b9fa328dba93ecaf13b0fb88b25006eb468",
"small_00.out": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"small_01.in": "98545d70f0eb06057c7c4ba22d33f2eb6e5cc63e7059d76780a6c81371fe8406",
"small_01.out": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"small_02.in": "f08377040de281b811a67b09ee01372e598a0cfdbf9c75545cd3148eb3f9a7ab",
"small_02.out": "4f9d0ac2a839f162529fedd5ce5e4867eb21b507e544758b2ff56324901405d3",
"small_03.in": "42485caaa5a874dc61bb4b9b988486460e02219d67f702d1dc3aed31c1c7fbec",
"small_03.out": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"small_04.in": "0e71b46f2f41bead0d333497ac4ce5ff3d2ac5d332f579ba66b3d195b475a07b",
"small_04.out": "66dbc036d41466ebcfaf4d3df2b97ae65da77fc4842dcaf9843b0a3546a5c6f5",
"small_05.in": "96b116f102728ef8c975a77956225ab6ac9d84611b642e0b31ddc74aafb64e49",
"small_05.out": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"small_06.in": "7bca218e90a972731e9d37ee841be71ecfeb485499c9ffa872d89e5f57909a8b",
"small_06.out": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"small_07.in": "3d9725f81a9841c07477a1fe536f45dd0df5565631cbd382e1a22fecfa25eca5",
"small_07.out": "da253e091aaa1178d479b5ec95fd7d1eaed49bc57f1da669414aaefd9a6b848c",
"small_08.in": "110e72c3889831deb342a3e76807fa2d3a7b7f5d534db60a9c9175701497ab18",
"small_08.out": "209e65ac447b31850aec216e902aea1a870adfbdc1c36925368d3288f899aba5",
"small_09.in": "b32fb31f2590c3a1c8b0850241243ea2a6e57849f7a7ab0739be4431f8a3afea",
"small_09.out": "ac2bea1cd249d27ce47343a57c9d6b992efc2d396744688e74ddcd3ef1415414"
}
22 changes: 22 additions & 0 deletions data_structure/deque/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
title = 'Deque'
timelimit = 5.0
forum = "https://github.com/yosupo06/library-checker-problems/issues/1342"

[[tests]]
name = "example.in"
number = 1
[[tests]]
name = "small.cpp"
number = 10
[[tests]]
name = "random.cpp"
number = 5
[[tests]]
name = "max_random.cpp"
number = 20

[params]
MIN_Q = 1
MAX_Q = 500_000
MIN_X = 0
MAX_X = 1_000_000_000
39 changes: 39 additions & 0 deletions data_structure/deque/sol/correct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <deque>
#include <cassert>
#include <cstdio>

using namespace std;

void solve() {
int Q;
scanf("%d", &Q);

deque<int> que;
for (int q = 0; q < Q; ++q) {
int t, x;
scanf("%d", &t);
if (t == 0) {
scanf("%d", &x);
que.push_front(x);
}
if (t == 1) {
scanf("%d", &x);
que.push_back(x);
}
if (t == 2) {
assert(!que.empty());
que.pop_front();
}
if (t == 3) {
assert(!que.empty());
que.pop_back();
}
if (t == 4) {
scanf("%d", &x);
assert(0 <= x && x < int(que.size()));
printf("%d\n", que[x]);
}
}
}

signed main() { solve(); }
Loading
Loading