#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 4e5;
int N;
pii _A[MAXN+10];
int A[MAXN+10];
int B[MAXN+10];
vector<int> V[MAXN+10];
struct SEG
{
int tree[MAXN*4+10], lazy[MAXN*4+10];
void init(int node, int tl, int tr)
{
lazy[node]=0;
if(tl==tr)
{
tree[node]=B[tl];
return;
}
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
tree[node]=min(tree[node*2], tree[node*2+1]);
}
void busy(int node, int tl, int tr)
{
tree[node]+=lazy[node];
if(tl!=tr)
{
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
void update(int node, int tl, int tr, int l, int r)
{
busy(node, tl, tr);
if(r<tl || tr<l) return;
if(l<=tl && tr<=r)
{
lazy[node]--;
busy(node, tl, tr);
return;
}
int mid=tl+tr>>1;
update(node*2, tl, mid, l, r);
update(node*2+1, mid+1, tr, l, r);
tree[node]=min(tree[node*2], tree[node*2+1]);
}
int query(int node, int tl, int tr, int l, int r)
{
busy(node, tl, tr);
if(l<=tl && tr<=r) return tree[node];
if(r<tl || tr<l) return 987654321;
int mid=tl+tr>>1;
return min(query(node*2, tl, mid, l, r), query(node*2+1, mid+1, tr, l, r));
}
}seg;
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%d%d", &_A[i].second, &_A[i].first), _A[i].second*=-1;
for(int i=1; i<=N; i++) scanf("%d%d", &_A[i+N].second, &_A[i+N].first);
N*=2;
sort(_A+1, _A+N+1);
for(int i=1; i<=N; i++) A[i]=_A[i].second;
for(int i=1; i<=N; i++)
{
if(A[i]<0) B[i]=B[i-1]+1;
else B[i]=B[i-1]-1;
}
seg.init(1, 1, N);
int ans=N/2;
for(int i=1; i<=N; i++)
{
if(A[i]<0)
{
V[-A[i]].push_back(i);
}
else
{
if(V[A[i]].empty()) continue;
if(seg.query(1, 1, N, V[A[i]].back(), i-1)<1)
{
V[A[i]].clear();
}
else
{
seg.update(1, 1, N, V[A[i]].back(), i-1);
V[A[i]].pop_back();
ans--;
}
}
}
printf("%d\n", ans);
}
Compilation message
worst_reporter2.cpp: In member function 'void SEG::init(int, int, int)':
worst_reporter2.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int mid=tl+tr>>1;
| ~~^~~
worst_reporter2.cpp: In member function 'void SEG::update(int, int, int, int, int)':
worst_reporter2.cpp:56:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid=tl+tr>>1;
| ~~^~~
worst_reporter2.cpp: In member function 'int SEG::query(int, int, int, int, int)':
worst_reporter2.cpp:67:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
67 | int mid=tl+tr>>1;
| ~~^~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
74 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
worst_reporter2.cpp:75:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
75 | for(int i=1; i<=N; i++) scanf("%d%d", &_A[i].second, &_A[i].first), _A[i].second*=-1;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:76:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
76 | for(int i=1; i<=N; i++) scanf("%d%d", &_A[i+N].second, &_A[i+N].first);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
8 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
8 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9708 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
9 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
8 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9836 KB |
Output is correct |
22 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
8 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9708 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
9 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
8 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9836 KB |
Output is correct |
22 |
Correct |
7 ms |
9708 KB |
Output is correct |
23 |
Correct |
12 ms |
10476 KB |
Output is correct |
24 |
Correct |
15 ms |
10348 KB |
Output is correct |
25 |
Correct |
11 ms |
10348 KB |
Output is correct |
26 |
Correct |
11 ms |
10348 KB |
Output is correct |
27 |
Correct |
12 ms |
10348 KB |
Output is correct |
28 |
Correct |
13 ms |
10220 KB |
Output is correct |
29 |
Correct |
12 ms |
10252 KB |
Output is correct |
30 |
Correct |
12 ms |
10220 KB |
Output is correct |
31 |
Correct |
11 ms |
10220 KB |
Output is correct |
32 |
Correct |
14 ms |
10220 KB |
Output is correct |
33 |
Correct |
12 ms |
10220 KB |
Output is correct |
34 |
Correct |
13 ms |
10220 KB |
Output is correct |
35 |
Correct |
12 ms |
10220 KB |
Output is correct |
36 |
Correct |
11 ms |
10220 KB |
Output is correct |
37 |
Correct |
13 ms |
10220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
8 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9708 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
9 ms |
9708 KB |
Output is correct |
19 |
Correct |
8 ms |
9708 KB |
Output is correct |
20 |
Correct |
8 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9836 KB |
Output is correct |
22 |
Correct |
7 ms |
9708 KB |
Output is correct |
23 |
Correct |
12 ms |
10476 KB |
Output is correct |
24 |
Correct |
15 ms |
10348 KB |
Output is correct |
25 |
Correct |
11 ms |
10348 KB |
Output is correct |
26 |
Correct |
11 ms |
10348 KB |
Output is correct |
27 |
Correct |
12 ms |
10348 KB |
Output is correct |
28 |
Correct |
13 ms |
10220 KB |
Output is correct |
29 |
Correct |
12 ms |
10252 KB |
Output is correct |
30 |
Correct |
12 ms |
10220 KB |
Output is correct |
31 |
Correct |
11 ms |
10220 KB |
Output is correct |
32 |
Correct |
14 ms |
10220 KB |
Output is correct |
33 |
Correct |
12 ms |
10220 KB |
Output is correct |
34 |
Correct |
13 ms |
10220 KB |
Output is correct |
35 |
Correct |
12 ms |
10220 KB |
Output is correct |
36 |
Correct |
11 ms |
10220 KB |
Output is correct |
37 |
Correct |
13 ms |
10220 KB |
Output is correct |
38 |
Correct |
270 ms |
28288 KB |
Output is correct |
39 |
Correct |
265 ms |
33516 KB |
Output is correct |
40 |
Correct |
258 ms |
33388 KB |
Output is correct |
41 |
Correct |
262 ms |
33460 KB |
Output is correct |
42 |
Correct |
326 ms |
33516 KB |
Output is correct |
43 |
Correct |
277 ms |
28524 KB |
Output is correct |
44 |
Correct |
267 ms |
28524 KB |
Output is correct |
45 |
Correct |
270 ms |
28524 KB |
Output is correct |
46 |
Correct |
190 ms |
28396 KB |
Output is correct |
47 |
Correct |
364 ms |
30828 KB |
Output is correct |
48 |
Correct |
270 ms |
28140 KB |
Output is correct |
49 |
Correct |
302 ms |
28268 KB |
Output is correct |
50 |
Correct |
306 ms |
28128 KB |
Output is correct |
51 |
Correct |
191 ms |
28156 KB |
Output is correct |
52 |
Correct |
346 ms |
29036 KB |
Output is correct |