Submission #669231

# Submission time Handle Problem Language Result Execution time Memory
669231 2022-12-06T04:22:57 Z penguin133 Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
288 ms 39124 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> > 
#define fi first
#define se second
int n,m,q;
int ft[200005];
void upd(int p, int v){
	for(;p<=m;p+=(p & -p))ft[p] += v;
}

int query(int p){
	int sum = 0;
	for(;p;p-=(p & -p))sum += ft[p];
	return sum;
}

pi A[200005];
bool cmp(pi a, pi b){
	return max(a.fi, a.se) < max(b.fi, b.se);
}

pi Q[200005];
struct node{
	int s,e,m,val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e)/2;
		val = 0;
		if(s != e)l = new node(s, m), r = new node(m+1, e), val = max(l->val, r->val);
		else val = Q[s].se;
	}
	int query(int a, int b){
		if(a == s && b == e)return val;
		else if(b <= m)return l->query(a, b);
		else if(a > m)return r->query(a, b);
		else return max(l->query(a, m), r->query(m+1, b));
	}
}*root;
void solve(){
	cin >> n >> m;
	for(int i=1;i<=n;i++)cin >> A[i].fi >> A[i].se;
	sort(A+1, A+n+1, cmp);
	for(int i=1;i<=m;i++)cin >> Q[i].fi, Q[i].se = i, upd(i, 1);
	sort(Q+1, Q+m+1);
	root = new node(1, m);
	int in = 1, cur = 0;
	Q[0].fi = -1e9;
	int ans = 0;
	for(int i=1;i<=n;i++){
		while(in <= m && Q[in].fi < max(A[i].fi, A[i].se))cur = max(cur, Q[in].se), upd(Q[in].se, -1), in++;
		int tmp;
		if(Q[in-1].fi < min(A[i].fi, A[i].se)){
			tmp = m - in + 1;
			ans += (tmp%2 ? A[i].se : A[i].fi);
		}
		else {
			int lo = 1, hi = in, ans2 = in + 1;
			while(lo <= hi){
				int mid = (lo + hi)>>1;
				if(Q[mid].fi >= min(A[i].fi, A[i].se))ans2 = mid, hi = mid - 1;
				else lo = mid + 1;
			}
			tmp = root->query(ans2, in - 1);
			tmp = query(m) - query(tmp);
			//cout << tmp << '\n';
			ans += (tmp%2 ? min(A[i].fi, A[i].se) : max(A[i].fi, A[i].se));
		}
		//cout << ans << ' ' << A[i].fi << ' ' << A[i].se << '\n';
	}
	cout << ans;
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

Compilation message

fortune_telling2.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 536 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 536 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 9 ms 2168 KB Output is correct
15 Correct 18 ms 4212 KB Output is correct
16 Correct 30 ms 6096 KB Output is correct
17 Correct 41 ms 8076 KB Output is correct
18 Correct 38 ms 8060 KB Output is correct
19 Correct 36 ms 8012 KB Output is correct
20 Correct 35 ms 8020 KB Output is correct
21 Correct 34 ms 8032 KB Output is correct
22 Correct 27 ms 7504 KB Output is correct
23 Correct 25 ms 7560 KB Output is correct
24 Correct 26 ms 7500 KB Output is correct
25 Correct 27 ms 7548 KB Output is correct
26 Correct 25 ms 7820 KB Output is correct
27 Correct 27 ms 8024 KB Output is correct
28 Correct 27 ms 8008 KB Output is correct
29 Correct 26 ms 7972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 536 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 9 ms 2168 KB Output is correct
15 Correct 18 ms 4212 KB Output is correct
16 Correct 30 ms 6096 KB Output is correct
17 Correct 41 ms 8076 KB Output is correct
18 Correct 38 ms 8060 KB Output is correct
19 Correct 36 ms 8012 KB Output is correct
20 Correct 35 ms 8020 KB Output is correct
21 Correct 34 ms 8032 KB Output is correct
22 Correct 27 ms 7504 KB Output is correct
23 Correct 25 ms 7560 KB Output is correct
24 Correct 26 ms 7500 KB Output is correct
25 Correct 27 ms 7548 KB Output is correct
26 Correct 25 ms 7820 KB Output is correct
27 Correct 27 ms 8024 KB Output is correct
28 Correct 27 ms 8008 KB Output is correct
29 Correct 26 ms 7972 KB Output is correct
30 Correct 72 ms 32324 KB Output is correct
31 Correct 121 ms 33744 KB Output is correct
32 Correct 160 ms 35476 KB Output is correct
33 Correct 262 ms 38872 KB Output is correct
34 Correct 61 ms 31972 KB Output is correct
35 Correct 255 ms 38992 KB Output is correct
36 Correct 258 ms 38956 KB Output is correct
37 Correct 288 ms 39072 KB Output is correct
38 Correct 204 ms 38988 KB Output is correct
39 Correct 197 ms 38988 KB Output is correct
40 Correct 185 ms 38744 KB Output is correct
41 Correct 157 ms 38988 KB Output is correct
42 Correct 178 ms 39016 KB Output is correct
43 Correct 136 ms 38352 KB Output is correct
44 Correct 136 ms 38304 KB Output is correct
45 Correct 139 ms 38220 KB Output is correct
46 Correct 138 ms 37160 KB Output is correct
47 Correct 126 ms 37024 KB Output is correct
48 Correct 140 ms 38944 KB Output is correct
49 Correct 140 ms 39124 KB Output is correct