标签:result return tmp amp names name lowbit etc ==
80s的评测交了五六发、、、貌似卡评测了
只讨论在左下角的点,cdq分支求出。
然后剩下的用坐标对称啥的再来三遍。
不过每次还原这样是会T的。
对x排序,然后搞就过了,(我也不知道,不过还是40s左右)
KD-tree比较快,10s+
/**************************************************************
Problem: 2716
User: gryz2016
Language: C++
Result: Accepted
Time:45880 ms
Memory:52076 kb
****************************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
using namespace std;
const int N = 1e6 + 7, maxn = 1e6, M = 5e5 + 7;
char buf[4000001],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,4000000,stdin),p1==p2)?EOF:*p1++)
int read() {
int x = 0,f = 1;char s = getchar();
for (;s > '9' || s < '0'; s = getchar()) if (s == '-') f = -1;
for (;s >= '0' && s <= '9'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
int ans[N],TLE;
struct node {
int type, x, y, id, jyb;
node(int nb = 0,int a = 0, int b = 0, int c = 0, int d = 0) {
jyb = nb, type = a, x = b, y = c, id = d;
}
bool operator < (const node &b) const {
return x == b.x ? y < b.y : x < b.x;
}
}Q[M * 2], tmp[M * 2];
struct mmp {
int ma[N];
void add(int x, int ad) {for (int i = x; i <= TLE; i += lowbit(i)) ma[i] = max(ma[i], ad);}
void clear(int x) {for (int i = x; i <= TLE; i += lowbit(i)) ma[i] = 0;}
int query(int x) {int ans = 0;for (int i = x; i >= 1; i -= lowbit(i)) ans = max(ans, ma[i]);return ans;}
}BIT;
void cdq(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
int p = l, q = mid + 1, js = l;
for(int i=l;i<=r;++i)
if(Q[i].jyb <= mid) tmp[p++]=Q[i];
else tmp[q++]=Q[i];
for(int i=l;i<=r;++i) Q[i]=tmp[i];
p=l;
for(int i=mid+1;i<=r;++i) {
if(Q[i].type==2) {
while(Q[p].x<=Q[i].x&&p<=mid) {
if(Q[p].type==1) BIT.add(Q[p].y,Q[p].x+Q[p].y);
p++;
}
int val=BIT.query(Q[i].y);
if(val) ans[Q[i].id]=min(ans[Q[i].id],Q[i].x+Q[i].y-val);
}
}
for(int i=l;i<=mid;++i) if(Q[i].type==1) BIT.clear(Q[i].y);
cdq(l, mid), cdq(mid + 1, r);
}
int main() {
int n = read(), m = read(), js = 0, DSR = 0;
for (int i = 1; i <= n; ++i) {
int x = read() + 1, y = read() + 1;
TLE = max(TLE, y);
TLE = max(TLE, x);
Q[++js] = node(js, 1, x, y);
}
for (int i = 1; i <= m; ++i) {
int opt = read(), x = read() + 1, y = read() + 1;
TLE = max(TLE, y);
TLE = max(TLE, x);
if (opt == 1) {
Q[++js] = node(js, 1, x, y);
} else {
Q[++js] = node(js, 2, x, y, ++DSR);
ans[DSR] = 0x3f3f3f3f;
}
}
TLE++;
sort(Q + 1, Q + 1 + js);
cdq(1, js);
for (int i = 1; i <= js; ++i) Q[i].x = -Q[i].x + TLE;
sort(Q + 1, Q + 1 + js);
cdq(1, js);
for (int i = 1; i <= js; ++i) Q[i].y = -Q[i].y + TLE;
sort(Q + 1, Q + 1 + js);
cdq(1, js);
for (int i = 1; i <= js; ++i) Q[i].x = -Q[i].x + TLE;
sort(Q + 1, Q + 1 + js);
cdq(1, js);
for (int i = 1; i <= DSR; ++i) printf("%d\n", ans[i]);
return 0;
}
标签:result return tmp amp names name lowbit etc ==
原文地址:https://www.cnblogs.com/dsrdsr/p/10983975.html