const int MAXN = 1100000;
struct Seg
{
int l, r;
bool operator< (const Seg& rhs)const
{
return r - l < rhs.r - rhs.l;
}
} ipt[MAXN];
VI split;
int ans[MAXN], q[MAXN];
set<int> st;
set<int>::iterator it;
int main()
{
int n, m;
while (~RI(n))
{
split.clear();
CLR(ans, -1);
FE(i, 1, n)
{
RII(ipt[i].l, ipt[i].r);
split.push_back(ipt[i].l);
split.push_back(ipt[i].r);
split.push_back(ipt[i].l - 1);
split.push_back(ipt[i].r + 1);
}
RI(m);
REP(i, m)
{
RI(q[i]);
split.push_back(q[i]);
}
sort(all(split));
split.erase(unique(all(split)), split.end());
FE(i, 0, split.size())
st.insert(i);
st.insert(INF);
FED(i, n, 1)
{
int l = lower_bound(all(split), ipt[i].l) - split.begin();
int r = lower_bound(all(split), ipt[i].r) - split.begin();
it = st.lower_bound(l);
while (*it <= r)
{
ans[*it] = i;
st.erase(it++);
}
}
REP(i, m)
{
int id = lower_bound(all(split), q[i]) - split.begin();
WI(ans[id]);
}
}
return 0;
}Nested Segments,布布扣,bubuko.com
原文:http://blog.csdn.net/wty__/article/details/38497043