#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 200000;
int N;
vector<pii> v1, v2;
int idx[MAX_N+1];
vector<int> g[MAX_N+1];
int chk[MAX_N+1];
int ans;
struct SEG{
SEG(int l, int r, int lazy, int mn) : l(l), r(r), lazy(lazy), mn(mn) {}
int l, r;
int lazy, mn;
};
vector<SEG> seg;
vector<int> cnt;
void init(int idx, int s, int e){
seg.push_back({-1, -1, 0, INF});
if(s==e) return;
seg[idx].l = seg.size(); init(seg[idx].l, s, (s+e)/2);
seg[idx].r = seg.size(); init(seg[idx].r, (s+e)/2+1, e);
}
void update(int idx, int s, int e, int x, int y){
if(s!=e && seg[idx].lazy!=0){
seg[seg[idx].l].lazy += seg[idx].lazy; seg[seg[idx].l].mn += seg[idx].lazy;
seg[seg[idx].r].lazy += seg[idx].lazy; seg[seg[idx].r].mn += seg[idx].lazy;
seg[idx].lazy = 0;
}
seg[idx].mn = min(seg[idx].mn, y);
if(s==e) return;
if(x<=(s+e)/2) update(seg[idx].l, s, (s+e)/2, x, y);
else update(seg[idx].r, (s+e)/2+1, e, x, y);
}
void lazy(int idx, int s, int e, int x, int y, int z){
if(idx==-1) return;
if(s!=e && seg[idx].lazy!=0){
seg[seg[idx].l].lazy += seg[idx].lazy; seg[seg[idx].l].mn += seg[idx].lazy;
seg[seg[idx].r].lazy += seg[idx].lazy; seg[seg[idx].r].mn += seg[idx].lazy;
seg[idx].lazy = 0;
}
if(x<=s && e<=y){
seg[idx].lazy += z; seg[idx].mn += z; return;
}
else if(x>e || y<s) return;
lazy(seg[idx].l, s, (s+e)/2, x, y, z); lazy(seg[idx].r, (s+e)/2+1, e, x, y, z);
seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);
}
int min(int idx, int s, int e, int x, int y){
if(idx==-1) return INF;
if(s!=e && seg[idx].lazy!=0){
seg[seg[idx].l].lazy += seg[idx].lazy; seg[seg[idx].l].mn += seg[idx].lazy;
seg[seg[idx].r].lazy += seg[idx].lazy; seg[seg[idx].r].mn += seg[idx].lazy;
seg[idx].lazy = 0;
}
if(x<=s && e<=y){
return seg[idx].mn;
}else if(x>e || y<s) return INF;
return min(min(seg[idx].l, s, (s+e)/2, x, y), min(seg[idx].r, (s+e)/2+1, e, x, y));
}
bool match(int x, int y){
//cout<<'*'<<x<<' '<<y<<endl;
if(cnt.empty()) return true;
int s = 0, e = cnt.size(), m;
while(s<e){
m = (s+e)/2;
if(cnt[m]>=y) e = m;
else s = m+1;
}
lazy(0, 0, N-1, s, cnt.size()-1, -1);
if(min(0, 0, N-1, 0, cnt.size()-1)>=0){
return true;
}
lazy(0, 0, N-1, s, cnt.size()-1, 1); return false;
}
int main(){
scanf("%d", &N);
init(0, 0, N-1);
ans = N;
for(int i=0 ;i<N; i++){
int a, b; scanf("%d%d", &a, &b);
v1.push_back({a, b});
}for(int i=0; i<N; i++){
int a, b; scanf("%d%d", &a, &b);
v2.push_back({a, b});
}
for(int i=0; i<N; i++){
if(i==0) idx[i] = 0;
else idx[i] = idx[i-1];
while(idx[i]!=N-1 && v2[idx[i]+1].SE >= v1[i].SE){
idx[i]++;
}
}
int index = 0;
int t = 0, num = 0;
for(int i=0; i<N; i++){
while(index<N && v2[index].SE >= v1[i].SE){
g[v2[index].FI].push_back(index); index++; num++;
}
if(!g[v1[i].FI].empty() && match(i, g[v1[i].FI].back())){
int k = g[v1[i].FI].back();
//cout<<i<<' '<<k<<endl;
//cout<<i<<' '<<k<<endl;
ans--;
g[v1[i].FI].pop_back(); num--;
}else{
update(0, 0, N-1, t, num-t-1);
cnt.push_back(idx[i]);
t++;
}
}
printf("%d", ans);
return 0;
}
Compilation message
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:129:8: warning: unused variable 'k' [-Wunused-variable]
int k = g[v1[i].FI].back();
^
worst_reporter2.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
worst_reporter2.cpp:109:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int a, b; scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
worst_reporter2.cpp:112:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int a, b; scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5020 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
8 ms |
4992 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5020 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
8 ms |
4992 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
5040 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
4992 KB |
Output is correct |
18 |
Correct |
5 ms |
4992 KB |
Output is correct |
19 |
Correct |
7 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4992 KB |
Output is correct |
21 |
Correct |
7 ms |
5096 KB |
Output is correct |
22 |
Correct |
6 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5020 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
8 ms |
4992 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
5040 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
4992 KB |
Output is correct |
18 |
Correct |
5 ms |
4992 KB |
Output is correct |
19 |
Correct |
7 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4992 KB |
Output is correct |
21 |
Correct |
7 ms |
5096 KB |
Output is correct |
22 |
Correct |
6 ms |
4992 KB |
Output is correct |
23 |
Correct |
12 ms |
5376 KB |
Output is correct |
24 |
Correct |
12 ms |
5472 KB |
Output is correct |
25 |
Correct |
11 ms |
5476 KB |
Output is correct |
26 |
Correct |
16 ms |
5376 KB |
Output is correct |
27 |
Correct |
11 ms |
5376 KB |
Output is correct |
28 |
Correct |
11 ms |
5500 KB |
Output is correct |
29 |
Correct |
13 ms |
5500 KB |
Output is correct |
30 |
Correct |
13 ms |
5504 KB |
Output is correct |
31 |
Correct |
14 ms |
5500 KB |
Output is correct |
32 |
Correct |
11 ms |
5500 KB |
Output is correct |
33 |
Correct |
11 ms |
5504 KB |
Output is correct |
34 |
Correct |
16 ms |
5500 KB |
Output is correct |
35 |
Correct |
15 ms |
5460 KB |
Output is correct |
36 |
Correct |
14 ms |
5500 KB |
Output is correct |
37 |
Correct |
10 ms |
5500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5020 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
8 ms |
4992 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
5040 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
4992 KB |
Output is correct |
18 |
Correct |
5 ms |
4992 KB |
Output is correct |
19 |
Correct |
7 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4992 KB |
Output is correct |
21 |
Correct |
7 ms |
5096 KB |
Output is correct |
22 |
Correct |
6 ms |
4992 KB |
Output is correct |
23 |
Correct |
12 ms |
5376 KB |
Output is correct |
24 |
Correct |
12 ms |
5472 KB |
Output is correct |
25 |
Correct |
11 ms |
5476 KB |
Output is correct |
26 |
Correct |
16 ms |
5376 KB |
Output is correct |
27 |
Correct |
11 ms |
5376 KB |
Output is correct |
28 |
Correct |
11 ms |
5500 KB |
Output is correct |
29 |
Correct |
13 ms |
5500 KB |
Output is correct |
30 |
Correct |
13 ms |
5504 KB |
Output is correct |
31 |
Correct |
14 ms |
5500 KB |
Output is correct |
32 |
Correct |
11 ms |
5500 KB |
Output is correct |
33 |
Correct |
11 ms |
5504 KB |
Output is correct |
34 |
Correct |
16 ms |
5500 KB |
Output is correct |
35 |
Correct |
15 ms |
5460 KB |
Output is correct |
36 |
Correct |
14 ms |
5500 KB |
Output is correct |
37 |
Correct |
10 ms |
5500 KB |
Output is correct |
38 |
Correct |
482 ms |
26356 KB |
Output is correct |
39 |
Correct |
589 ms |
25236 KB |
Output is correct |
40 |
Correct |
446 ms |
25168 KB |
Output is correct |
41 |
Correct |
451 ms |
25148 KB |
Output is correct |
42 |
Correct |
311 ms |
24860 KB |
Output is correct |
43 |
Correct |
384 ms |
21532 KB |
Output is correct |
44 |
Correct |
340 ms |
21532 KB |
Output is correct |
45 |
Correct |
318 ms |
21508 KB |
Output is correct |
46 |
Correct |
421 ms |
22300 KB |
Output is correct |
47 |
Correct |
191 ms |
22668 KB |
Output is correct |
48 |
Correct |
327 ms |
21104 KB |
Output is correct |
49 |
Correct |
253 ms |
21124 KB |
Output is correct |
50 |
Correct |
272 ms |
21148 KB |
Output is correct |
51 |
Correct |
455 ms |
21960 KB |
Output is correct |
52 |
Correct |
178 ms |
21136 KB |
Output is correct |