#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int n,m,b[100005],mx,tree[4*100005],dp[100005];
pair<int,int>a[100005];
vector<int>v,v1;
multiset<int>ms;
map<int,int>mp;
void up(int nod,int l,int r,int x,int val)
{
if(x<l||r<x)return;
if(l==r)
{
tree[nod]=val;
return;
}
int mid=(l+r)/2;
up(nod*2,l,mid,x,val);
up(nod*2+1,mid+1,r,x,val);
tree[nod]=max(tree[nod*2],tree[nod*2+1]);
}
int qu(int nod,int l,int r,int x,int y)
{
if(x<=l&&r<=y)return tree[nod];
if(y<l||r<x)return 0;
int mid=(l+r)/2;
return max(qu(nod*2,l,mid,x,y),qu(nod*2+1,mid+1,r,x,y));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
sort(a,a+n);
for(int i=0;i<m;i++)cin>>b[i];
sort(b,b+m);
int x=0;
for(int i=0;i<m;i++)
{
while(a[x].first<=b[i]&&x<n)
{
ms.insert(a[x].second);
x++;
}
if(ms.size()==0)continue;
v.push_back(*ms.begin());
v1.push_back(*ms.begin());
ms.erase(ms.begin());
}
int k=0;
sort(v1.begin(),v1.end());
for(int i=0;i<v1.size();i++)mp[v1[i]]=++k;
for(int i=0;i<v.size();i++)
{
v[i]=mp[v[i]];
dp[v[i]]=1+qu(1,0,m,0,v[i]);
up(1,0,m,v[i],dp[v[i]]);
mx=max(mx,dp[v[i]]);
}
cout<<mx;
}
Compilation message
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v1.size();i++)mp[v1[i]]=++k;
~^~~~~~~~~~
joi2019_ho_t2.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 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 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 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 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 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 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |