#include <bits/stdc++.h>
using namespace std;
const int N=200050;
int a[N],b[N],c[N],d[N];
const int M=2*N;
int mx[M],lzy[M],ls[M],rs[M],tsz,root;
void Set(int &c, int ss, int se, int qs, int qe, int f)
{
if(qs>qe || qs>se || ss>qe) return;
if(!c) c=++tsz;
if(qs<=ss && qe>=se){ lzy[c]+=f;mx[c]+=f;return;}
int mid=ss+se>>1;
Set(ls[c],ss,mid,qs,qe,f);
Set(rs[c],mid+1,se,qs,qe,f);
mx[c]=max(mx[ls[c]],mx[rs[c]])+lzy[c];
}
int Get(int c, int ss, int se, int qs, int qe)
{
if(qs<=ss && qe>=se) return mx[c];
int mid=ss+se>>1;
if(qe<=mid) return Get(ls[c],ss,mid,qs,qe);
if(qs>mid) return Get(rs[c],mid+1,se,qs,qe);
return max(Get(ls[c],ss,mid,qs,qe),Get(rs[c],mid+1,se,qs,qe))+lzy[c];
}
int main()
{
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]);
for(int i=1;i<=n;i++) scanf("%i %i",&c[i],&d[i]);
map<int,stack<int>> cnt;
int all=0,ans=n;
for(int i=n,j=n;i>=1;i--)
{
for(;j>=1 && b[j]<=d[i];j--)
{
cnt[a[j]].push(i);
Set(root,1,n,1,i,-1);
}
if(cnt[c[i]].size())
{
int x=cnt[c[i]].top();
if(Get(root,1,n,1,x)<0)
{
cnt[c[i]].pop();
Set(root,1,n,1,x,1);
ans--;
}
else Set(root,1,n,1,i,1);
}
else Set(root,1,n,1,i,1);
}
printf("%i\n",ans);
return 0;
}
Compilation message
worst_reporter2.cpp: In function 'void Set(int&, int, int, int, int, int)':
worst_reporter2.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
worst_reporter2.cpp: In function 'int Get(int, int, int, int, int)':
worst_reporter2.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:32:6: warning: unused variable 'all' [-Wunused-variable]
int all=0,ans=n;
^~~
worst_reporter2.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
worst_reporter2.cpp:29:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:30:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%i %i",&c[i],&d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
300 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 |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
300 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 |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
300 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 |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
300 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 |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |