Skip to content

Commit

Permalink
Merge branch 'yosupo06:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maspypy authored Nov 16, 2023
2 parents b87615c + f1322bb commit 287258a
Show file tree
Hide file tree
Showing 81 changed files with 2,435 additions and 139 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/all-generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ on:
- cron: "0 0 * * *"

jobs:
deploy:
generate:
strategy:
matrix:
include:
- os: ubuntu-latest
cxx: g++-12
- os: ubuntu-latest
cxx: g++-13
- os: macos-latest
cxx: clang++
- os: windows-latest
cxx: g++
uses: ./.github/workflows/generate.yml
with:
force-generate: true
os: ${{ matrix.os }}
cxx: ${{ matrix.cxx }}
force-generate: true
14 changes: 13 additions & 1 deletion .github/workflows/diff-generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:

jobs:
generate:
strategy:
matrix:
include:
- os: ubuntu-latest
cxx: g++-12
- os: ubuntu-latest
cxx: g++-13
- os: macos-latest
cxx: clang++
- os: windows-latest
cxx: g++
uses: ./.github/workflows/generate.yml
with:
force-generate: false
os: ${{ matrix.os }}
cxx: ${{ matrix.cxx }}
121 changes: 22 additions & 99 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,113 +3,31 @@ name: Generate test
on:
workflow_dispatch:
inputs:
os:
type: string
required: true
cxx:
type: string
required: true
force-generate:
description: Ignore cache and force generate
default: false
type: boolean
enable-gcc-ubuntu-generate:
description: Enable gcc-ubuntu-generate
default: true
type: boolean
enable-clang-mac-generate:
description: Enable clang-mac-generate
default: true
type: boolean
enable-mingw-windows-generate:
description: Enable mingw-windows-generate
default: true
type: boolean
workflow_call:
inputs:
os:
type: string
required: true
cxx:
type: string
required: true
force-generate:
default: false
type: boolean
enable-gcc-ubuntu-generate:
default: true
type: boolean
enable-clang-mac-generate:
default: true
type: boolean
enable-mingw-windows-generate:
default: true
type: boolean

