QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634621#5109. Spider WalkStayAloneWA 531ms13924kbC++144.6kb2024-10-12 17:45:392024-10-12 17:45:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 17:45:39]
  • 评测
  • 测评结果:WA
  • 用时:531ms
  • 内存:13924kb
  • [2024-10-12 17:45:39]
  • 提交

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 + n, 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: 0
Wrong Answer
time: 531ms
memory: 13924kb

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
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
2
...

result:

wrong answer 2nd lines differ - expected: '1', found: '2'