-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize: Dynamic Point Set Rectangle Affine Rectangle Sum
Generators, solutions and checkers.
- Loading branch information
Showing
22 changed files
with
2,249 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/checker.cpp
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
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"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/example_00.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
3 7 | ||
2 0 1 | ||
6 2 10 | ||
5 4 100 | ||
2 1 1 7 7 | ||
0 5 6 1000 | ||
0 5 1 10000 | ||
3 1 5 7 7 0 100000 | ||
1 1 1000000 | ||
2 5 4 7 5 | ||
2 5 1 7 7 |
70 changes: 70 additions & 0 deletions
70
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/gen_random.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/python3 | ||
|
||
import random as rd | ||
import argparse as agp | ||
|
||
parser = agp.ArgumentParser(description="Generate a random test case.") | ||
|
||
parser.add_argument('N_MAX', type=int, help='Number of initial points.') | ||
parser.add_argument('Q_MAX', type=int, help='Number of queries.') | ||
parser.add_argument('COORD_MAX', type=int, nargs='?', default=10**9, help='Range of coord x.') | ||
parser.add_argument('COORD_MAX', type=int, nargs='?', default=10**9, help='Range of coord y.') | ||
parser.add_argument('MOD - 1', type=int, nargs='?', default=998244352, help='Range of initial weight.') | ||
parser.add_argument('-OP', nargs='*', default=[0, 1, 2, 3], help='Type of operations.') | ||
|
||
args = parser.parse_args() | ||
|
||
N_MAX = args.N_MAX | ||
Q_MAX = args.Q_MAX | ||
COORD_MAX = args.COORD_MAX | ||
COORD_MAX = args.COORD_MAX | ||
MOD - 1 = args.MOD - 1 | ||
OP = list(map(int, args.OP)) | ||
|
||
assert set(OP).issubset({0, 1, 2, 3}) | ||
|
||
n = rd.randint(1, N_MAX) | ||
q = rd.randint(1, Q_MAX) | ||
|
||
print(n, q) | ||
|
||
size = n | ||
|
||
for _ in range(n): | ||
print(rd.randint(0, COORD_MAX), rd.randint(0, COORD_MAX), rd.randint(0, MOD - 1)) | ||
|
||
for _ in range(q): | ||
|
||
op = rd.choice(OP) | ||
|
||
print(op, end=' ') | ||
|
||
if op == 0: | ||
print(rd.randint(0, COORD_MAX), rd.randint(0, COORD_MAX), rd.randint(0, MOD - 1)) | ||
size += 1 | ||
|
||
elif op == 1: | ||
print(rd.randrange(0, size), rd.randint(0, MOD - 1)) | ||
|
||
else: | ||
l = rd.randint(0, COORD_MAX) | ||
r = rd.randint(0, COORD_MAX) | ||
while l == r: | ||
l = rd.randint(0, COORD_MAX) | ||
r = rd.randint(0, COORD_MAX) | ||
|
||
d = rd.randint(0, COORD_MAX) | ||
u = rd.randint(0, COORD_MAX) | ||
while d == u: | ||
d = rd.randint(0, COORD_MAX) | ||
u = rd.randint(0, COORD_MAX) | ||
|
||
if l > r: | ||
l, r = r, l | ||
if d > u: | ||
d, u = u, d | ||
|
||
if op == 2: | ||
print(l, d, r, u) | ||
else: | ||
print(l, d, r, u, rd.randint(0, MOD - 1), rd.randint(0, MOD - 1)) |
56 changes: 56 additions & 0 deletions
56
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/many_affine_queries.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Adapted from gen_random.py | ||
|
||
#include <stdio.h> | ||
#include <tuple> | ||
#include "random.h" | ||
#include "../params.h" | ||
|
||
const int OP[] = {0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; | ||
|
||
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) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
} | ||
|
||
for (int i = 0; i < q; ++i) { | ||
int op = OP[gen.uniform<int>(0, sizeof(OP) / 4 - 1)]; | ||
printf("%d ", op); | ||
if (op == 0) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
++n; | ||
} | ||
else if (op == 1) { | ||
int idx = gen.uniform<int>(0, n - 1); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d\n", idx, w); | ||
} | ||
else { | ||
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX); | ||
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX); | ||
|
||
if (op == 2) { | ||
printf("%d %d %d %d\n", l, d, r, u); | ||
} | ||
else { // op == 3 | ||
int a = gen.uniform<int>(0, MOD - 1); | ||
int b = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d %d %d %d\n", l, d, r, u, a, b); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
56 changes: 56 additions & 0 deletions
56
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/many_points.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Adapted from gen_random.py | ||
|
||
#include <stdio.h> | ||
#include <tuple> | ||
#include "random.h" | ||
#include "../params.h" | ||
|
||
const int OP[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}; | ||
|
||
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) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
} | ||
|
||
for (int i = 0; i < q; ++i) { | ||
int op = OP[gen.uniform<int>(0, sizeof(OP) / 4 - 1)]; | ||
printf("%d ", op); | ||
if (op == 0) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
++n; | ||
} | ||
else if (op == 1) { | ||
int idx = gen.uniform<int>(0, n - 1); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d\n", idx, w); | ||
} | ||
else { | ||
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX); | ||
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX); | ||
|
||
if (op == 2) { | ||
printf("%d %d %d %d\n", l, d, r, u); | ||
} | ||
else { // op == 3 | ||
int a = gen.uniform<int>(0, MOD - 1); | ||
int b = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d %d %d %d\n", l, d, r, u, a, b); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
56 changes: 56 additions & 0 deletions
56
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/many_random_queries.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Adapted from gen_random.py | ||
|
||
#include <stdio.h> | ||
#include <tuple> | ||
#include "random.h" | ||
#include "../params.h" | ||
|
||
const int OP[] = {0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3}; | ||
|
||
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) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
} | ||
|
||
for (int i = 0; i < q; ++i) { | ||
int op = OP[gen.uniform<int>(0, sizeof(OP) / 4 - 1)]; | ||
printf("%d ", op); | ||
if (op == 0) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
++n; | ||
} | ||
else if (op == 1) { | ||
int idx = gen.uniform<int>(0, n - 1); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d\n", idx, w); | ||
} | ||
else { | ||
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX); | ||
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX); | ||
|
||
if (op == 2) { | ||
printf("%d %d %d %d\n", l, d, r, u); | ||
} | ||
else { // op == 3 | ||
int a = gen.uniform<int>(0, MOD - 1); | ||
int b = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d %d %d %d\n", l, d, r, u, a, b); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
56 changes: 56 additions & 0 deletions
56
data_structure/dynamic_point_set_rectangle_affine_rectangle_sum/gen/many_sum_queries.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Adapted from gen_random.py | ||
|
||
#include <stdio.h> | ||
#include <tuple> | ||
#include "random.h" | ||
#include "../params.h" | ||
|
||
const int OP[] = {0, 1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; | ||
|
||
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) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
} | ||
|
||
for (int i = 0; i < q; ++i) { | ||
int op = OP[gen.uniform<int>(0, sizeof(OP) / 4 - 1)]; | ||
printf("%d ", op); | ||
if (op == 0) { | ||
int x = gen.uniform<int>(0, COORD_MAX); | ||
int y = gen.uniform<int>(0, COORD_MAX); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d\n", x, y, w); | ||
++n; | ||
} | ||
else if (op == 1) { | ||
int idx = gen.uniform<int>(0, n - 1); | ||
int w = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d\n", idx, w); | ||
} | ||
else { | ||
auto [l, r] = gen.uniform_pair<int>(0, COORD_MAX); | ||
auto [d, u] = gen.uniform_pair<int>(0, COORD_MAX); | ||
|
||
if (op == 2) { | ||
printf("%d %d %d %d\n", l, d, r, u); | ||
} | ||
else { // op == 3 | ||
int a = gen.uniform<int>(0, MOD - 1); | ||
int b = gen.uniform<int>(0, MOD - 1); | ||
printf("%d %d %d %d %d %d\n", l, d, r, u, a, b); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.