#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
vector<ii> segt1[4*100100];
ii segt2[4*100100],arr[100001];
int fr[100001];
vi v;
unordered_map<lli,lli> m1;
void merge(int node)
{
int s=0,s1=0;
while(s+s1!=segt1[2*node+1].size()+segt1[2*node+2].size())
{
if(segt1[2*node+1].size()!=s&&(segt1[2*node+2].size()==s1||segt1[2*node+1][s]<=segt1[2*node+2][s1]))
{
segt1[node].pb(segt1[2*node+1][s]);
s++;
}
else
{
segt1[node].pb(segt1[2*node+2][s1]);
s1++;
}
}
}
void build(int node,int l,int r)
{
if(l==r)
{
segt1[node].pb(mp(arr[l].S,l));
return;
}
int m=(l+r)/2;
build(2*node+1,l,m);
build(2*node+2,m+1,r);
merge(node);
}
void up2(int node,int l,int r,int in,ii val)
{
if(l==r)
{
segt2[node]=val;
return;
}
int m=(l+r)/2;
if(in<=m)
up2(2*node+1,l,m,in,val);
else
up2(2*node+2,m+1,r,in,val);
if(segt2[2*node+1].F==segt2[2*node+2].F)
segt2[node]=min(segt2[2*node+1],segt2[2*node+2]);
else
segt2[node]=max(segt2[2*node+1],segt2[2*node+2]);
}
int qu1(int node,int l,int r,int s,int e,int val)
{
if(l>e||r<s)
return(1000000000);
if(l>=s&&r<=e)
{
int it=lower_bound(all(segt1[node]),mp(val,0))-segt1[node].begin();
if(it>=segt1[node].size()||segt1[node][it].F>val)
it--;
if(it==-1)
return(1000000000);
else
return(segt1[node][it].S);
}
int m=(l+r)/2;
int q1=qu1(2*node+1,l,m,s,e,val),q2=qu1(2*node+2,m+1,r,s,e,val);
return(min(q1,q2));
}
ii qu2(int node,int l,int r,int s,int e,int n,int k)
{
if(r<s||l>e)
return(mp(0,-1));
if(l>=s&&r<=e)
{
if(qu1(0,0,n-1,segt2[node].S+1,n-1,k)!=1000000000)
return(segt2[node]);
else
return(mp(0,-1));
}
int m=(l+r)/2;
ii q1=qu2(2*node+1,l,m,s,e,n,k),q2=qu2(2*node+2,m+1,r,s,e,n,k);
if(q1.F==q2.F)
return(min(q1,q2));
else
return(max(q1,q2));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(int i=0;i<4*100010;++i)
segt2[i]=mp(0,-1);
for(;test>0;--test)
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;++i)
{
int f,s;
cin>>f>>s;
arr[i]=mp(s,f);
v.pb(f);
}
for(int i=0;i<m;++i)
{
cin>>fr[i];
v.pb(fr[i]);
}
sort(all(v));
for(lli i=0;i<v.size();++i)
m1[v[i]]=i+1;
for(int i=0;i<n;++i)
arr[i].S=m1[arr[i].S];
for(int i=0;i<m;++i)
fr[i]=m1[fr[i]];
sort(arr,arr+n);
build(0,0,n-1);
lli ma=0;
sort(fr,fr+m);
for(int i=0;i<m;++i)
{
ii sl=qu2(0,0,m+n+1,0,fr[i],n,fr[i]);
int in=qu1(0,0,n-1,sl.S+1,n-1,fr[i]);
if(in!=1000000000)
{
up2(0,0,m+n+1,fr[i],mp(sl.F+1,in));
ma=max(ma,sl.F+1);
}
}
cout<<ma<<endl;
}
return(0);
}
Compilation message
joi2019_ho_t2.cpp: In function 'void merge(int)':
joi2019_ho_t2.cpp:26:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(s+s1!=segt1[2*node+1].size()+segt1[2*node+2].size())
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:28:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(segt1[2*node+1].size()!=s&&(segt1[2*node+2].size()==s1||segt1[2*node+1][s]<=segt1[2*node+2][s1]))
~~~~~~~~~~~~~~~~~~~~~~^~~
joi2019_ho_t2.cpp:28:58: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(segt1[2*node+1].size()!=s&&(segt1[2*node+2].size()==s1||segt1[2*node+1][s]<=segt1[2*node+2][s1]))
~~~~~~~~~~~~~~~~~~~~~~^~~~
joi2019_ho_t2.cpp: In function 'int qu1(int, int, int, int, int, int)':
joi2019_ho_t2.cpp:76:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it>=segt1[node].size()||segt1[node][it].F>val)
~~^~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:129:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(lli i=0;i<v.size();++i)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12928 KB |
Output is correct |
2 |
Correct |
14 ms |
12928 KB |
Output is correct |
3 |
Correct |
12 ms |
12928 KB |
Output is correct |
4 |
Correct |
12 ms |
12928 KB |
Output is correct |
5 |
Correct |
13 ms |
12928 KB |
Output is correct |
6 |
Incorrect |
12 ms |
12928 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12928 KB |
Output is correct |
2 |
Correct |
14 ms |
12928 KB |
Output is correct |
3 |
Correct |
12 ms |
12928 KB |
Output is correct |
4 |
Correct |
12 ms |
12928 KB |
Output is correct |
5 |
Correct |
13 ms |
12928 KB |
Output is correct |
6 |
Incorrect |
12 ms |
12928 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12928 KB |
Output is correct |
2 |
Correct |
14 ms |
12928 KB |
Output is correct |
3 |
Correct |
12 ms |
12928 KB |
Output is correct |
4 |
Correct |
12 ms |
12928 KB |
Output is correct |
5 |
Correct |
13 ms |
12928 KB |
Output is correct |
6 |
Incorrect |
12 ms |
12928 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |