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

Add range_chmin_chmax_add_range_sum #257

Merged
merged 4 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/range_chmin_chmax_add_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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
5 7
1 2 3 4 5
3 0 5
2 2 4 100
3 0 3
0 1 3 10
3 2 5
1 2 5 20
3 0 5
50 changes: 50 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/gen/max_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "random.h"
#include <iostream>
#include <tuple>
#include <vector>
#include "../params.h"
#include "../segtree.hpp"

using namespace std;

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

int n = N_AND_Q_MAX;
int q = N_AND_Q_MAX;
printf("%d %d\n", n, q);
vector<typename min_max_monoid::value_type> init(n);
for (int i = 0; i < n; i++) {
long long a = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%lld", a);
if (i != n - 1) printf(" ");
init[i] = { a, a };
}
printf("\n");
chmin_chmax_add_min_max_segment_tree segtree(init.begin(), init.end());

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 3);
int l, r;
tie(l, r) = gen.uniform_pair(0, n - 1);
r++;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(0, n)?(さっきの #253 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました (small.cpp だけ修正して他を忘れていました)

if (t == 0) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { b, LLONG_MIN, 0ll });
} else if (t == 1) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, b, 0ll });
} else if (t == 2) {
auto c = segtree.range_get(0, n);
long long b = gen.uniform<long long>(-A_ABS_MAX - c.min, A_ABS_MAX - c.max);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, LLONG_MIN, b });
printf("%d %d %d %lld\n", t, l, r, b);
} else {
printf("%d %d %d\n", t, l, r);
}
}
return 0;
}
50 changes: 50 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/gen/medium.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "random.h"
#include <iostream>
#include <tuple>
#include <vector>
#include "../params.h"
#include "../segtree.hpp"

using namespace std;

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

int n = gen.uniform<int>(1, 2000);
int q = gen.uniform<int>(1, 2000);
printf("%d %d\n", n, q);
vector<typename min_max_monoid::value_type> init(n);
for (int i = 0; i < n; i++) {
long long a = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%lld", a);
if (i != n - 1) printf(" ");
init[i] = { a, a };
}
printf("\n");
chmin_chmax_add_min_max_segment_tree segtree(init.begin(), init.end());

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 3);
int l, r;
tie(l, r) = gen.uniform_pair(0, n - 1);
r++;
if (t == 0) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { b, LLONG_MIN, 0ll });
} else if (t == 1) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, b, 0ll });
} else if (t == 2) {
auto c = segtree.range_get(0, n);
long long b = gen.uniform<long long>(-A_ABS_MAX - c.min, A_ABS_MAX - c.max);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, LLONG_MIN, b });
printf("%d %d %d %lld\n", t, l, r, b);
} else {
printf("%d %d %d\n", t, l, r);
}
}
return 0;
}
50 changes: 50 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "random.h"
#include <iostream>
#include <tuple>
#include <vector>
#include "../params.h"
#include "../segtree.hpp"

using namespace std;

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

int n = gen.uniform<int>(1, N_AND_Q_MAX);
int q = gen.uniform<int>(1, N_AND_Q_MAX);
printf("%d %d\n", n, q);
vector<typename min_max_monoid::value_type> init(n);
for (int i = 0; i < n; i++) {
long long a = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%lld", a);
if (i != n - 1) printf(" ");
init[i] = { a, a };
}
printf("\n");
chmin_chmax_add_min_max_segment_tree segtree(init.begin(), init.end());

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 3);
int l, r;
tie(l, r) = gen.uniform_pair(0, n - 1);
r++;
if (t == 0) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { b, LLONG_MIN, 0ll });
} else if (t == 1) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, b, 0ll });
} else if (t == 2) {
auto c = segtree.range_get(0, n);
long long b = gen.uniform<long long>(-A_ABS_MAX - c.min, A_ABS_MAX - c.max);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, LLONG_MIN, b });
printf("%d %d %d %lld\n", t, l, r, b);
} else {
printf("%d %d %d\n", t, l, r);
}
}
return 0;
}
51 changes: 51 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/gen/small.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "random.h"
#include <cassert>
#include <iostream>
#include <tuple>
#include <vector>
#include "../params.h"
#include "../segtree.hpp"

using namespace std;

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

assert (0 <= seed and seed < 10);
int n = seed + 1; // use the seed, which is an index in the test set, to check n = 2^k - 1, 2^k, 2^k + 1
int q = 20;
printf("%d %d\n", n, q);
vector<typename min_max_monoid::value_type> init(n);
for (int i = 0; i < n; i++) {
long long a = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%lld", a);
if (i != n - 1) printf(" ");
init[i] = { a, a };
}
printf("\n");
chmin_chmax_add_min_max_segment_tree segtree(init.begin(), init.end());

for (int i = 0; i < q; i++) {
int t = gen.uniform(0, 3);
int l, r;
tie(l, r) = gen.uniform_pair(0, n);
if (t == 0) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { b, LLONG_MIN, 0ll });
} else if (t == 1) {
long long b = gen.uniform<long long>(-A_ABS_MAX, A_ABS_MAX);
printf("%d %d %d %lld\n", t, l, r, b);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, b, 0ll });
} else if (t == 2) {
auto c = segtree.range_get(0, n);
long long b = gen.uniform<long long>(-A_ABS_MAX - c.min, A_ABS_MAX - c.max);
segtree.range_apply(l, r, (typename chmin_chmax_add_monoid::value_type) { LLONG_MAX, LLONG_MIN, b });
printf("%d %d %d %lld\n", t, l, r, b);
} else {
printf("%d %d %d\n", t, l, r);
}
}
return 0;
}
42 changes: 42 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"example_00.in": "8691e362b7409e5566abe9cdf2ba2d1659b46edef70dabbe485f750c3f185cfc",
"example_00.out": "a98cad4d512832ba33f51cab84fb6a1a91ebccda726f28a96b95fbb5eb04caba",
"max_random_00.in": "6df3ef8d10a8d3ce957a05601fc54dc9281df261c55cdf8e6fcec1eb00ad55b9",
"max_random_00.out": "943653ffcfbb99aef472509dae13b128c45f39e46587c9f6265e73d2b333e994",
"max_random_01.in": "15f3b5b82996b6eb0fe4d10e685bd91e6269fd8c058f9cb2e0483bfb2b038336",
"max_random_01.out": "9083f76e23a2feabd50d3a8258e8ee7db29eb34264be8d0e110eb4d4beba817b",
"max_random_02.in": "5f3f3ab2b2565d76e9e78ed570fde4dcd7b292988833f60ba097208caf73d4f0",
"max_random_02.out": "2c496372fd9fea4d0df77ecd8f3a43a06673bcff0c80189d3fd3e5e2d125d09d",
"medium_00.in": "ead716b7af87b92ffd462737540f0341757f8b65345ed0577f3a7bc1e6deeb67",
"medium_00.out": "19e94be2876945b11525c3088981d901f12dd0b43eec1607f8157cbe3f052de0",
"medium_01.in": "59fc696c044f0001824072cc7d92d5ccdec57b0b40dca39c862c1759f7e5f58f",
"medium_01.out": "2c57bb800fa65ae45d4bfa9bcb589ad0069b8ad026aeedcf25621d015fa8e276",
"medium_02.in": "0473ff81c64f2de287b119ee4a7a9ce3a7d1aacd72d1de88d9b5e4a5c095b388",
"medium_02.out": "219ba95c207fb2e933ae636af95e25e754cbec1d37da50af8b7b5302a5773c65",
"random_00.in": "fe25991270b835e4f2765f319c3b9e90357a0b7d293b63d443b8b1f1192e804d",
"random_00.out": "caa3d1d9b2fd82ee58377ef26eb627ebc817522106021eb96c8403bfd1956c0b",
"random_01.in": "d1bab988cb935301477ced8b32ed14fcfdd0106f4360d242268164e0c757604c",
"random_01.out": "9f9210e1ed7826139bf10876d928502d8112d268b1059d0c574b3e6a818323f6",
"random_02.in": "d4aa4113635fe6f07f11dea1a5fb4e804a12146977534e1dee5fcf4c5e08cdb2",
"random_02.out": "f8913512115d01aca1395fe115176ef3392088479612738a674ce7951f426caf",
"small_00.in": "a55a5fe923e9cfd4b6fc86f4d1fa6524ef58d2e00805f57a3a87a4f2e0195b4a",
"small_00.out": "6088af775600493389506c87350d8a8e292826f5c1d1dc19bbb5f7a1065952e6",
"small_01.in": "ef075086c922bfe337c0e3fbd4d1d7bd37a4e4854e9092c7bd718c764127595b",
"small_01.out": "21fa8fc9319dda4572b130e745aa2ffe81ca4deb3cbdae4d3865fbbe313fbb73",
"small_02.in": "77d59563adb078370fd91b4c5b9b6902b4d0e929f37998eb06fcf5216c0a134e",
"small_02.out": "503618eaa7a866f70ae46dc4d420808e064abd4ecd3d6c6a1e90a77d0400173b",
"small_03.in": "406feb996eeab64740ea3cb9df8685052dee08533306b78c359e2716762fbe67",
"small_03.out": "5494425d43b40baefd2e304f6a77d0316e2fd1cd79c7b25d012d50aa3df42d82",
"small_04.in": "88abc6f643e49add33082ae38954ee1b9a07f99c15aabea61355c9df7678b6dc",
"small_04.out": "35be01a9eda5f3c9648b67428bfa83da4cc3f8fb429020304ba8dfa056ee2664",
"small_05.in": "15ec25bebea4618e09c6acf124c8c226bb3e07bbdbe209899082534aa3d10ba3",
"small_05.out": "8ad17c34388ab2ca7f2ef72853dd852294d7ee10b484ade1d36f4c72d32cb124",
"small_06.in": "f2547c1acd50f28ec8883ab3726e5fe05d1064a227c6ae2f07d4c63e69b95443",
"small_06.out": "ed936a67f1657642e8073e21f95103196229cc77455d6482ebd59a08c912cfc9",
"small_07.in": "ece284376fe38557c8080bfd1de0f356d453ebad583918cd8c5da57eec147d29",
"small_07.out": "3a3d997f842b7e88643c56a04e69ad0bcebe8e84de7687fc505970b2eb8f7490",
"small_08.in": "de54614c264210e47609898635bcfb6440f059a0895a1a078c2d831ef7a732eb",
"small_08.out": "f1270aed58f4d85cde341cfcdb81773760f0e9609bc6764bfc2fca05d8d229c3",
"small_09.in": "9e7e4fe32e402a6a5a928a8ef9531fcebf201f04eac1f222f1aa47d2cf842a70",
"small_09.out": "50bac94959608ff81cfdc25cca9b674fd9fe38f1c8bb3ea50c031339f1d6acdc"
}
27 changes: 27 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
title = 'Range Chmin Chmax Add Range Sum'
timelimit = 5.0
forum = "https://github.com/yosupo06/library-checker-problems/issues/243"
[[tests]]
name = "example.in"
number = 1

[[tests]]
name = "small.cpp"
number = 10
[[tests]]
name = "medium.cpp"
number = 3
[[tests]]
name = "random.cpp"
number = 3
[[tests]]
name = "max_random.cpp"
number = 3

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

[params]
N_AND_Q_MAX = 500_000
A_ABS_MAX = 1_000_000_000_000
Loading