0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#1223. 【NEERC2016】Mole Tunnels

https://sjzezoj.com/submission/66902
This commit is contained in:
Baoshuo Ren 2023-01-14 19:32:32 +08:00
parent f04778be4b
commit 68704f8cb9
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
162 changed files with 579 additions and 0 deletions

96
S2OJ/1223/1223.cpp Normal file
View File

@ -0,0 +1,96 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int n, m, c[N], p[N], f[N << 1], g[N << 1], f2[N], ans;
void update(int u) {
f[u] = INF;
if (c[u]) {
f[u] = 0;
g[u] = u;
}
if (f[u] > f[u << 1] + (f2[u << 1] < 0 ? -1 : 1)) {
f[u] = f[u << 1] + (f2[u << 1] < 0 ? -1 : 1);
g[u] = g[u << 1];
}
if (f[u] > f[u << 1 | 1] + (f2[u << 1 | 1] < 0 ? -1 : 1)) {
f[u] = f[u << 1 | 1] + (f2[u << 1 | 1] < 0 ? -1 : 1);
g[u] = g[u << 1 | 1];
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
std::fill(std::begin(f), std::end(f), INF);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
for (int i = 1; i <= m; i++) {
cin >> p[i];
}
for (int i = n; i; i--) {
update(i);
}
for (int i = 1; i <= m; i++) {
int x = INF,
y = 0,
u = p[i],
t = 0,
v = 0;
while (u) {
if (x > f[u] + t) {
x = f[u] + t;
y = g[u];
v = u;
}
t += (f2[u] > 0 ? -1 : 1);
u >>= 1;
}
u = p[i];
ans += x;
while (u != v) {
f2[u]--;
update(u >>= 1);
}
c[y]--;
update(y);
while (y != v) {
f2[y]++;
update(y >>= 1);
}
while (v) {
update(v);
v >>= 1;
}
cout << ans << ' ';
}
cout << endl;
return 0;
}

BIN
S2OJ/1223/data/mole1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole21.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole22.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole23.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole24.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole25.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole26.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole26.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole27.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole27.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole28.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole28.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole29.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole29.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole30.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole30.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole31.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole31.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole32.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole32.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole33.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole33.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole34.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole34.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole35.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole35.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole36.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole36.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole37.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole37.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole38.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole38.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole39.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole39.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole40.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole40.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole41.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole41.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole42.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole42.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole43.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole43.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole44.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole44.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole45.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole45.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole46.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole46.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole47.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole47.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole48.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole48.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole49.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole49.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole50.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole50.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole51.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole51.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole52.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole52.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole53.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole53.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1223/data/mole54.in (Stored with Git LFS) Normal file

Binary file not shown.

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