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 unsigned long long ull;
int hmt() {int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';if(n) x=-x;return x;}
#define in hmt()
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forb(i,BS) for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=400010;
int n,m,t[N],ans[N];
pii a[N];
struct oo {int a,b,id;} q[N];
vector<int> ea,eb;
void update(int i,int x)
{
for(;i<=400000;i+=i&-i) t[i]=max(t[i],x);
}
int get(int i)
{
int g=0;
for(;i;i-=i&-i) g=max(g,t[i]);
return g;
}
bool cmp(pii u,pii v)
{
return (u.fi!=v.fi)?(u.fi>v.fi):(u.se<v.se);
}
bool sor(oo u,oo v) {return u.a>v.a;}
int main()
{
//freopen("Matryoshka.inp","r",stdin);
n=in,m=in;
forinc(i,1,n)
{
a[i]={in,in};
ea.pb(a[i].fi),eb.pb(a[i].se);
}
forinc(i,1,m)
{
q[i]={in,in,i};
ea.pb(q[i].a),eb.pb(q[i].b);
}
sort(all(ea));sort(all(eb));
forinc(i,1,n)
{
a[i].fi=lower_bound(all(ea),a[i].fi)-ea.begin()+1;
a[i].se=lower_bound(all(eb),a[i].se)-eb.begin()+1;
}
forinc(i,1,m)
{
q[i].a=lower_bound(all(ea),q[i].a)-ea.begin()+1;
q[i].b=lower_bound(all(eb),q[i].b)-eb.begin()+1;
}
sort(a+1,a+n+1,cmp);
sort(q+1,q+m+1,sor);
int j=1;
forinc(i,1,m)
{
while(j<=n&&a[j].fi>=q[i].a) update(a[j].se,get(a[j].se)+1),++j;
ans[q[i].id]=get(q[i].b);
}
forinc(i,1,m) cout<<ans[i]<<"\n";
}
# | 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... |