求助!
查看原帖
求助!
109114
_l_l_¯l¯l¯楼主2023/12/5 20:08

rt,卡在 subtask_1_16 那一个也仅是那一个点,求调

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
pair<int, int> pt[MAXN]; vector<array<int, 3> > vc; vector<int> ycor;
map<int, int> xc, yc;
int c[MAXN]; void insert(int u, int w) {for (; u < MAXN; u += u & -u) c[u] = max(c[u], w);}
int query(int u) {int w = -0x3f3f3f3f; for (; u; u -= u & -u) w = max(w, c[u]); return w;}
int main() {
	int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	bool mirrx = x1 > x2, mirry = y1 > y2;
	if (mirrx) x1 = 99999999 - x1, x2 = 99999999 - x2;
	if (mirry) y1 = 99999999 - y1, y2 = 99999999 - y2;
	int n; scanf("%d", &n); for (int i = 1; i <= n; i++) {
		scanf("%d %d", &pt[i].first, &pt[i].second);
		if (mirrx) pt[i].first = 99999999 - pt[i].first;
		if (mirry) pt[i].second = 99999999 - pt[i].second;
	}
	if (x1 == x2) {
		bool tag = 0; for (int i = 1; i <= n; i++) if (pt[i].first == x1 && y1 < pt[i].second && pt[i].second < y2) tag = 1;
		printf("%.15lf\n", (y2 - y1) * 100.0 + tag * 11.415926535897938);
	}
	else if (y1 == y2) {
		bool tag = 0; for (int i = 1; i <= n; i++) if (pt[i].second == y1 && x1 < pt[i].first && pt[i].first < x2) tag = 1;
		printf("%.15lf\n", (x2 - x1) * 100.0 + tag * 11.415926535897938);
	}
	else {
		for (int i = 1; i <= n; i++) xc.insert({pt[i].first, pt[i].second}), yc.insert({pt[i].second, pt[i].first});
		bool tag1 = 1, tag2 = 1;
		for (int i = x1, lst = y1; i <= x2; i++) {
			if (xc.find(i) == xc.end()) {tag1 = 0; break;}
			else if (xc[i] < lst || xc[i] > y2) {tag1 = 0; break;} lst = xc[i];
		}
		for (int i = y1, lst = x1; i <= y2; i++) {
			if (yc.find(i) == yc.end()) {tag2 = 0; break;}
			else if (yc[i] < lst || yc[i] > y2) {tag2 = 0; break;} lst = yc[i];
		}
		if (tag1 || tag2) return printf("%.15lf\n", (x2 - x1 + y2 - y1) * 100.0 - 4.292036732051031 * min(x2 - x1, y2 - y1) + 11.415926535897938), 0;
		vc.push_back({x1, y1 - 1000000001, -1}); vc.push_back({x2, y2, -2}); ycor.push_back(y1); ycor.push_back(y2);
		for (int i = 1; i <= n; i++) vc.push_back({pt[i].first, -pt[i].second, i}), ycor.push_back(pt[i].second);
		sort(vc.begin(), vc.end()); sort(ycor.begin(), ycor.end()); memset(c, 0xcf, sizeof c);
		ycor.resize(unique(ycor.begin(), ycor.end()) - ycor.begin()); for (auto x : vc) {
			x[1] = lower_bound(ycor.begin(), ycor.end(), x[2] > 0 ? -x[1] : x[2] == -1 ? x[1] + 1000000001 : x[1]) - ycor.begin() + 2;
			if (x[2] == -1) insert(x[1] - 1, 0);
			else if (x[2] == -2) return printf("%.15lf\n", (x2 - x1 + y2 - y1) * 100.0 - 4.292036732051031 * query(x[1])), 0;
			else insert(x[1], query(x[1] - 1) + 1);
		}
	}
}
2023/12/5 20:08
加载中...