0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:28:48 +00:00

Compare commits

..

4 Commits

94 changed files with 671 additions and 0 deletions

113
LibreOJ/2086/2086.cpp Normal file
View File

@ -0,0 +1,113 @@
#include <iostream>
#include <algorithm>
#include <limits>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
struct node {
int l, r, m, d;
node(int _l = 0, int _r = 0)
: l(_l), r(_r), m(0), d(0) {}
} tr[N << 3];
void pushup(int u) {
tr[u].m = std::max(tr[u << 1].m, tr[u << 1 | 1].m);
}
void pushdown(int u) {
if (!tr[u].d) return;
tr[u << 1].d += tr[u].d;
tr[u << 1 | 1].d += tr[u].d;
tr[u << 1].m += tr[u].d;
tr[u << 1 | 1].m += tr[u].d;
tr[u].d = 0;
}
void build(int u, int l, int r) {
tr[u] = node(l, r);
if (l == r) return;
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
}
void modify(int u, int l, int r, int v) {
if (l <= tr[u].l && tr[u].r <= r) {
tr[u].d += v;
tr[u].m += v;
return;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) modify(u << 1, l, r, v);
if (r > mid) modify(u << 1 | 1, l, r, v);
pushup(u);
}
int n, m, ans = std::numeric_limits<int>::max();
std::pair<int, int> seg[N];
std::vector<int> nums;
int len(int p) {
return nums[seg[p].second - 1] - nums[seg[p].first - 1];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> seg[i].first >> seg[i].second;
nums.emplace_back(seg[i].first);
nums.emplace_back(seg[i].second);
}
std::sort(seg + 1, seg + 1 + n, [&](const std::pair<int, int> &a, const std::pair<int, int> &b) {
return a.second - a.first < b.second - b.first;
});
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
for (int i = 1; i <= n; i++) {
seg[i].first = std::lower_bound(nums.begin(), nums.end(), seg[i].first) - nums.begin() + 1;
seg[i].second = std::lower_bound(nums.begin(), nums.end(), seg[i].second) - nums.begin() + 1;
}
build(1, 1, nums.size());
for (int i = 1, l = 1; i <= n; i++) {
modify(1, seg[i].first, seg[i].second, 1);
while (tr[1].m >= m) {
ans = std::min(ans, len(i) - len(l));
modify(1, seg[l].first, seg[l].second, -1);
l++;
}
}
cout << (ans == std::numeric_limits<int>::max() ? -1 : ans) << endl;
return 0;
}

BIN
LibreOJ/2086/data/interval1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2086/data/interval9.out (Stored with Git LFS) Normal file

Binary file not shown.

113
Luogu/P1712/P1712.cpp Normal file
View File

@ -0,0 +1,113 @@
#include <iostream>
#include <algorithm>
#include <limits>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
struct node {
int l, r, m, d;
node(int _l = 0, int _r = 0)
: l(_l), r(_r), m(0), d(0) {}
} tr[N << 3];
void pushup(int u) {
tr[u].m = std::max(tr[u << 1].m, tr[u << 1 | 1].m);
}
void pushdown(int u) {
if (!tr[u].d) return;
tr[u << 1].d += tr[u].d;
tr[u << 1 | 1].d += tr[u].d;
tr[u << 1].m += tr[u].d;
tr[u << 1 | 1].m += tr[u].d;
tr[u].d = 0;
}
void build(int u, int l, int r) {
tr[u] = node(l, r);
if (l == r) return;
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
}
void modify(int u, int l, int r, int v) {
if (l <= tr[u].l && tr[u].r <= r) {
tr[u].d += v;
tr[u].m += v;
return;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) modify(u << 1, l, r, v);
if (r > mid) modify(u << 1 | 1, l, r, v);
pushup(u);
}
int n, m, ans = std::numeric_limits<int>::max();
std::pair<int, int> seg[N];
std::vector<int> nums;
int len(int p) {
return nums[seg[p].second - 1] - nums[seg[p].first - 1];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> seg[i].first >> seg[i].second;
nums.emplace_back(seg[i].first);
nums.emplace_back(seg[i].second);
}
std::sort(seg + 1, seg + 1 + n, [&](const std::pair<int, int> &a, const std::pair<int, int> &b) {
return a.second - a.first < b.second - b.first;
});
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
for (int i = 1; i <= n; i++) {
seg[i].first = std::lower_bound(nums.begin(), nums.end(), seg[i].first) - nums.begin() + 1;
seg[i].second = std::lower_bound(nums.begin(), nums.end(), seg[i].second) - nums.begin() + 1;
}
build(1, 1, nums.size());
for (int i = 1, l = 1; i <= n; i++) {
modify(1, seg[i].first, seg[i].second, 1);
while (tr[1].m >= m) {
ans = std::min(ans, len(i) - len(l));
modify(1, seg[l].first, seg[l].second, -1);
l++;
}
}
cout << (ans == std::numeric_limits<int>::max() ? -1 : ans) << endl;
return 0;
}

