QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644796#6420. Certain Scientific Railgunrush-from-behind#RE 0ms9832kbC++235.2kb2024-10-16 15:29:512024-10-16 15:29:51

Judging History

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

  • [2024-10-16 15:29:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:9832kb
  • [2024-10-16 15:29:51]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define int long long
#define mid ((l + r) >> 1)
#define ls num << 1
#define rs ls | 1
#define li ls, l, mid
#define ri rs, mid + 1, r
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T &x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T &x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 1e5 + 10, M = N << 2;
int n, tag1[M], tag2[M], m;
pair <int, int> a[N], b[N];
struct Info {
	int a, b, c, mx1, mx2;
} info[M];
vector <int> g;
void build(int num, int l, int r) {
	info[num] = {g[l], g[l], g[l], 0, 0};
	if (l == r) {
		return;
	}
	tag1[num] = tag2[num] = 0;
	build(li), build(ri);
}
void down1(int num, int l, int r, int x) {
	info[num].a = info[num].c + x;
	info[num].b = g[l] + x;
	info[num].mx1 = x;
	tag1[num] = x;
}
void down2(int num, int l, int r, int x) {
	info[num].a = info[num].b + x;
	info[num].c = g[l] + x;
	info[num].mx2 = x;
	tag2[num] = x;
}
void pushdown(int num, int l, int r) {
	if (tag1[num]) {
		down1(li, tag1[num]), down1(ri, tag1[num]);
		tag1[num] = 0;
	}
	if (tag2[num]) {
		down2(li, tag2[num]), down2(ri, tag2[num]);
		tag2[num] = 0;
	}
}
void pushup(int num) {
	info[num] = {min(info[ls].a, info[rs].a), min(info[ls].b, info[rs].b), min(info[ls].c, info[rs].c), info[ls].mx1, info[ls].mx2};
	assert(info[ls].mx1 >= info[rs].mx1);
	// debug << info[ls].mx2 << " " << info[rs].mx2 << endl;
	assert(info[ls].mx2 >= info[rs].mx2);
}
int qpos1(int num, int l, int r, int x) {
	// if (info)
	if (l == r) return l;
	pushdown(num, l, r);
	if (info[rs].mx1 >= x) {
		return qpos1(ri, x);
	}
	return qpos1(li, x);
}
int qpos2(int num, int l, int r, int x) {
	// if (info)
	if (l == r) return l;
	pushdown(num, l, r);
	if (info[rs].mx2 >= x) {
		return qpos2(ri, x);
	}
	return qpos2(li, x);
}
void change1(int num, int l, int r, int L, int R, int x) {
	if (L <= l && r <= R) return down1(num, l, r, x);
	pushdown(num, l, r);
	if (mid >= L) change1(li, L, R, x);
	if (mid < R) change1(ri, L, R, x);
	pushup(num);
}
void change2(int num, int l, int r, int L, int R, int x) {
	if (L <= l && r <= R) return down2(num, l, r, x);
	pushdown(num, l, r);
	if (mid >= L) change2(li, L, R, x);
	if (mid < R) change2(ri, L, R, x);
	pushup(num);
}
int ans;
void solve() {
	g.clear();
	F(i, 1, n)
		if (a[i].first > 0) {
			g.push_back(a[i].first);
		}
	g.push_back(0);
	sort(all(g));
	g.pop_back();
	g.resize(unique(all(g)) - g.begin());
	m = g.size();
	g.insert(g.begin(), - 1);
	sort(a + 1, a + n + 1, [&] (pair <int, int> x, pair <int, int> y) {
		return x.first < y.first;
	});
	build(1, 1, m);
	// debug << "!\n";
	// debug << m << endl;
	F(i, 1, n) {
		if (a[i].first > 0) {
			int h = lower_bound(all(g), a[i].first) - g.begin() - 1;
			if (a[i].second > 0) {
				int p = info[1].mx1 < a[i].second ? 1 : qpos1(1, 1, m, a[i].second) + 1;
				if (p <= h) {
					// debug << p << " " << h << " " << a[i].second << endl;
					change1(1, 1, m, p, h, a[i].second);
				}
			} else {
				int p = info[1].mx2 < - a[i].second ? 1 : qpos2(1, 1, m, - a[i].second) + 1;
				if (p <= h) {
					// debug << p << " " << h << " " << - a[i].second << endl;
					change2(1, 1, m, p, h, - a[i].second);
				}
			}
		}
	}
	// debug << info[1].a << endl;
	F(i, 1, n) {
		if (a[i].first < 0) {
			chkmin(ans, - a[i].first + info[1].a);
			if (a[i].second > 0) {
				int p = info[1].mx1 < a[i].second ? 1 : qpos1(1, 1, m, a[i].second) + 1;
				if (p <= m) {
					change1(1, 1, m, p, m, a[i].second);
				}
			} else {
				int p = info[1].mx2 < - a[i].second ? 1 : qpos2(1, 1, m, - a[i].second) + 1;
				if (p <= m) {
					// debug << p << " " << m << " " << - a[i].second << endl;
					change2(1, 1, m, p, m, - a[i].second);
				}
			}
		}
	}
	// debug << endl;
	// debug << info[1].a << endl;
	chkmin(ans, info[1].a);
}
void zhk() {
	ans = 1e18;
	cin >> n;
	// map <int, vector <int>> mp;
	F(i, 1, n) {
		cin >> b[i].first >> b[i].second;
	}
	F(i, 1, n) {
		a[i] = b[i];
		if (a[i].first < 0) a[i].first *= 2;
		if (a[i].second < 0) a[i].second *= 2;
	}
	solve();
	F(i, 1, n) {
		a[i] = b[i];
		if (a[i].first > 0) a[i].first *= 2;
		if (a[i].second < 0) a[i].second *= 2;
	}
	solve();
	F(i, 1, n) {
		a[i] = b[i];
		if (a[i].first < 0) a[i].first *= 2;
		if (a[i].second > 0) a[i].second *= 2;
	}
	solve();
	F(i, 1, n) {
		a[i] = b[i];
		if (a[i].first > 0) a[i].first *= 2;
		if (a[i].second > 0) a[i].second *= 2;
	}
	solve();
	cout << ans << '\n';
}
signed main() {
	ios::sync_with_stdio(0); // don't use puts
	cin.tie(0), cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9832kb

input:

3
2
0 1
1 0
4
1 1
-3 -3
4 -4
-2 2
4
1 100
3 100
-100 1
3 -100

output:

0
8
4

result:

ok 3 number(s): "0 8 4"

Test #2:

score: -100
Runtime Error

input:

120
4
11 11
-22 -22
33 -33
-44 44
4
-11 11
22 -22
-33 -33
44 44
4
-11 -11
22 22
-33 33
44 -44
4
11 -11
-22 22
33 33
-44 -44
4
-11 11
22 -22
33 33
-44 -44
4
11 11
-22 -22
-33 33
44 -44
4
11 -11
-22 22
-33 -33
44 44
4
-11 -11
22 22
33 -33
-44 44
4
1 1
-2 -2
3 -3
-4 4
4
-1 1
2 -2
-3 -3
4 4
4
-1 -1
2 2
...

output:


result: