扫描线是对的,用注释掉的代码拿到了 95。
想问一下我这个斜线什么问题。
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N, M, Q, n, lin[2000005];
struct node{
int l, r, h, op;
}a[2000005];
struct tmp{
int op, x, y, xx, yy;
bool operator == (tmp b){
return op == b.op && x == b.x && y == b.y && xx == b.xx && yy == b.yy;
}
};
struct seg{
int l, r, len, vl;
}tr[4000005];
map<pair<int, int>, bool> JunXion;
vector<tmp> vec, vvec;
void build(int u, int l, int r){
tr[u].l = l;
tr[u].r = r;
tr[u].len = tr[u].vl = 0;
if (l == r)
return;
int mid = (l + r) >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
}
void pup(int u){
int L = tr[u].l, R = tr[u].r;
if (tr[u].vl)
tr[u].len = lin[R + 1] - lin[L];
else
tr[u].len = tr[u << 1].len + tr[u << 1 | 1].len;
}
void upd(int u, int l, int r, int x){
int L = tr[u].l, R = tr[u].r;
if (lin[R + 1] <= l || lin[L] >= r)
return;
if (l <= lin[L] && lin[R + 1] <= r){
tr[u].vl += x;
pup(u);
return;
}
upd(u << 1, l, r, x);
upd(u << 1 | 1, l, r, x);
pup(u);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// cin >> n;
int cccc;
cin >> cccc;
int cnt = 0;
cin >> N >> M >> Q;
for (int i = 1; i <= Q; i++){
int op, x, y, xx, yy;
cin >> op >> x >> y >> xx >> yy;
vvec.push_back({op, x, y, xx, yy});
if (op == 1){
lin[++cnt] = x;
a[cnt] = {x, xx + 1, y, 1};
lin[++cnt] = xx + 1;
a[cnt] = {x, xx + 1, yy + 1, -1};
}else if (op == 2){
lin[++cnt] = x;
a[cnt] = {x, xx + 1, y, 1};
lin[++cnt] = xx + 1;
a[cnt] = {x, xx + 1, yy + 1, -1};
}else
vec.push_back({op, x, y, xx, yy});
//else{
// for (int i = 0; i <= yy - y; i++){
// lin[++cnt] = x + i;
// a[cnt] = {x + i, x + i + 1, y + i, 1};
// lin[++cnt] = x + i + 1;
// a[cnt] = {x + i, x + i + 1, y + i + 1, -1};
// }
//}
}
n = cnt;
sort(a + 1, a + n + 1, [](node a, node b){return a.h < b.h;});
sort(lin + 1, lin + n + 1);
int qwq = unique(lin + 1, lin + n + 1) - lin - 1;
build(1, 1, qwq - 1);
int ans = 0;
for (int i = 1; i < n; i++){
upd(1, a[i].l, a[i].r, a[i].op);
ans += tr[1].len * (a[i + 1].h - a[i].h);
}
for (tmp u : vec){
JunXion.clear();
int x, y, xx, yy;
x = u.x;
y = u.y;
xx = u.xx;
yy = u.yy;
ans += yy - y + 1;
for (tmp v : vvec){
if (v.op == 1){
if (u.y <= v.y && v.y <= u.yy){
int jx = u.x + (v.y - u.y);
if (v.x <= jx && v.xx >= jx){
//(jx, v.y)
if (!JunXion[make_pair(jx, v.y)]){
JunXion[make_pair(jx, v.y)] = 1;
ans--;
}
}
}
}else if (v.op == 2){
if (u.x <= v.x && v.x <= u.xx){
int jy = u.y + (v.x - u.x);
if (v.y <= jy && v.yy >= jy){
//(v.x, jy)
if (!JunXion[make_pair(v.x, jy)]){
JunXion[make_pair(v.x, jy)] = 1;
ans--;
}
}
}
}else if (v.op == 3){
if (u == v)
continue;
if (v.x - v.y != u.x - u.y)
continue;
if (v.x >= u.x && v.x <= u.xx)
ans -= (u.xx - v.x + 1);
}
}
}
cout << ans;
return 0;
}