Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

問題追加 Ordered Set #1275

Merged
merged 7 commits into from
Nov 11, 2024
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/ordered_set/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");
}
}
19 changes: 19 additions & 0 deletions data_structure/ordered_set/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
3 17
10 20 30
2 1
2 2
2 3
3 19
3 20
3 21
4 19
4 20
4 21
0 0
2 1
0 0
2 1
1 0
2 1
1 0
2 1
6 changes: 6 additions & 0 deletions data_structure/ordered_set/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0 4

2 1
3 1
4 1
5 1
117 changes: 117 additions & 0 deletions data_structure/ordered_set/gen/max_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <cstdlib>
#include <cstdio>

#include "../params.h"
#include "random.h"

using namespace std;

/*
要素の種類 K
0:1000, dense
1:1000, random
2:10^6, dense
3:10^6, random

クエリ
0:[1/6,1/6,1/6,1/6,1/6,1/6]
1:[1/5,eps,1/5,1/5,1/5,1/5]
2:[1,eps,eps,eps,eps,eps]
3:[eps,1,eps,eps,eps,eps]
4:[eps,eps,1,eps,eps,eps]
5:[eps,eps,eps,1,eps,eps]
6:[eps,eps,eps,eps,1,eps]
7:[eps,eps,eps,eps,eps,1]

seed/8, seed%8
*/

vector<int> gen_val(Random& gen, int seed) {
seed /= 8;
int K = ((seed == 0 || seed == 1) ? 1000 : 1000000);
if (seed == 0 || seed == 2) {
int s = gen.uniform<int>(0, A_MAX - K + 1);
vector<int> A(K);
for (int i = 0; i < K; ++i) A[i] = i + s;
return A;
}
return gen.choice<int>(K, A_MIN, A_MAX);
}

vector<int> gen_prob(int seed) {
seed %= 8;
vector<int> S = {0, 1, 2, 3, 4, 5};
for (int t = 0; t < 6; ++t) {
bool add = 0;
if (seed == 0) add = 1;
if (seed == 1 && t != 1) add = 1;
if (seed == 2 && t == 0) add = 1;
if (seed == 3 && t == 1) add = 1;
if (seed == 4 && t == 2) add = 1;
if (seed == 5 && t == 3) add = 1;
if (seed == 6 && t == 4) add = 1;
if (seed == 7 && t == 5) add = 1;
if (add) {
for (int i = 0; i < 100; ++i) S.emplace_back(t);
}
}
return S;
}

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

vector<int> kind = gen_val(gen, seed);
vector<int> S = gen_prob(seed);

vector<int> A;
for (auto& x: kind) {
if (gen.uniform<int>(0, 1)) { A.emplace_back(x); }
}
if (int(A.size()) > N_MAX) A.resize(N_MAX);

int N = A.size();
int Q = Q_MAX;

printf("%d %d\n", N, Q);
for (int i = 0; i < N; ++i) {
if (i) printf(" ");
printf("%d", A[i]);
}
printf("\n");

int sz = S.size();
int K = kind.size();

set<int> ANS(A.begin(), A.end());

for (int i = 0; i < Q; i++) {
int t = S[gen.uniform<int>(0, sz - 1)];
int x = 0;
if (t == 0) {
x = kind[gen.uniform<int>(0, K - 1)];
ANS.insert(x);
}
if (t == 1) {
x = kind[gen.uniform<int>(0, K - 1)];
ANS.erase(x);
}
if (t == 2) {
int n = ANS.size();
x = gen.uniform<int>(1, n + 1);
if (gen.uniform<int>(0, 100) == 0) { x = gen.uniform<int>(1, A_MAX); }
}
if (t == 3 || t == 4 || t == 5) {
x = gen.uniform<int>(A_MIN, A_MAX);
if (gen.uniform<int>(0, 1)) { x = kind[gen.uniform<int>(0, K - 1)]; }
}

printf("%d %d\n", t, x);
}
return 0;
}
36 changes: 36 additions & 0 deletions data_structure/ordered_set/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <string>

#include "../params.h"
#include "random.h"

using namespace std;

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

int K = seed % 3 + 1;
int Q = Q_MAX;

vector<int> A;
for (int x = 0; x < K; ++x) {
if (gen.uniform<int>(0, 1)) A.emplace_back(x);
}
int N = A.size();

printf("%d %d\n", N, Q);
for (int i = 0; i < N; ++i) {
if (i) printf(" ");
printf("%d", A[i]);
}
printf("\n");

