# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
172770 | arnold518 | Matryoshka (JOI16_matryoshka) | C++14 | 473 ms | 13264 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 4e5;
struct Point
{
int x, y, p;
};
int N, Q, ans[MAXN+10];
Point A[MAXN+10];
vector<int> xcomp, ycomp;
int tree[MAXN+10];
void update(int i, int val) { for(; i<=xcomp.size(); i+=(i&-i)) tree[i]=max(tree[i], val); }
int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret=max(ret, tree[i]); return ret; }
int main()
{
int i, j;
scanf("%d%d", &N, &Q);
for(i=1; i<=N; i++)
{
scanf("%d%d", &A[i].x, &A[i].y);
A[i].x*=-1; A[i].p=-1;
xcomp.push_back(A[i].x);
ycomp.push_back(A[i].y);
}
for(i=N+1; i<=N+Q; i++)
{
scanf("%d%d", &A[i].x, &A[i].y);
A[i].x*=-1; A[i].p=i-N;
xcomp.push_back(A[i].x);
ycomp.push_back(A[i].y);
}
sort(xcomp.begin(), xcomp.end());
sort(ycomp.begin(), ycomp.end());
xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());
for(i=1; i<=N+Q; i++) A[i].x=lower_bound(xcomp.begin(), xcomp.end(), A[i].x)-xcomp.begin()+1;
for(i=1; i<=N+Q; i++) A[i].y=lower_bound(ycomp.begin(), ycomp.end(), A[i].y)-ycomp.begin()+1;
sort(A+1, A+N+Q+1, [&](const Point &p, const Point &q)
{
if(pii(p.y, p.x)!=pii(q.y, q.x)) return pii(p.y, p.x)<pii(q.y, q.x);
else return p.p<q.p;
});
for(i=1; i<=N+Q; i++)
{
if(A[i].p==-1) update(A[i].x, query(A[i].x)+1);
else ans[A[i].p]=query(A[i].x);
}
for(i=1; i<=Q; i++) printf("%d\n", ans[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |