#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
6 ms |
508 KB |
Output is correct |
27 |
Correct |
5 ms |
604 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
632 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
632 KB |
Output is correct |
26 |
Correct |
6 ms |
508 KB |
Output is correct |
27 |
Correct |
5 ms |
604 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
5 ms |
632 KB |
Output is correct |
36 |
Correct |
424 ms |
15944 KB |
Output is correct |
37 |
Correct |
381 ms |
14604 KB |
Output is correct |
38 |
Correct |
151 ms |
6232 KB |
Output is correct |
39 |
Correct |
358 ms |
13652 KB |
Output is correct |
40 |
Correct |
360 ms |
14048 KB |
Output is correct |
41 |
Correct |
405 ms |
15116 KB |
Output is correct |
42 |
Correct |
173 ms |
11348 KB |
Output is correct |
43 |
Correct |
119 ms |
11480 KB |
Output is correct |
44 |
Correct |
457 ms |
18440 KB |
Output is correct |
45 |
Correct |
459 ms |
18512 KB |
Output is correct |
46 |
Correct |
455 ms |
18444 KB |
Output is correct |
47 |
Correct |
463 ms |
18136 KB |
Output is correct |
48 |
Correct |
454 ms |
18708 KB |
Output is correct |
49 |
Correct |
456 ms |
18136 KB |
Output is correct |
50 |
Correct |
457 ms |
18772 KB |
Output is correct |