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

問題追加 rectangle_add_point_get #1072

Merged
merged 4 commits into from
Jan 18, 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 datastructure/rectangle_add_point_get/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");
}
}
14 changes: 14 additions & 0 deletions datastructure/rectangle_add_point_get/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
4 9
1 2 2 3 1
1 1 2 5 10
2 2 5 5 100
3 1 5 2 1000
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
11 changes: 11 additions & 0 deletions datastructure/rectangle_add_point_get/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2 8
1 2 2 3 1
1 1 2 5 10
1 1 2
1 2 3
0 1 1 3 3 100
1 1 2
1 2 3
0 2 1 3 5 1000
1 1 2
1 2 3
44 changes: 44 additions & 0 deletions datastructure/rectangle_add_point_get/gen/many_points.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
bool rect = gen.uniform<int>(0, 10) == 0;
if (rect) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
44 changes: 44 additions & 0 deletions datastructure/rectangle_add_point_get/gen/many_rectangles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
bool rect = gen.uniform<int>(0, 10) > 0;
if (rect) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
44 changes: 44 additions & 0 deletions datastructure/rectangle_add_point_get/gen/max_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
int t = gen.uniform<int>(0, 1);
if (t == 0) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
48 changes: 48 additions & 0 deletions datastructure/rectangle_add_point_get/gen/power_of_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = 1;
for (; n + n <= N_MAX; n <<= 1)
;
int q = 1;
for (; q + q <= Q_MAX; q <<= 1)
;
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
int t = gen.uniform<int>(0, 1);
if (t == 0) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
44 changes: 44 additions & 0 deletions datastructure/rectangle_add_point_get/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = gen.uniform<int>(1, N_MAX);
int q = gen.uniform<int>(1, Q_MAX);
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
int t = gen.uniform<int>(0, 1);
if (t == 0) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
47 changes: 47 additions & 0 deletions datastructure/rectangle_add_point_get/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

#define SMALL_N_MAX 1000
#define SMALL_Q_MAX 1000

tuple<int, int, int, int, int> random_rect(Random& gen) {
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX);
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX);
int w = gen.uniform<int>(0, WEIGHT_MAX);
return {l, d, r, u, w};
}

pair<int, int> random_pt(Random& gen) {
int x = gen.uniform<int>(0, COORD_MAX);
int y = gen.uniform<int>(0, COORD_MAX);
return {x, y};
}

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

int n = gen.uniform(1, SMALL_N_MAX);
int q = gen.uniform(1, SMALL_Q_MAX);
printf("%d %d\n", n, q);

for (int i = 0; i < n; i++) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d\n", l, d, r, u, w);
}
for (int i = 0; i < q; i++) {
int t = gen.uniform<int>(0, 1);
if (t == 0) {
auto [l, d, r, u, w] = random_rect(gen);
printf("%d %d %d %d %d %d\n", 0, l, d, r, u, w);
} else {
auto [x, y] = random_pt(gen);
printf("%d %d %d\n", 1, x, y);
}
}
return 0;
}
Loading