jobs:
gcc-ubuntu-generate:
if: ${{ inputs.enable-gcc-ubuntu-generate }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -r requirements.txt
- name: Restore versions.json
uses: actions/cache/restore@v3
if: ${{ !inputs.force-generate }}
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-

- name: Run generate.py
run: |
ulimit -s unlimited
./generate_test.py TestGenerateAll
env:
ENABLE_GENERATE_TEST: 1
VERSIONS_CACHE_PATH: versions.json

- name: Save versions.json
uses: actions/cache/save@v3
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-${{ hashFiles('versions.json') }}

clang-mac-generate:
if: ${{ inputs.enable-clang-mac-generate }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -r requirements.txt
- name: Restore versions.json
uses: actions/cache/restore@v3
if: ${{ !inputs.force-generate }}
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-

- name: Run generate.py
run: |
./generate_test.py TestGenerateAll
env:
CXX: clang++
ENABLE_GENERATE_TEST: 1
VERSIONS_CACHE_PATH: versions.json

- name: Save versions.json
uses: actions/cache/save@v3
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-${{ hashFiles('versions.json') }}

mingw-windows-generate:
if: ${{ inputs.enable-mingw-windows-generate }}
runs-on: windows-latest
generate:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v3

Expand All @@ -127,17 +45,22 @@ jobs:
if: ${{ !inputs.force-generate }}
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-
key: ${{ runner.os }}-(${{ inputs.cxx }})-versions-cache-

- name: Run generate.py
run: |
python generate_test.py TestGenerateAll
if [ "$RUNNER_OS" == "Linux" ]; then
ulimit -s unlimited
fi
python3 generate_test.py TestGenerateAll
shell: bash
env:
CXX: ${{ inputs.cxx }}
ENABLE_GENERATE_TEST: 1
VERSIONS_CACHE_PATH: versions.json

- name: Save versions.json
uses: actions/cache/save@v3
with:
path: versions.json
key: ${{ runner.os }}-versions-cache-${{ hashFiles('versions.json') }}
key: ${{ runner.os }}-(${{ inputs.cxx }})-versions-cache-${{ hashFiles('versions.json') }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <vector>
#include <cassert>
#include <cstdint>

int ri() {
int n;
Expand Down
1 change: 1 addition & 0 deletions datastructure/predecessor_problem/sol/correct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <array>
#include <cassert>
#include <cstdint>
#include <string>
#include <type_traits>
using namespace std;
Expand Down
3 changes: 3 additions & 0 deletions datastructure/range_chmin_chmax_add_range_sum/sol/correct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <cstdint>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdint>

#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdint>

#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vector>
#include <tuple>
#include <cassert>
#include <cstdint>
#include <algorithm>

using namespace std;
Expand Down
23 changes: 11 additions & 12 deletions datastructure/unionfind/gen/path.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#include "random.h"
#include "../params.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <utility>
#include <vector>
#include <algorithm>

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

const int N = 200000;
const int Q = 200000;

assert(N == Q);
const int N_AND_Q = std::min(N_MAX, Q_MAX);

struct query_type {
int t;
int u;
int v;
};

std::vector<query_type> qs(Q);
std::vector<query_type> qs(N_AND_Q);

// unused-but-set-variable が誤反応するようなので、抑制する
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
Expand All @@ -30,14 +29,14 @@ int main(int, char *argv[]) {
#endif
if (seed == 0 || seed == 1) {
// parent[v] = u 最悪ケース
const int K = 2 * N / 3;
const int K = 2 * N_AND_Q / 3;
for (int i = 0; i != K; i += 1) {
auto &[t, u, v] = qs[i];
t = 0;
u = i + 1;
v = 0;
}
for (int i = K; i != Q; i += 1) {
for (int i = K; i != N_AND_Q; i += 1) {
auto &[t, u, v] = qs[i];
t = 1;
u = 0;
Expand All @@ -46,17 +45,17 @@ int main(int, char *argv[]) {
}
if (seed == 2 || seed == 3) {
// parent[v] = u 深さ最大
for (int i = 0; i != Q - 1; i += 1) {
for (int i = 0; i != N_AND_Q - 1; i += 1) {
auto &[t, u, v] = qs[i];
t = 0;
u = i + 1;
v = i;
}
{
auto &[t, u, v] = qs[Q - 1];
auto &[t, u, v] = qs[N_AND_Q - 1];
t = 0;
u = 0;
v = Q - 1;
v = N_AND_Q - 1;
}
}
if (seed == 1 || seed == 3) {
Expand All @@ -69,10 +68,10 @@ int main(int, char *argv[]) {
#pragma GCC diagnostic pop
#endif

std::vector<int> p(N);
std::vector<int> p(N_AND_Q);
std::iota(p.begin(), p.end(), 0);
gen.shuffle(p.begin(), p.end());
std::printf("%d %d\n", N, Q);
std::printf("%d %d\n", N_AND_Q, N_AND_Q);
for (const auto &[t, u, v] : qs) {
std::printf("%d %d %d\n", t, p[u], p[v]);
}
Expand Down
5 changes: 3 additions & 2 deletions datastructure/unionfind/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
#include "random.h"
#include "../params.h"

using namespace std;

Expand All @@ -8,8 +9,8 @@ int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = gen.uniform(1, 200000);
int q = gen.uniform(1, 200000);
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 < q; i++) {
int ty = gen.uniform_bool();
Expand Down
4 changes: 4 additions & 0 deletions datastructure/unionfind/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ forum = 'https://github.com/yosupo06/library-checker-problems/issues/33'
[[tests]]
name = "path.cpp"
number = 4

[params]
N_MAX = 200_000
Q_MAX = 200_000
4 changes: 2 additions & 2 deletions datastructure/unionfind/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ $N$ 頂点 $0$ 辺の無向グラフに $Q$ 個のクエリが飛んできます

## @{keyword.constraints}

- $1 \leq N \leq 200,000$
- $1 \leq Q \leq 200,000$
- $1 \leq N \leq @{param.N_MAX}$
- $1 \leq Q \leq @{param.Q_MAX}$
- $0 \leq u_i, v_i \lt N$

## @{keyword.input}
Expand Down
2 changes: 2 additions & 0 deletions graph/min_cost_b_flow/sol/correct.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <limits>
#include <queue>
#include <tuple>
#include <vector>
#include <cstdio>

enum Objective {
MINIMIZE = 1,
Expand Down
2 changes: 2 additions & 0 deletions graph/min_cost_b_flow/sol/ssp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <tuple>
#include <vector>
#include <limits>
#include <cstdio>
#include <cstdint>

enum Objective {
MINIMIZE = 1,
Expand Down
4 changes: 3 additions & 1 deletion graph/vertex_add_range_contour_sum_on_tree/sol/correct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ struct SegmentTree {
SegmentTree() : SegmentTree(0) {}
SegmentTree(int n) : _n(n), _seg(2 * n, e()) {}
SegmentTree(const std::vector<value_type> &a) : _n(a.size()), _seg(2 * _n) {
std::copy(a.begin(), a.end(), _seg.begin() + _n);
for (int i = 0; i < _n; i++) {
_seg[_n + i] = a[i];
}
for (int i = _n - 1; i > 0; --i) {
_seg[i] = op(_seg[2 * i + 0], _seg[2 * i + 1]);
}
Expand Down
Loading

0 comments on commit 287258a

Please sign in to comment.