47
S2OJ/1585/1585.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 305;
const int mod = 998244353;
int n, k, a[N], f[N][N][N], g[N][N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
std::sort(a + 1, a + 1 + n);
for (int i = 0; i <= k; i++) {
g[0][0][i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
for (int l = 0; l <= k; l++) {
int p = std::min(a[i] - a[i - 1] + l, k);
if (p < 0) continue;
if (l <= j) {
f[i][j][l] = (f[i][j][l] + g[i - 1][j - l][p]) % mod;
}
g[i][j][l] = (f[i][j][l] + (l ? g[i][j][l - 1] : 0)) % mod;
}
}
}
cout << g[n][k][k] << endl;
return 0;
}

BIN
S2OJ/1585/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1585/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

128
S2OJ/1586/1586.cpp Normal file
View File

@ -0,0 +1,128 @@
#include <iostream>
#include <algorithm>
#include <array>
#include <numeric>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int INF = 0x3f3f3f3f;
class DSU {
private:
std::vector<int> fa;
public:
DSU(int _n = 0)
: fa(_n) {
std::iota(fa.begin(), fa.end(), 0);
}
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
bool merge(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
return x != y;
}
};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
std::vector<int> a(n), b(n);
std::vector<std::tuple<int, int, int>> edges;
std::vector<bool> f(1 << n, false);
for (int i = 0, u, v, w; i < m; i++) {
cin >> u >> v >> w;
edges.emplace_back(u - 1, v - 1, w);
}
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
auto check = [&](int s) -> bool {
auto in_block = [&](int x) -> bool {
return s >> x & 1;
};
int sum = 0, root = 0;
DSU dsu(n);
std::vector<std::tuple<int, int, int>> block_edges;
for (auto& edge : edges) {
int u, v;
std::tie(u, v, std::ignore) = edge;
if (in_block(u) && in_block(v)) {
block_edges.emplace_back(edge);
}
}
std::sort(block_edges.begin(), block_edges.end(), [](auto& lhs, auto& rhs) {
return std::get<2>(lhs) < std::get<2>(rhs);
});
for (int i = 0; i < n; i++) {
if (in_block(i)) sum += a[i] - b[i];
}
for (auto& edge : block_edges) {
int u, v, w;
std::tie(u, v, w) = edge;
if (dsu.merge(u, v)) sum -= w;
}
for (int i = 0; i < n; i++) {
if (in_block(i) && dsu.find(i) == i) {
root = i;
}
}
for (int i = 0; i < n; i++) {
if (in_block(i) && dsu.find(i) != root) {
return false;
}
}
return sum >= 0;
};
f[0] = true;
for (int s = 1; s < 1 << n; s++) {
f[s] = check(s);
for (int i = s; i; i = (i - 1) & s) {
f[s] = f[s] || f[i] && f[s ^ i];
}
}
cout << (f[(1 << n) - 1] ? "Yes" : "No") << endl;
}
return 0;
}

BIN
S2OJ/1586/data/ex_trans1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/ex_trans4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1586/data/trans9.in (Stored with Git LFS) Normal file

Binary file not shown.