#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n;
int a[200005],b[200005],c[200005],d[200005];
multiset<int> pos[200005],col[200005];
bool act[200005],took[200005];
struct node{
int sum,mn,idx;
}st[800005];
node operator+(node a,node b){
node ret;
ret.sum=a.sum+b.sum;
ret.mn=min(a.mn+b.sum,b.mn);
ret.idx=(ret.mn==a.mn+b.sum?a.idx:b.idx);
return ret;
}
void build(int id,int l,int r){
st[id].sum=st[id].mn=0;
if(l==r) return (void)(st[id].idx=l);
int mid=(l+r)/2;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
st[id]=st[id<<1]+st[id<<1|1];
}
void change(int id,int l,int r,int p,int v){
if(l==r) return (void)(st[id].sum+=v,st[id].mn+=v);
int mid=(l+r)/2;
if(p<=mid) change(id<<1,l,mid,p,v);
else change(id<<1|1,mid+1,r,p,v);
st[id]=st[id<<1]+st[id<<1|1];
}
node query(int id,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return st[id];
int mid=(l+r)/2;
if(qr<=mid) return query(id<<1,l,mid,ql,qr);
else if(ql>mid) return query(id<<1|1,mid+1,r,ql,qr);
else return query(id<<1,l,mid,ql,qr)+query(id<<1|1,mid+1,r,ql,qr);
}
int main(){
n=readint();
for(int i=1;i<=n;i++) a[i]=readint(),b[i]=readint();
for(int i=1;i<=n;i++) c[i]=readint(),d[i]=readint();
build(1,1,n);
int ans=n,ptr=n,brd=n;
for(int i=n;i>=1;i--){
while(ptr>=1&&b[ptr]<=d[i]){
pos[a[ptr]].insert(i);
col[i].insert(a[ptr]);
change(1,1,n,i,+1);
ptr--;
}
change(1,1,n,i,-1);
act[i]=true;
if(!pos[c[i]].empty()){
change(1,1,n,i,+1);
int idx=*pos[c[i]].begin();
pos[c[i]].erase(pos[c[i]].begin());
change(1,1,n,idx,-1);
col[idx].erase(col[idx].find(c[i]));
act[i]=false;
ans--;
}
int j=query(1,1,n,i,n).idx;
if(j<=brd&&query(1,1,n,j,n).sum==0){
for(int k=j;k<=brd;k++){
for(auto&p:col[k]){
while(pos[p].find(k)!=pos[p].end()){
change(1,1,n,k,-1);
pos[p].erase(pos[p].find(k));
}
}
col[k].clear();
if(act[k]){
change(1,1,n,k,1);
act[k]=false;
}
}
brd=j-1;
}
}
printf("%d\n",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22876 KB |
Output is correct |
2 |
Correct |
4 ms |
22876 KB |
Output is correct |
3 |
Correct |
5 ms |
23004 KB |
Output is correct |
4 |
Correct |
4 ms |
22872 KB |
Output is correct |
5 |
Correct |
4 ms |
22876 KB |
Output is correct |
6 |
Correct |
4 ms |
22876 KB |
Output is correct |
7 |
Correct |
4 ms |
22876 KB |
Output is correct |
8 |
Correct |
4 ms |
22876 KB |
Output is correct |
9 |
Correct |
4 ms |
22876 KB |
Output is correct |
10 |
Correct |
5 ms |
23016 KB |
Output is correct |
11 |
Correct |
5 ms |
22872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22876 KB |
Output is correct |
2 |
Correct |
4 ms |
22876 KB |
Output is correct |
3 |
Correct |
5 ms |
23004 KB |
Output is correct |
4 |
Correct |
4 ms |
22872 KB |
Output is correct |
5 |
Correct |
4 ms |
22876 KB |
Output is correct |
6 |
Correct |
4 ms |
22876 KB |
Output is correct |
7 |
Correct |
4 ms |
22876 KB |
Output is correct |
8 |
Correct |
4 ms |
22876 KB |
Output is correct |
9 |
Correct |
4 ms |
22876 KB |
Output is correct |
10 |
Correct |
5 ms |
23016 KB |
Output is correct |
11 |
Correct |
5 ms |
22872 KB |
Output is correct |
12 |
Correct |
5 ms |
22876 KB |
Output is correct |
13 |
Correct |
4 ms |
22876 KB |
Output is correct |
14 |
Correct |
5 ms |
22876 KB |
Output is correct |
15 |
Correct |
5 ms |
22876 KB |
Output is correct |
16 |
Correct |
4 ms |
22996 KB |
Output is correct |
17 |
Correct |
5 ms |
22876 KB |
Output is correct |
18 |
Correct |
4 ms |
22876 KB |
Output is correct |
19 |
Correct |
4 ms |
22872 KB |
Output is correct |
20 |
Correct |
5 ms |
22876 KB |
Output is correct |
21 |
Correct |
5 ms |
22876 KB |
Output is correct |
22 |
Correct |
5 ms |
22872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22876 KB |
Output is correct |
2 |
Correct |
4 ms |
22876 KB |
Output is correct |
3 |
Correct |
5 ms |
23004 KB |
Output is correct |
4 |
Correct |
4 ms |
22872 KB |
Output is correct |
5 |
Correct |
4 ms |
22876 KB |
Output is correct |
6 |
Correct |
4 ms |
22876 KB |
Output is correct |
7 |
Correct |
4 ms |
22876 KB |
Output is correct |
8 |
Correct |
4 ms |
22876 KB |
Output is correct |
9 |
Correct |
4 ms |
22876 KB |
Output is correct |
10 |
Correct |
5 ms |
23016 KB |
Output is correct |
11 |
Correct |
5 ms |
22872 KB |
Output is correct |
12 |
Correct |
5 ms |
22876 KB |
Output is correct |
13 |
Correct |
4 ms |
22876 KB |
Output is correct |
14 |
Correct |
5 ms |
22876 KB |
Output is correct |
15 |
Correct |
5 ms |
22876 KB |
Output is correct |
16 |
Correct |
4 ms |
22996 KB |
Output is correct |
17 |
Correct |
5 ms |
22876 KB |
Output is correct |
18 |
Correct |
4 ms |
22876 KB |
Output is correct |
19 |
Correct |
4 ms |
22872 KB |
Output is correct |
20 |
Correct |
5 ms |
22876 KB |
Output is correct |
21 |
Correct |
5 ms |
22876 KB |
Output is correct |
22 |
Correct |
5 ms |
22872 KB |
Output is correct |
23 |
Correct |
9 ms |
25432 KB |
Output is correct |
24 |
Correct |
8 ms |
25436 KB |
Output is correct |
25 |
Correct |
8 ms |
25436 KB |
Output is correct |
26 |
Correct |
8 ms |
25180 KB |
Output is correct |
27 |
Correct |
9 ms |
25692 KB |
Output is correct |
28 |
Correct |
8 ms |
25180 KB |
Output is correct |
29 |
Correct |
8 ms |
25180 KB |
Output is correct |
30 |
Correct |
8 ms |
25176 KB |
Output is correct |
31 |
Correct |
8 ms |
25180 KB |
Output is correct |
32 |
Correct |
10 ms |
25644 KB |
Output is correct |
33 |
Correct |
9 ms |
25176 KB |
Output is correct |
34 |
Correct |
9 ms |
25432 KB |
Output is correct |
35 |
Correct |
8 ms |
25328 KB |
Output is correct |
36 |
Correct |
8 ms |
25180 KB |
Output is correct |
37 |
Correct |
9 ms |
25584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22876 KB |
Output is correct |
2 |
Correct |
4 ms |
22876 KB |
Output is correct |
3 |
Correct |
5 ms |
23004 KB |
Output is correct |
4 |
Correct |
4 ms |
22872 KB |
Output is correct |
5 |
Correct |
4 ms |
22876 KB |
Output is correct |
6 |
Correct |
4 ms |
22876 KB |
Output is correct |
7 |
Correct |
4 ms |
22876 KB |
Output is correct |
8 |
Correct |
4 ms |
22876 KB |
Output is correct |
9 |
Correct |
4 ms |
22876 KB |
Output is correct |
10 |
Correct |
5 ms |
23016 KB |
Output is correct |
11 |
Correct |
5 ms |
22872 KB |
Output is correct |
12 |
Correct |
5 ms |
22876 KB |
Output is correct |
13 |
Correct |
4 ms |
22876 KB |
Output is correct |
14 |
Correct |
5 ms |
22876 KB |
Output is correct |
15 |
Correct |
5 ms |
22876 KB |
Output is correct |
16 |
Correct |
4 ms |
22996 KB |
Output is correct |
17 |
Correct |
5 ms |
22876 KB |
Output is correct |
18 |
Correct |
4 ms |
22876 KB |
Output is correct |
19 |
Correct |
4 ms |
22872 KB |
Output is correct |
20 |
Correct |
5 ms |
22876 KB |
Output is correct |
21 |
Correct |
5 ms |
22876 KB |
Output is correct |
22 |
Correct |
5 ms |
22872 KB |
Output is correct |
23 |
Correct |
9 ms |
25432 KB |
Output is correct |
24 |
Correct |
8 ms |
25436 KB |
Output is correct |
25 |
Correct |
8 ms |
25436 KB |
Output is correct |
26 |
Correct |
8 ms |
25180 KB |
Output is correct |
27 |
Correct |
9 ms |
25692 KB |
Output is correct |
28 |
Correct |
8 ms |
25180 KB |
Output is correct |
29 |
Correct |
8 ms |
25180 KB |
Output is correct |
30 |
Correct |
8 ms |
25176 KB |
Output is correct |
31 |
Correct |
8 ms |
25180 KB |
Output is correct |
32 |
Correct |
10 ms |
25644 KB |
Output is correct |
33 |
Correct |
9 ms |
25176 KB |
Output is correct |
34 |
Correct |
9 ms |
25432 KB |
Output is correct |
35 |
Correct |
8 ms |
25328 KB |
Output is correct |
36 |
Correct |
8 ms |
25180 KB |
Output is correct |
37 |
Correct |
9 ms |
25584 KB |
Output is correct |
38 |
Correct |
191 ms |
38140 KB |
Output is correct |
39 |
Correct |
193 ms |
36580 KB |
Output is correct |
40 |
Correct |
185 ms |
38024 KB |
Output is correct |
41 |
Correct |
176 ms |
35252 KB |
Output is correct |
42 |
Correct |
308 ms |
52564 KB |
Output is correct |
43 |
Correct |
172 ms |
34420 KB |
Output is correct |
44 |
Correct |
177 ms |
34444 KB |
Output is correct |
45 |
Correct |
177 ms |
34576 KB |
Output is correct |
46 |
Correct |
158 ms |
34132 KB |
Output is correct |
47 |
Correct |
230 ms |
49488 KB |
Output is correct |
48 |
Correct |
176 ms |
33992 KB |
Output is correct |
49 |
Correct |
193 ms |
34092 KB |
Output is correct |
50 |
Correct |
179 ms |
33992 KB |
Output is correct |
51 |
Correct |
174 ms |
33904 KB |
Output is correct |
52 |
Correct |
227 ms |
48008 KB |
Output is correct |