QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#634648 | #5109. Spider Walk | StayAlone | WA | 988ms | 14016kb | C++14 | 4.6kb | 2024-10-12 17:48:21 | 2024-10-12 17:48:21 |
Judging History
answer
// Problem: P9447 [ICPC2021 WF] Spider Walk
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9447
// Memory Limit: 256 MB
// Time Limit: 6000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define rep1(i, l, r) for (int i = l; i <= int(r); ++i)
#define rep2(i, l, r) for (int i = l; i >= int(r); --i)
#define rer(i, l, r, a) rep1(i, l, r) read(a[i])
#define ptc putchar
#define il inline
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fst first
#define snd second
#define sqr(x) ((x) * (x))
#define ls(x) x << 1
#define rs(x) x << 1 | 1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 bll;
// typedef unsigned __int128 ubll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5 + 10, MAXM = 5e5 + 10;
const int LOGN = log2(MAXN) + 1, inf = ~0U >> 2, INF = ~0U >> 1;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
namespace stupid_lrc {
template <typename T> il bool read(T &x) {
x = 0; bool f = false; char ch;
while (!isdigit(ch = getchar())) {
f ^= !(ch ^ '-');
if (ch == EOF) return false;
}
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
if (f) x = ~x + 1; return true;
}
il int read() {int x; read(x); return x;}
template <typename T> il bool read(pair <T, T> &x) {return read(x.fst) && read(x.snd);}
template <typename T> il void gmin(T &x, T y) {x = x < y ? x : y;}
template <typename T> il void gmax(T &x, T y) {x = x > y ? x : y;}
template <typename T, typename ...L>
il bool read(T &x, L &...y) {return read(x) && read(y...);}
template <typename T> il T lowbit(const T &x) {return x & -x;}
}
using namespace stupid_lrc;
int n, m, s; pii a[MAXM];
struct setr {
#define STZ MAXN << 2
int tag1[STZ], tag2[STZ];
il void pushdown(int x, int l, int r) {
int mid = l + r >> 1;
if (~tag1[x]) {
gmin(tag1[ls(x)], tag1[x]);
gmin(tag1[rs(x)], tag1[x] + mid - l + 1);
tag1[x] = -1;
}
if (~tag2[x]) {
gmin(tag2[ls(x)], tag2[x]);
gmin(tag2[rs(x)], tag2[x] - (mid - l + 1));
tag2[x] = -1;
}
}
il void build(int x, int l, int r) {
tag1[x] = tag2[x] = -1;
if (l == r) return tag1[x] = tag2[x] = l == s ? 0 : inf, void();
int mid = l + r >> 1;
build(ls(x), l, mid); build(rs(x), mid + 1, r);
}
il int query(int x, int l, int r, int k) {
if (l == r) return min(tag1[x], tag2[x]);
int mid = l + r >> 1; pushdown(x, l, r);
return k <= mid ? query(ls(x), l, mid, k) : query(rs(x), mid + 1, r, k);
}
il void upd1(int x, int l, int r, int ql, int qr, int &k) {
if (l > qr || r < ql) return;
if (l >= ql && r <= qr) return gmin(tag1[x], k), k += r - l + 1, void();
int mid = l + r >> 1; pushdown(x, l, r);
upd1(ls(x), l, mid, ql, qr, k); upd1(rs(x), mid + 1, r, ql, qr, k);
}
il void upd2(int x, int l, int r, int ql, int qr, int &k) {
if (l > qr || r < ql) return;
if (l >= ql && r <= qr) return gmin(tag2[x], k), k -= r - l + 1, void();
int mid = l + r >> 1; pushdown(x, l, r);
upd2(ls(x), l, mid, ql, qr, k); upd2(rs(x), mid + 1, r, ql, qr, k);
}
il void print(int x, int l, int r) {
if (l == r) return printf("%d\n", min(tag1[x], tag2[x])), void();
int mid = l + r >> 1; pushdown(x, l, r);
print(ls(x), l, mid); print(rs(x), mid + 1, r);
}
il void update(int x, int l, int r, int k, int p) {
if (l == r) return gmin(tag1[x], p), gmin(tag2[x], p);
int mid = l + r >> 1; pushdown(x, l, r);
k <= mid ? update(ls(x), l, mid, k, p) : update(rs(x), mid + 1, r, k, p);
}
il void update2(int x, int l, int r, int k, int p) {
if (l == r) return tag1[x] = tag2[x] = p, void();
int mid = l + r >> 1; pushdown(x, l, r);
k <= mid ? update2(ls(x), l, mid, k, p) : update2(rs(x), mid + 1, r, k, p);
}
} T;
il void change(int x) {
T.update(1, 1, n, x, min(T.query(1, 1, n, x % n + 1), T.query(1, 1, n, x > 1 ? x - 1 : n)) + 1);
}
il void spread(int x) {
int g, f = T.query(1, 1, n, x);
// rep1(i, 1, n) gmin(f[i], f[x] + dis(i, x));
T.upd1(1, 1, n, 1, x - 1, g = f + n - x + 1); T.upd1(1, 1, n, x + 1, n, g = f + 1);
T.upd2(1, 1, n, 1, x - 1, g = f + x - 1); T.upd2(1, 1, n, x + 1, n, g = f + n - 1);
}
int main() {
read(n, m, s); rer(i, 1, m, a);
sort(a + 1, a + 1 + m, greater<>());
T.build(1, 1, n); spread(s);
rep1(i, 1, m) {
int x = a[i].snd, y = x % n + 1, fx = T.query(1, 1, n, x), fy = T.query(1, 1, n, y);
T.update2(1, 1, n, y, fx); T.update2(1, 1, n, x, fy);
change(x); change(y); spread(x); spread(y);
} T.print(1, 1, n);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 547ms
memory: 13940kb
input:
200000 500000 116205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200000 lines
Test #2:
score: -100
Wrong Answer
time: 988ms
memory: 14016kb
input:
200000 500000 200000 1 148896 2 178903 3 36800 4 98361 5 79634 6 29266 7 51632 8 166082 9 66246 10 145043 11 41644 12 81858 13 87530 14 199625 15 127160 16 49786 17 181673 18 48403 19 30274 20 101455 21 105100 22 52149 23 22810 24 79308 25 191579 26 96365 27 154697 28 45255 29 64965 30 192604 31 330...
output:
1 0 1 1 2 2 3 3 4 5 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 10737...
result:
wrong answer 11th lines differ - expected: '6', found: '1073741823'