QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634286 | #5109. Spider Walk | StayAlone | TL | 0ms | 0kb | C++14 | 2.4kb | 2024-10-12 17:00:41 | 2024-10-12 17:00:42 |
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, f[MAXN]; pii a[MAXM];
il void change(int x) {
gmin(f[x], min(f[x % n + 1], f[x > 1 ? x - 1 : n]) + 1);
}
il void spread(int x) {
auto dis = [&](int x, int y) {
if (x > y) swap(x, y);
return min(y - x, x + n - y);
};
rep1(i, 1, n) gmin(f[i], f[x] + dis(i, x));
}
int main() {
read(n, m, s); rer(i, 1, m, a);
sort(a + 1, a + 1 + n, greater<>());
rep1(i, 1, n) f[i] = inf;
f[s] = 0; spread(s);
rep1(i, 1, m) {
int x = a[i].snd, y = x % n + 1; swap(f[x], f[y]);
change(x); change(y);
spread(x); spread(y);
}
rep1(i, 1, n) printf("%d\n", f[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
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...