Skip to content

Commit

Permalink
Merge pull request #1294 from NachiaVivias/persistent-lazyseg
Browse files Browse the repository at this point in the history
[問題追加] Persistent Range Affine Range Sum
  • Loading branch information
maspypy authored Jan 2, 2025
2 parents 6c21fd7 + db1fd99 commit d68e9b9
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 0 deletions.
62 changes: 62 additions & 0 deletions data_structure/persistent_range_affine_range_sum/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");
}
}
13 changes: 13 additions & 0 deletions data_structure/persistent_range_affine_range_sum/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
5 11
1 2 3 4 5
2 -1 0 5
0 -1 2 4 100 1
0 1 1 3 100 3
2 2 1 5
2 2 0 5
1 2 -1 1 3
2 5 0 1
2 5 0 2
2 5 0 3
2 5 0 4
2 5 0 5
12 changes: 12 additions & 0 deletions data_structure/persistent_range_affine_range_sum/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
10 10
98571302 347764691 874908879 522525408 665451426 585614689 752625419 867933974 588349757 331245164
2 -1 5 7
1 -1 -1 8 9
0 -1 3 4 559932567 67455332
1 1 1 0 8
1 3 1 5 9
2 1 1 2
1 2 -1 5 6
0 -1 0 9 703344909 379527638
2 6 2 9
2 7 7 9
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <cstdio>
#include "../params.h"
#include "random.h"

using namespace std;

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

vector<int> query_freq;
switch(seed){
case 0 :
query_freq = { 0 }; break;
case 1 :
query_freq = { 1 }; break;
case 2 :
query_freq = { 2 }; break;
case 3 :
query_freq = { 0,1 }; break;
case 4 :
query_freq = { 1,2 }; break;
case 5 :
query_freq = { 0,2 }; break;
default :
return 0;
}

int n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);
for (int i = 0; i < n; i++) {
int a = gen.uniform<int>(0, MOD - 1);
printf("%d", a);
if (i != n - 1) printf(" ");
}
printf("\n");

std::vector<int> data_enable;
data_enable.push_back(-1);
auto choose_data = [&]() -> int {
int i = gen.uniform(0, (int)data_enable.size() - 1);
return data_enable[i];
};

for (int i = 0; i < q; i++) {
int t = query_freq[gen.uniform<int>(0, (int)query_freq.size()-1)];
int k = choose_data();
printf("%d %d ", t, k);
if (t == 0) {
auto [l, r] = gen.uniform_pair(0, n);
int b = gen.uniform<int>(1, MOD - 1);
int c = gen.uniform<int>(0, MOD - 1);
printf("%d %d %d %d\n", l, r, b, c);
data_enable.push_back(i);
} else if(t == 1) {
int s = choose_data();
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d %d\n", s, l, r);
data_enable.push_back(i);
} else {
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d\n", l, r);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <cstdio>
#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 n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);
for (int i = 0; i < n; i++) {
int a = gen.uniform<int>(0, MOD - 1);
printf("%d", a);
if (i != n - 1) printf(" ");
}
printf("\n");

std::vector<int> data_enable;
data_enable.push_back(-1);
auto choose_data = [&]() -> int {
int i = gen.uniform(0, (int)data_enable.size() - 1);
return data_enable[i];
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 2);
int k = choose_data();
printf("%d %d ", t, k);
if (t == 0) {
auto [l, r] = gen.uniform_pair(0, n);
int b = gen.uniform<int>(1, MOD - 1);
int c = gen.uniform<int>(0, MOD - 1);
printf("%d %d %d %d\n", l, r, b, c);
data_enable.push_back(i);
} else if(t == 1) {
int s = choose_data();
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d %d\n", s, l, r);
data_enable.push_back(i);
} else {
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d\n", l, r);
}
}
return 0;
}
47 changes: 47 additions & 0 deletions data_structure/persistent_range_affine_range_sum/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "random.h"
#include <cstdio>
#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<int>(N_MIN, N_MAX);
int q = gen.uniform<int>(Q_MIN, Q_MAX);
printf("%d %d\n", n, q);
for (int i = 0; i < n; i++) {
int a = gen.uniform<int>(0, MOD - 1);
printf("%d", a);
if (i != n - 1) printf(" ");
}
printf("\n");

std::vector<int> data_enable;
data_enable.push_back(-1);
auto choose_data = [&]() -> int {
int i = gen.uniform(0, (int)data_enable.size() - 1);
return data_enable[i];
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 2);
int k = choose_data();
printf("%d %d ", t, k);
if (t == 0) {
auto [l, r] = gen.uniform_pair(0, n);
int b = gen.uniform<int>(1, MOD - 1);
int c = gen.uniform<int>(0, MOD - 1);
printf("%d %d %d %d\n", l, r, b, c);
} else if(t == 1) {
int s = choose_data();
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d %d\n", s, l, r);
} else {
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d\n", l, r);
}
}
return 0;
}
49 changes: 49 additions & 0 deletions data_structure/persistent_range_affine_range_sum/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "random.h"
#include <cstdio>
#include "../params.h"

using namespace std;

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

int n = seed % 10 + N_MIN;
int q = 1000;
printf("%d %d\n", n, q);
for (int i = 0; i < n; i++) {
int a = gen.uniform<int>(0, MOD - 1);
printf("%d", a);
if (i != n - 1) printf(" ");
}
printf("\n");

std::vector<int> data_enable;
data_enable.push_back(-1);
auto choose_data = [&]() -> int {
int i = gen.uniform(0, (int)data_enable.size() - 1);
return data_enable[i];
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 2);
int k = choose_data();
printf("%d %d ", t, k);
if (t == 0) {
auto [l, r] = gen.uniform_pair(0, n);
int b = gen.uniform<int>(1, MOD - 1);
int c = gen.uniform<int>(0, MOD - 1);
printf("%d %d %d %d\n", l, r, b, c);
data_enable.push_back(i);
} else if(t == 1) {
int s = choose_data();
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d %d\n", s, l, r);
data_enable.push_back(i);
} else {
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d\n", l, r);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "random.h"
#include <cstdio>
#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<int>(N_MIN, 2000);
int q = gen.uniform<int>(Q_MIN, 2000);
printf("%d %d\n", n, q);
for (int i = 0; i < n; i++) {
int a = gen.uniform<int>(0, MOD - 1);
printf("%d", a);
if (i != n - 1) printf(" ");
}
printf("\n");

std::vector<int> data_enable;
data_enable.push_back(-1);
auto choose_data = [&]() -> int {
int i = gen.uniform(0, (int)data_enable.size() - 1);
return data_enable[i];
};

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 2);
int k = choose_data();
printf("%d %d ", t, k);
if (t == 0) {
auto [l, r] = gen.uniform_pair(0, n);
int b = gen.uniform<int>(1, MOD - 1);
int c = gen.uniform<int>(0, MOD - 1);
printf("%d %d %d %d\n", l, r, b, c);
data_enable.push_back(i);
} else if(t == 1) {
int s = choose_data();
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d %d\n", s, l, r);
data_enable.push_back(i);
} else {
auto [l, r] = gen.uniform_pair(0, n);
printf("%d %d\n", l, r);
}
}
return 0;
}
Loading

0 comments on commit d68e9b9

Please sign in to comment.