WA on #9 球条
查看原帖
WA on #9 球条
759710
LuoFeng_Nanami楼主2024/7/6 13:14
#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define F(i, a, b) for(rll i = a; i <= b; i++)
#define Fdn(i, a, b) for(rll i = a; i >= b; i--)
#define int ll
#define pii pair<int, int>

using namespace std;

const int inf = 0x3f3f3f3f3f3f3f3f,mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int n, p;
int Tree[maxn << 2];
int buc[maxn];
int tot;
int dis[maxn];
int f[maxn];

inline void PushUp(int p) { Tree[p] = max(Tree[p << 1], Tree[p << 1 | 1]); }

inline void Modify(int p, int l, int r, int k, int v) {
	if(l == r) 
		return Tree[p] = v, void();
	int mid = (l + r) >> 1;
	if(k <= mid) Modify(p << 1, l, mid, k, v);
	else Modify(p << 1 | 1, mid + 1, r, k, v);
	PushUp(p);
}

inline int Query(int p, int l, int r, int s, int t) {
	if(s <= l && r <= t)
		return Tree[p];
	int mid = (l + r) >> 1, ret = -inf;
	if(s <= mid) ret = max(ret, Query(p << 1, l, mid, s, t));
	if(mid < t) ret = max(ret, Query(p << 1 | 1, mid + 1, r, s, t));
	return ret;
}

struct node {
	int x, y;
	bool op;
	int bel;
	
	bool operator < (const node &m) const {
		if(y == m.y) return x < m.x;
		return y < m.y;
	}
}nodes[maxn];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> p;
	F(i, 1, p) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		nodes[(i - 1) * 2 + 1] = {x1, y1, 0, i}, nodes[i * 2] = {x2, y2, 1, i};
		buc[i * 2 - 1] = x1, buc[i * 2] = x2; 
		dis[i] = x2 + y2 - x1 - y1;
	}
	sort(nodes + 1, nodes + 2 * p + 1);
	sort(buc + 1, buc + 2 * p + 1);
	tot = unique(buc + 1, buc + 2 * p + 1) - buc - 1;
	F(i, 1, 2 * p) nodes[i].x = lower_bound(buc + 1, buc + 1 + tot, nodes[i].x) - buc;
	F(i,1 , 2 * p) {
		if(!nodes[i].op) f[nodes[i].bel] = Query(1, 1, tot, 1, nodes[i].x) + dis[nodes[i].bel];
		else Modify(1, 1, tot, nodes[i].x, f[nodes[i].bel]);
	} int ans = 0;
	F(i, 1, p) ans = max(ans, f[i]);
	cout << 2 * n - ans;

	return 0;
}```
2024/7/6 13:14
加载中...