$n , m \leq 3 \times 10^5, 1 \leq x_i, y_i \leq 10^9,$ 每次操作的 $x$$y$ 分别互不相同。

#include <bits/stdc++.h>
using namespace std;
#define gc() getchar()
template <typename tp>
x = 0; char tmp; bool key = 0;
for (tmp = gc() ; !isdigit(tmp) ; tmp = gc())
key = (tmp == '-');
for ( ; isdigit(tmp) ; tmp = gc())
x = (x << 3) + (x << 1) + (tmp ^ '0');
if (key) x = -x;
}
const int N = 300010, INF = 0x3f3f3f3f;
struct edge {
int la,b;
} con[N << 1];
int tot,fir[N << 1];
con[++tot] = (edge) {fir[from],to};
fir[from] = tot;
}
struct data {
int x,y,v;
bool operator < (const data& a) const {
return y > a.y;
}
} dat[N << 1];
int n,m,cnt,fa[N],val[N],uni[N],ans[N];
int getfa(int pos) {
return pos == uni[pos] ? pos : uni[pos] = getfa(uni[pos]);
}
typedef pair<int,int> pii;
set<pii> st;
set<pii> :: iterator t, t1;
void ins(int x,int y) {
t = st.insert(pii(x,y)).first;
while (t != st.begin()) {
t1 = t;
-- t1;
if (t1 -> second < y) break;
st.erase(t1);
}
}
return st.upper_bound(pii(p+1,0))->second;
}
int main() {
for (int i = 1, x, y ; i <= n ; ++ i) {
-- x, -- y;
dat[++cnt] = (data) {x,y,0};
}
for (int i = 1, x, y ; i <= m ; ++ i) {
dat[++cnt] = (data) {x,y,i};
}
dat[++cnt] = (data) {INF,INF,m+1};
sort(dat+1,dat+cnt+1);
for (int i = 1, las = 1, tmp ; i <= cnt ; ++ i) {
if (dat[i].y != dat[las].y) {
for (int j = las ; j < i ; ++ j)
if (dat[j].v) ins(dat[j].x, dat[j].v);
las = i;
}
if (dat[i].v) fa[dat[i].v] = tmp;
else ++ val[tmp];
}
for (int i = 1 ; i <= m ; ++ i)
uni[i] = i;
for (int i = m ; i >= 1 ; -- i) {
ans[i] = val[getfa(i)];
uni[getfa(i)] = getfa(fa[i]);
val[getfa(fa[i])] += ans[i];
}
for (int i = 1 ; i <= m ; ++ i)
printf("%d\n",ans[i]);
return 0;
}

posted @ 2019-01-19 13:35 莫名其妙的aaa 阅读(...) 评论(...) 编辑 收藏