Skip to content

Commit

Permalink
Merge pull request #1283 from maspypy/rars
Browse files Browse the repository at this point in the history
問題追加 Range Affine Range Sum (Large Array)
  • Loading branch information
maspypy authored Jan 26, 2025
2 parents f7b5acd + a840cc2 commit e5610a0
Show file tree
Hide file tree
Showing 18 changed files with 955 additions and 2 deletions.
62 changes: 62 additions & 0 deletions data_structure/range_affine_range_sum_large_array/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");
}
}
43 changes: 43 additions & 0 deletions data_structure/range_affine_range_sum_large_array/gen/dense.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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);

int ws[] = {1, 1000, 500000};
int w = ws[seed % 3];

int L = gen.uniform<int>(0, n - w);
int R = L + w;

auto idx = [&]() -> int { return gen.uniform<int>(L, R - 1); };

auto idx2 = [&]() -> pair<int, int> {
int a = idx(), b = idx();
if (a > b) swap(a, b);
++b;
return {a, b};
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 1);
auto p = idx2();

if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1000000000 6
0 0 100 10 1
1 10 90
1 0 1000000000
0 50 10000 10 1
1 10 90
1 0 1000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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 < q; i++) {
int t = gen.uniform(0, 100);
t = (t == 0 ? 1 : 0);
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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 < q; i++) {
int t = gen.uniform(0, 100);
t = (t == 0 ? 0 : 1);
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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 < q; i++) {
int t = gen.uniform(0, 1);
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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);

auto idx = [&]() -> int {
int t = gen.uniform<int>(0, 2);
if (t == 0) return gen.uniform<int>(0, n - 1);
if (t == 1) return gen.uniform<int>(0, 1000);
if (t == 2) return gen.uniform<int>(n - 1000, n - 1);
return 0;
};

auto idx2 = [&]() -> pair<int, int> {
int a = idx(), b = idx();
if (a > b) swap(a, b);
++b;
return {a, b};
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 1);
auto p = idx2();
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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 < q; i++) {
int t = (i < q / 2 ? 0 : 1);
if (gen.uniform<int>(0, 100) == 0) t = 1 - t;
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
26 changes: 26 additions & 0 deletions data_structure/range_affine_range_sum_large_array/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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

int n = gen.uniform(1LL, N_MAX);
int q = gen.uniform(1LL, Q_MAX);
printf("%d %d\n", n, q);
for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 1);
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
26 changes: 26 additions & 0 deletions data_structure/range_affine_range_sum_large_array/gen/small_N.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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

int n = seed + 1;
int q = Q_MAX;
printf("%d %d\n", n, q);
for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 1);
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
34 changes: 34 additions & 0 deletions data_structure/range_affine_range_sum_large_array/gen/small_Q.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "random.h"
#include <iostream>
#include "../params.h"

using namespace std;

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

int n = N_MAX;
int q;
vector<int> ts;
if (seed == 0) { q = 1, ts = {0}; }
if (seed == 1) { q = 1, ts = {1}; }
if (seed == 2) { q = 2, ts = {0, 0}; }
if (seed == 3) { q = 2, ts = {0, 1}; }
if (seed == 4) { q = 2, ts = {1, 0}; }
if (seed == 5) { q = 2, ts = {1, 1}; }

printf("%d %d\n", n, q);
for (int i = 0; i < q; i++) {
int t = ts[i];
auto p = gen.uniform_pair(0, n);
if (t == 0) {
int b = gen.uniform(1LL, MOD - 1);
int c = gen.uniform(0LL, MOD - 1);
printf("%d %d %d %d %d\n", t, p.first, p.second, b, c);
} else {
printf("%d %d %d\n", t, p.first, p.second);
}
}
return 0;
}
Loading

0 comments on commit e5610a0

Please sign in to comment.