for (int i = 0; i < Q; i++) {
int t = gen.uniform(0, 5);
int x = gen.uniform(0, K - 1);
if (t == 2) ++x;
printf("%d %d\n", t, x);
}
return 0;
}
76 changes: 76 additions & 0 deletions data_structure/ordered_set/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"example_00.in": "226c519151f1cdbd49fc9904c6d1e143a34b29b69b38cb129cf7bcd8ff2b171f",
"example_00.out": "7447f71ee379e98b22a881d3630c5efac561290939b0c7204a2002c339d6ff8d",
"example_01.in": "8e4ab9cc1f3b21c6fe5e854a9e8149d833ed7dd7893a8ddfaaa28788988abf16",
"example_01.out": "c072f97b1f6faeb9a98a6e63d5962d56aff52be48a1eef570c9722906d51c621",
"max_random_00.in": "7a1ac2dbb0b7c6df32ae690777b1623223254b80871be6e80e86af6bd326d44f",
"max_random_00.out": "56674f50d7f4e725aac2108f7d94097639273ace40371b5619c165914bcde89e",
"max_random_01.in": "2e303efdaac48ca9e6269f0d72ce29f95f2f4d88e7d5aea088abfa2c8e2a11c6",
"max_random_01.out": "73a09ca72730187407976ee27946d9daff35840ab6b8c9671e91177d2b85e454",
"max_random_02.in": "0a71a46735f430adbdb80bd8653ed3de2e30885e70ee88833aecc25d986ef3dd",
"max_random_02.out": "202fbf58a0965fe5753e55cef0d060f6187c9e084e8000643ee59349efb221b6",
"max_random_03.in": "516397deefa093842049fcc8fd0ab4ef068219dddf3b7d41b285c85ba9e8c406",
"max_random_03.out": "87ccadb2d01b25a87c87c9d95968b1739a1876b78ebf46cdf8a702c24d5ec2f4",
"max_random_04.in": "1441fa2c98f0289e4ea95276f06b2649f3315dadc3e597717c022470202960ba",
"max_random_04.out": "9470fa86dd46ad62c2a52d7ad94ae176a336c3c64543b127fc6f6a5928222133",
"max_random_05.in": "db22cb4ff9749b95e04778ff4cce430485a710bfc294ba8d2748ac9b4b30773a",
"max_random_05.out": "dc67f42d816daaf7a9c3eb1b7e4c81848b42441c98b468279861031d5070dfa4",
"max_random_06.in": "41735d2716207b75d679e359befc533f354ba2936eb7d59a4d1859541d13af3c",
"max_random_06.out": "f8bf076c922ca6eb4179ac3792b92d18ef4c472b657a2b881ffd99e812e39199",
"max_random_07.in": "26085cb66d9d2c3744bb6cf41fe5e5e70441277e031ffdb21e15b742065a2644",
"max_random_07.out": "c2e95e1a7f5fde6366f2278ac5011c279bd4a4fac0239c2b2b9cdf1463ece891",
"max_random_08.in": "e70fd62194f2a6fffabbf0d258767a88a2f436a799a6194345d6f0dc6ae46bfc",
"max_random_08.out": "f770f12ccfc1f9e09791ab6d41d07faa0a2141c591049e32b1dd1873fd089f1a",
"max_random_09.in": "161d51d239c31f1b70b9d526394d2a9eff0115147751a1741354bdb768b1817c",
"max_random_09.out": "973f568cac6830e4136010b50fbd6f0a2f65cfe25be70660e7975018a2f2a543",
"max_random_10.in": "246854b84ee227121dbba4112890c0c5c09e2b4f5ee6c0ba8ed1e2a1c90fe0c7",
"max_random_10.out": "18779899a7a81ed6b6ea66e9691b4f069ded760d91aa5c4895f2e30c2585cff9",
"max_random_11.in": "d891016bb5baa31f4c88fdc5f8f2338f025b8990644d25b0ca8752a262ecc905",
"max_random_11.out": "23a12beae04ec057be350f3590b0b9f44ca375a808f662a9208370ad1fc24280",
"max_random_12.in": "3da90acfb705b2dc1d52cafd39a8f1d8b305f99e68ec8fb9b162f1ae94ebd9f3",
"max_random_12.out": "a5d96dabfa9db0d4366086b14545b55c4ef3d400df25c239f54a53ac8204ef34",
"max_random_13.in": "c4c225f2cc8e919033a58d4e16b150eac0ec353894ec13d0873302345d6cde93",
"max_random_13.out": "8bd0b32ae5febe037946101bb44b09da1210d5aeeb57802d113b1e49d3ee94f4",
"max_random_14.in": "d6273d963fa882a938b27880dbfde425260d6e8f8c7510786f71f45a6ecad601",
"max_random_14.out": "628bd96af683ec61c014596a3352e035580da6baf3353cac0718ae6f5d114760",
"max_random_15.in": "f3617cc3840779b2161c0a3eaf06568bd294bf971e7a771512dfa55b1dbcec76",
"max_random_15.out": "b93bf2a8836283071657d259db5b4ca14a253e47fdf73d6c6baecfd98568b786",
"max_random_16.in": "438db97646a3f6055d6bfc7b7ffca2c590b07aac2c0ad01bdc28dd1939470aa0",
"max_random_16.out": "31fe327f27e16cea0753008891619f3c08612c40e109e3a0ddc96de567553535",
"max_random_17.in": "d3888c77ca8863b6984687f518624fcd6276405b18a52b942e505509531b82b1",
"max_random_17.out": "8c3d1fda530e3162c900ba9145d1753bfc819477ae617f054110963e40584773",
"max_random_18.in": "8c270fdba93ec531c764a0ccaabc56baa8648fa1c3a2776d87fa5daabaf16a9c",
"max_random_18.out": "dbb88b8e9593a2bb4b8a888bf0377afcc433d5169c740073397fe3b51f76402d",
"max_random_19.in": "2869883ac314cd9a5b8a6cfdec834ea295980014242e97b0bef7019142229f88",
"max_random_19.out": "6fba96c92e2151cc95a542eedd13a59e65f20e7968b279dd1666d268f7ad7969",
"max_random_20.in": "ba015c6063a68dc29f42bb1491047852641663e9babf1d0896eaaf1363c35b90",
"max_random_20.out": "bb95c7d3c9d337489a25748ceda141f5804864aa3545355678d623019eb7a089",
"max_random_21.in": "9c27a5825a3225cd72226379cb86bfef37daa985f27c97b58b3f7adbedd90359",
"max_random_21.out": "688cc5acdfc3f31dc49e6495486f6f39665270de89e78162b787a7ba42a7fcbd",
"max_random_22.in": "0ce1469a706b3724833ab61c102fcba3216318d6e4ae7262e1b2b4be51fc080c",
"max_random_22.out": "d36b283fa9fde8f68601f4b52894abe63c7bb70e4af265979cfebda701829198",
"max_random_23.in": "c87400eb0bfec9ac6a00014cf7884851c420b30eeb4282902cdde89ff8f650da",
"max_random_23.out": "bf2dc1e8b56cf05c64bd341030b5e8f991173010b0650ede34b215f99bce2cf4",
"max_random_24.in": "04aac5c4fda27cd5d7aadbeca7a4cd15d814467398f20244343f52f7270a7d47",
"max_random_24.out": "036c79ba4e691d3758e3a2a7cb3caebee08c20eea16ec0d5663ccc56ac0d52c7",
"max_random_25.in": "128c8493416e5c7a1334cd92fd5d1861009afe065b918f1ffb8b174afeafaf1b",
"max_random_25.out": "d1295b4b7f5d7af683197356d835b9245ec8b0098595b924c7105bc8dae9a73f",
"max_random_26.in": "46e5ddda3af75e67c6a0c15c75fa102ac9469108a21c510cf57ae7b4d4a9b23c",
"max_random_26.out": "4e7d4109df372366f9d4febdd3896abd5986b95397a18fa4a212c23db98c5e2b",
"max_random_27.in": "3ffff875b827372a9c11b1844eb08bc5ec696ba7c3d22f9ebae4d604a130035c",
"max_random_27.out": "3b3a40970957ea67fdd218e1bf2e56ec65789b40c60ead430e302c586c1f446b",
"max_random_28.in": "11860bc8cad139a62d54f1a1416513287dd23fc3389923c8a73860c732a43f29",
"max_random_28.out": "87cefea86dfe563b0c53292b41f2df4520c366a8cac3efdf191ac3eea755c864",
"max_random_29.in": "fde12032aa0ad5210d1c700ef8a8b98b583fc31dc5eb2c2fb9a8ed410a0cacf0",
"max_random_29.out": "b2203a2734d3ef3758c56c22c986dbc54c7ac0198739bd5345d9346666017510",
"max_random_30.in": "4537eac68209d45d97fd0339afaf78e23dea3682200bf78e382c1384d0381a44",
"max_random_30.out": "15b8cb726779ecf96b8c8b7146d6f502bfce47f43b06e5706d81f596cbab3716",
"max_random_31.in": "01b9ac8f94dc79a624a7729deb87b3224ba46d84de6301ec7bba6ad920065f0f",
"max_random_31.out": "90407a9a360db3ba8f57fbf2440e8248c332d82258eb47be361222509f195260",
"small_00.in": "ddc8dd62d510c2622d8aa2f4852b7e4e3e851edcd25a97149c8e539ffcc49860",
"small_00.out": "1530577c46406620cb03fd10fd9efe4fd77b7dca73293dade58cf8e86c6d3f08",
"small_01.in": "27b74d22f8235a213c93555d3fd2a22648ff03f22c0ee926589a41f8a24d0192",
"small_01.out": "65578eb9a7fc4903e03aa4a7ac1ecf3a781e08c9880761a538177c00a042ff2f",
"small_02.in": "94334f2e39d09a6f16070dcf5be669f983df859238f171e672808823b85031a7",
"small_02.out": "5aed019a0274322279ef71cd06bc6fff1ffdaf331a18343c112d019717951f17"
}
28 changes: 28 additions & 0 deletions data_structure/ordered_set/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
title = 'Ordered Set'
timelimit = 10.0
forum = "https://github.com/yosupo06/library-checker-problems/issues/1243"


[[tests]]
name = "example.in"
number = 2

[[tests]]
name = "small.cpp"
number = 3

[[tests]]
name = "max_random.cpp"
number = 32

[[solutions]]
name = "naive.cpp"
allow_tle = true

[params]
N_MIN = 0
N_MAX = 500_000
Q_MIN = 1
Q_MAX = 500_000
A_MIN = 0
A_MAX = 1_000_000_000
Loading