0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2025-02-17 12:46:47 +00:00

Compare commits

..

No commits in common. "efa569b497e09a7bf2c329a1d9d44f0b876ae6e5" and "3256f5c172a88542f6c82568476bec4b4a7000c4" have entirely different histories.

973 changed files with 0 additions and 5123 deletions

View File

@ -1,84 +0,0 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 4e5 + 5;
int n, m, k, a[N], fa[N], ans[N];
bool vis[N], del[N];
std::vector<int> g[N];
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0, x, y; i < m; i++) {
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; i++) fa[i] = i;
cin >> k;
for (int i = 1; i <= k; i++) {
cin >> a[i];
del[a[i]] = true;
}
for (int i = 0; i < n; i++) {
if (!del[i]) {
for (int v : g[i]) {
if (!del[v]) {
int f1 = find(i),
f2 = find(v);
fa[f1] = f2;
}
}
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (fa[i] == i && !del[i]) cnt++;
}
ans[k] = cnt;
for (int i = k; i; i--) {
del[a[i]] = false;
cnt++;
for (int v : g[a[i]]) {
if (!del[v]) {
int f1 = find(a[i]),
f2 = find(v);
if (f1 != f2) {
fa[f1] = f2;
cnt--;
}
}
}
ans[i - 1] = cnt;
}
for (int i = 0; i <= k; i++) {
cout << ans[i] << endl;
}
return 0;
}

BIN
BZOJ/1015/data/1.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/1.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/10.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/10.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/2.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/2.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/3.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/3.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/4.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/4.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/5.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/5.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/6.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/6.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/7.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/7.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/8.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/8.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/9.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1015/data/9.out (Stored with Git LFS)

Binary file not shown.

View File

@ -1,68 +0,0 @@
#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
const int INF = 0x3f3f3f3f;
int c, n, f[N][1 << 8][20];
std::pair<int, int> a[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> c;
while (c--) {
memset(f, 0x3f, sizeof(f));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
f[1][0][7] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 1 << 8; j++) {
for (int k = -8; k <= 7; k++) {
if (f[i][j][k + 8] != INF) {
if (j & 1) { // 当前同学吃了,无需考虑后方
f[i + 1][j >> 1][k + 7] = std::min(f[i + 1][j >> 1][k + 7], f[i][j][k + 8]);
} else {
int t = INF;
for (int l = 0; l <= 7; l++) {
if (j & 1 << l) continue;
if (i + l > t) break;
if (i + l <= n) t = std::min(t, i + l + a[i + l].second);
else t = std::min(t, i + l);
if (i + k) {
int x = i + k <= n ? a[i + k].first : 0,
y = i + l <= n ? a[i + l].first : 0;
f[i][j | 1 << l][l + 8] = std::min(f[i][j | 1 << l][l + 8], f[i][j][k + 8] + (x ^ y));
} else {
f[i][j | 1 << l][l + 8] = std::min(f[i][j | 1 << l][l + 8], f[i][j][k + 8]);
}
}
}
}
}
}
}
int ans = INF;
for (int i = 0; i <= 8; i++) {
ans = std::min(ans, f[n + 1][0][i]);
}
cout << ans << endl;
}
return 0;
}

BIN
BZOJ/1226/data/1.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/1.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/10.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/10.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/11.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/11.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/12.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/12.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/13.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/13.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/14.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/14.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/15.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/15.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/16.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/16.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/17.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/17.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/18.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/18.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/19.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/19.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/2.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/2.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/20.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/20.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/21.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/21.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/22.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/22.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/23.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/23.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/24.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/24.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/25.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/25.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/3.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/3.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/4.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/4.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/5.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/5.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/6.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/6.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/7.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/7.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/8.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/8.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/9.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1226/data/9.out (Stored with Git LFS)

Binary file not shown.

View File

@ -1,112 +0,0 @@
#include <iostream>
#include <deque>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 205;
int n, m, x, y, k, s, t, d, f[N][N], ans;
bool g[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> x >> y >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
g[i][j] = c == 'x';
f[i][j] = -0x3f3f3f3f;
}
}
f[x][y] = 0;
for (int i = 1; i <= k; i++) {
cin >> s >> t >> d;
int len = t - s + 1;
switch (d) {
case 1: { // 上
for (int y = 1; y <= m; y++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, x = n; x; j++, x--) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 2: { // 下
for (int y = 1; y <= m; y++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, x = 1; x <= n; j++, x++) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 3: { // 左
for (int x = 1; x <= n; x++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, y = m; y; j++, y--) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
case 4: { // 右
for (int x = 1; x <= n; x++) {
std::deque<std::pair<int, int>> q;
for (int j = 1, y = 1; y <= m; j++, y++) {
if (g[x][y]) {
q.clear();
} else {
while (!q.empty() && q.back().second < f[x][y] - j) q.pop_back();
q.push_back(std::make_pair(j, f[x][y] - j));
while (!q.empty() && j - q.front().first > len) q.pop_front();
f[x][y] = q.front().second + j;
ans = std::max(ans, f[x][y]);
}
}
}
break;
}
}
}
cout << ans << endl;
return 0;
}

BIN
BZOJ/1499/data/1.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/1.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/10.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/10.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/2.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/2.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/3.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/3.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/4.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/4.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/5.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/5.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/6.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/6.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/7.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/7.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/8.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/8.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/9.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1499/data/9.out (Stored with Git LFS)

Binary file not shown.

View File

@ -1,183 +0,0 @@
#include <iostream>
#include <algorithm>
#include <chrono>
#include <limits>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
struct node {
node *lchild, *rchild;
size_t size;
unsigned key;
int value, min;
bool reversed;
node()
: lchild(nullptr),
rchild(nullptr),
size(0),
key(rand()),
value(0),
min(std::numeric_limits<int>::max()),
reversed(false) {}
node(int _value)
: lchild(nullptr),
rchild(nullptr),
size(1),
key(rand()),
value(_value),
min(_value),
reversed(false) {}
~node() {
if (lchild != nullptr) delete lchild;
if (rchild != nullptr) delete rchild;
}
inline size_t lsize() {
return lchild == nullptr ? 0 : lchild->size;
}
inline size_t rsize() {
return rchild == nullptr ? 0 : rchild->size;
}
inline void pushup() {
size = lsize() + 1 + rsize();
min = value;
if (lchild != nullptr) {
min = std::min(min, lchild->min);
}
if (rchild != nullptr) {
min = std::min(min, rchild->min);
}
}
inline void pushdown() {
if (reversed) {
std::swap(lchild, rchild);
if (lchild != nullptr) lchild->reversed = !lchild->reversed;
if (rchild != nullptr) rchild->reversed = !rchild->reversed;
reversed = false;
}
}
};
int n, b[N];
std::pair<int, int> a[N];
node *root;
std::pair<node *, node *> split(node *u, int k) {
if (u == nullptr) return std::make_pair(nullptr, nullptr);
u->pushdown();
if (k <= u->lsize()) {
auto o = split(u->lchild, k);
u->lchild = o.second;
u->pushup();
o.second = u;
return o;
}
auto o = split(u->rchild, k - u->lsize() - 1);
u->rchild = o.first;
u->pushup();
o.first = u;
return o;
}
node *merge(node *x, node *y) {
if (x == nullptr) return y;
if (y == nullptr) return x;
if (x->key < y->key) {
x->pushdown();
x->rchild = merge(x->rchild, y);
x->pushup();
return x;
}
y->pushdown();
y->lchild = merge(x, y->lchild);
y->pushup();
return y;
}
void reverse(int k) {
auto x = split(root, k);
auto y = split(x.first, k - 1);
if (y.first != nullptr) y.first->reversed = !y.first->reversed;
delete y.second;
root = merge(y.first, x.second);
}
int find(node *p) {
int k = 1;
while (p != nullptr) {
p->pushdown();
if (p->lchild != nullptr && p->min == p->lchild->min) {
p = p->lchild;
} else if (p->rchild != nullptr && p->min == p->rchild->min) {
k += p->lsize() + 1;
p = p->rchild;
} else {
return k + p->lsize();
}
}
return -1;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
std::sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
b[a[i].second] = i;
}
for (int i = 1; i <= n; i++) {
root = merge(root, new node(b[i]));
}
for (int i = 1; i <= n; i++) {
int k = find(root);
reverse(k);
cout << k + i - 1 << ' ';
}
cout << endl;
// Cleanup
delete root;
return 0;
}

BIN
BZOJ/1552/data/1.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1552/data/1.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1552/data/10.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1552/data/10.out (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1552/data/11.in (Stored with Git LFS)

Binary file not shown.

BIN
BZOJ/1552/data/11.out (Stored with Git LFS)

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More