Submission #1012739

# Submission time Handle Problem Language Result Execution time Memory
1012739 2024-07-02T14:32:40 Z pcc None (JOI16_worst_reporter2) C++17
100 / 100
227 ms 40396 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second
#define _all(T) T.begin(),T.end()

const int mxn = 4e5+10;
pii arr[mxn],brr[mxn];
vector<pii> v;
int N;
vector<int> stk[mxn];

struct SEG{
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	SEG(){}
	pii seg[mxn*4];
	void modify(int now,int l,int r,int s,int e,int v){
		if(l>=s&&e>=r){
			seg[now].sc += v;
			return;
		}
		if(mid>=s)modify(ls,l,mid,s,e,v);
		if(mid<e)modify(rs,mid+1,r,s,e,v);
		seg[now].fs = min(seg[ls].fs+seg[ls].sc,seg[rs].fs+seg[rs].sc);
		return;
	}
	int getval(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return seg[now].fs+seg[now].sc;
		if(mid>=e)return getval(ls,l,mid,s,e)+seg[now].sc;
		else if(mid<s)return getval(rs,mid+1,r,s,e)+seg[now].sc;
		else return min(getval(ls,l,mid,s,e),getval(rs,mid+1,r,s,e))+seg[now].sc;
	}
#undef ls
#undef rs
#undef mid
};

SEG seg;
int pref[mxn];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	for(int i = 0;i<N;i++)cin>>arr[i].fs>>arr[i].sc,v.push_back(pii(arr[i].sc,-arr[i].fs));
	for(int i = 0;i<N;i++)cin>>brr[i].fs>>brr[i].sc,v.push_back(pii(brr[i].sc,brr[i].fs));
	sort(_all(v));
	for(int i = 0;i<v.size();i++){
		if(i)pref[i] = pref[i-1];
		if(v[i].sc<0)pref[i]++;
		else pref[i]--;
		seg.modify(0,0,mxn,i,i,pref[i]);
	}
	int ans = N;
	for(int i = 0;i<v.size();i++){
		if(v[i].sc<0){
			v[i].sc = -v[i].sc;
			stk[v[i].sc].push_back(i);
		}
		else{
			int tar = v[i].sc;
			if(stk[tar].empty())continue;
			int pos = stk[tar].back();
			if(seg.getval(0,0,mxn,pos,i-1) == 0)continue;
			ans--;
			seg.modify(0,0,mxn,pos,pos,mxn);
			seg.modify(0,0,mxn,i,i,mxn);
			seg.modify(0,0,mxn,pos,i,-1);
			stk[tar].pop_back();
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0;i<v.size();i++){
      |                ~^~~~~~~~~
worst_reporter2.cpp:58:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i = 0;i<v.size();i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22364 KB Output is correct
2 Correct 10 ms 22388 KB Output is correct
3 Correct 10 ms 22364 KB Output is correct
4 Correct 11 ms 22232 KB Output is correct
5 Correct 8 ms 22364 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 9 ms 22380 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 9 ms 22364 KB Output is correct
11 Correct 9 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22364 KB Output is correct
2 Correct 10 ms 22388 KB Output is correct
3 Correct 10 ms 22364 KB Output is correct
4 Correct 11 ms 22232 KB Output is correct
5 Correct 8 ms 22364 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 9 ms 22380 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 9 ms 22364 KB Output is correct
11 Correct 9 ms 22364 KB Output is correct
12 Correct 12 ms 22360 KB Output is correct
13 Correct 9 ms 22360 KB Output is correct
14 Correct 9 ms 22292 KB Output is correct
15 Correct 9 ms 22364 KB Output is correct
16 Correct 9 ms 22364 KB Output is correct
17 Correct 9 ms 22396 KB Output is correct
18 Correct 9 ms 22364 KB Output is correct
19 Correct 9 ms 22364 KB Output is correct
20 Correct 9 ms 22400 KB Output is correct
21 Correct 10 ms 22364 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22364 KB Output is correct
2 Correct 10 ms 22388 KB Output is correct
3 Correct 10 ms 22364 KB Output is correct
4 Correct 11 ms 22232 KB Output is correct
5 Correct 8 ms 22364 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 9 ms 22380 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 9 ms 22364 KB Output is correct
11 Correct 9 ms 22364 KB Output is correct
12 Correct 12 ms 22360 KB Output is correct
13 Correct 9 ms 22360 KB Output is correct
14 Correct 9 ms 22292 KB Output is correct
15 Correct 9 ms 22364 KB Output is correct
16 Correct 9 ms 22364 KB Output is correct
17 Correct 9 ms 22396 KB Output is correct
18 Correct 9 ms 22364 KB Output is correct
19 Correct 9 ms 22364 KB Output is correct
20 Correct 9 ms 22400 KB Output is correct
21 Correct 10 ms 22364 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
23 Correct 13 ms 22616 KB Output is correct
24 Correct 13 ms 22620 KB Output is correct
25 Correct 13 ms 22804 KB Output is correct
26 Correct 13 ms 22620 KB Output is correct
27 Correct 13 ms 22580 KB Output is correct
28 Correct 13 ms 22620 KB Output is correct
29 Correct 14 ms 22620 KB Output is correct
30 Correct 15 ms 22696 KB Output is correct
31 Correct 11 ms 22620 KB Output is correct
32 Correct 13 ms 22620 KB Output is correct
33 Correct 13 ms 22620 KB Output is correct
34 Correct 13 ms 22844 KB Output is correct
35 Correct 14 ms 22620 KB Output is correct
36 Correct 13 ms 22708 KB Output is correct
37 Correct 14 ms 22620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22364 KB Output is correct
2 Correct 10 ms 22388 KB Output is correct
3 Correct 10 ms 22364 KB Output is correct
4 Correct 11 ms 22232 KB Output is correct
5 Correct 8 ms 22364 KB Output is correct
6 Correct 11 ms 22364 KB Output is correct
7 Correct 9 ms 22380 KB Output is correct
8 Correct 9 ms 22364 KB Output is correct
9 Correct 9 ms 22364 KB Output is correct
10 Correct 9 ms 22364 KB Output is correct
11 Correct 9 ms 22364 KB Output is correct
12 Correct 12 ms 22360 KB Output is correct
13 Correct 9 ms 22360 KB Output is correct
14 Correct 9 ms 22292 KB Output is correct
15 Correct 9 ms 22364 KB Output is correct
16 Correct 9 ms 22364 KB Output is correct
17 Correct 9 ms 22396 KB Output is correct
18 Correct 9 ms 22364 KB Output is correct
19 Correct 9 ms 22364 KB Output is correct
20 Correct 9 ms 22400 KB Output is correct
21 Correct 10 ms 22364 KB Output is correct
22 Correct 9 ms 22364 KB Output is correct
23 Correct 13 ms 22616 KB Output is correct
24 Correct 13 ms 22620 KB Output is correct
25 Correct 13 ms 22804 KB Output is correct
26 Correct 13 ms 22620 KB Output is correct
27 Correct 13 ms 22580 KB Output is correct
28 Correct 13 ms 22620 KB Output is correct
29 Correct 14 ms 22620 KB Output is correct
30 Correct 15 ms 22696 KB Output is correct
31 Correct 11 ms 22620 KB Output is correct
32 Correct 13 ms 22620 KB Output is correct
33 Correct 13 ms 22620 KB Output is correct
34 Correct 13 ms 22844 KB Output is correct
35 Correct 14 ms 22620 KB Output is correct
36 Correct 13 ms 22708 KB Output is correct
37 Correct 14 ms 22620 KB Output is correct
38 Correct 173 ms 40396 KB Output is correct
39 Correct 162 ms 39364 KB Output is correct
40 Correct 156 ms 39204 KB Output is correct
41 Correct 161 ms 39356 KB Output is correct
42 Correct 185 ms 39408 KB Output is correct
43 Correct 189 ms 34668 KB Output is correct
44 Correct 212 ms 34752 KB Output is correct
45 Correct 184 ms 34748 KB Output is correct
46 Correct 142 ms 35768 KB Output is correct
47 Correct 202 ms 36544 KB Output is correct
48 Correct 175 ms 34216 KB Output is correct
49 Correct 208 ms 34176 KB Output is correct
50 Correct 196 ms 34236 KB Output is correct
51 Correct 137 ms 34976 KB Output is correct
52 Correct 227 ms 34780 KB Output is correct