Submission #751580

# Submission time Handle Problem Language Result Execution time Memory
751580 2023-05-31T19:36:50 Z aebov Fortune Telling 2 (JOI14_fortune_telling2) C++17
100 / 100
1745 ms 48976 KB
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O2")
//#pragma GCC optimize("fast-math")
#include<iostream>
#include<vector>
#include<cmath>
#include<queue>
#include<utility>
#include<algorithm>
#include<bitset>
#include<map>
#include<iomanip>
#include<set>
#include<string.h>
#include<stack>
#include <list>
#include <numeric>
#include <random>
#include<unordered_map>
#define all(x) x.begin(), x.end()
#define ln (e-s+1)
#define lc (id*2)
#define rc (id*2 + 1)
#define md ((e+s)/2)
#define dm ((e+s)/2+1)
#define pb push_back
#define ll long long 
#define endl '\n'
#define mk make_pair
#define F first
#define pll pair<ll, ll>
#define S second
#define pvv pair<vector<int> , vector<int> > 
#define pii pair<int,int>
#define plll pair<ll, pair<int, int> >
#define ld long double
#define mat vector<vector<ll>>
//#define int long long 
using namespace std;

const int N = (int)2e5 + 5, mod = (int) 1e9 + 7;
int n, k, a[N], b[N], t[N], mn, mx;
vector<int> seg[N << 2];

void build(int id = 1,int s = 1,int e = k){
	if(ln == 1){
		seg[id].pb(t[s]);
		return;
	}build(lc, s, md), build(rc, dm, e);
	for(int x : seg[lc]) seg[id].pb(x);
	for(int x : seg[rc]) seg[id].pb(x);
	sort(seg[id].begin(), seg[id].end());
}
pii get(int l2,int r2,int id = 1,int s = 1,int e = k){
	if(l2 > e || r2 < s) return {mod, 0};
	if( l2 <= s && e <= r2){
		int l = 0, r = seg[id].size() - 1, ans = -1;
		while(l <= r){
			int mid = (l+r) >> 1;
			if(seg[id][mid] >= mn) ans = mid, r = mid - 1;
			else l = mid + 1;
		}
		l = 0, r = seg[id].size() - 1;int ans2 = seg[id].size();
		while(l <= r){
			int mid = (l+r) >> 1;
			if(seg[id][mid] >= mx) ans2 = mid, r = mid - 1;
			else l = mid + 1;
		}
		if(ans == -1) return {mod , 0};
		return {seg[id][ans], seg[id].size() - ans2};
	}
	auto g1 = get(l2, r2, lc, s, md), g2 = get(l2, r2, rc, dm, e);
	return {min(g1.F, g2.F), g1.S + g2.S} ;
}
int main(){
//	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i], &b[i]);
	for(int i = 1; i <= k; i ++) scanf("%d", &t[i]);
	build();
	ll ret = 0;
	for(int i = 1; i <= n; i ++){
		int l = 1, r = k, ans = k+1;
		mn = min(a[i], b[i]), mx = max(a[i], b[i]);
		while(l <= r){
			int mid = (l+r) >> 1;
			if(get(mid, k).F >= mx) ans = mid, r = mid - 1;
			else l = mid + 1;
		}
	//	cout << "few : " <<  ans << endl;
		if(get(1, ans - 1).F < mx){
			if(get(ans, k).S %2 == 0) ret += mx;
			else ret += mn;
		}
		else{
			if(get(ans , k).S % 2 == 0) ret += a[i];
			else ret += b[i];
		}
	//	cout << ret << endl;
	}printf("%lld\n", ret);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:79:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i], &b[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:80:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  for(int i = 1; i <= k; i ++) scanf("%d", &t[i]);
      |                               ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19156 KB Output is correct
2 Correct 12 ms 19156 KB Output is correct
3 Correct 13 ms 19120 KB Output is correct
4 Correct 15 ms 19156 KB Output is correct
5 Correct 14 ms 19212 KB Output is correct
6 Correct 13 ms 19220 KB Output is correct
7 Correct 14 ms 19096 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 12 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 15 ms 19156 KB Output is correct
12 Correct 14 ms 19204 KB Output is correct
13 Correct 15 ms 19156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19156 KB Output is correct
2 Correct 12 ms 19156 KB Output is correct
3 Correct 13 ms 19120 KB Output is correct
4 Correct 15 ms 19156 KB Output is correct
5 Correct 14 ms 19212 KB Output is correct
6 Correct 13 ms 19220 KB Output is correct
7 Correct 14 ms 19096 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 12 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 15 ms 19156 KB Output is correct
12 Correct 14 ms 19204 KB Output is correct
13 Correct 15 ms 19156 KB Output is correct
14 Correct 59 ms 20536 KB Output is correct
15 Correct 95 ms 22096 KB Output is correct
16 Correct 141 ms 22860 KB Output is correct
17 Correct 216 ms 25144 KB Output is correct
18 Correct 200 ms 25164 KB Output is correct
19 Correct 201 ms 25164 KB Output is correct
20 Correct 230 ms 25136 KB Output is correct
21 Correct 155 ms 25144 KB Output is correct
22 Correct 133 ms 25188 KB Output is correct
23 Correct 136 ms 25168 KB Output is correct
24 Correct 151 ms 25180 KB Output is correct
25 Correct 122 ms 25168 KB Output is correct
26 Correct 204 ms 25092 KB Output is correct
27 Correct 291 ms 25180 KB Output is correct
28 Correct 203 ms 25164 KB Output is correct
29 Correct 387 ms 25164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19156 KB Output is correct
2 Correct 12 ms 19156 KB Output is correct
3 Correct 13 ms 19120 KB Output is correct
4 Correct 15 ms 19156 KB Output is correct
5 Correct 14 ms 19212 KB Output is correct
6 Correct 13 ms 19220 KB Output is correct
7 Correct 14 ms 19096 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 12 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 15 ms 19156 KB Output is correct
12 Correct 14 ms 19204 KB Output is correct
13 Correct 15 ms 19156 KB Output is correct
14 Correct 59 ms 20536 KB Output is correct
15 Correct 95 ms 22096 KB Output is correct
16 Correct 141 ms 22860 KB Output is correct
17 Correct 216 ms 25144 KB Output is correct
18 Correct 200 ms 25164 KB Output is correct
19 Correct 201 ms 25164 KB Output is correct
20 Correct 230 ms 25136 KB Output is correct
21 Correct 155 ms 25144 KB Output is correct
22 Correct 133 ms 25188 KB Output is correct
23 Correct 136 ms 25168 KB Output is correct
24 Correct 151 ms 25180 KB Output is correct
25 Correct 122 ms 25168 KB Output is correct
26 Correct 204 ms 25092 KB Output is correct
27 Correct 291 ms 25180 KB Output is correct
28 Correct 203 ms 25164 KB Output is correct
29 Correct 387 ms 25164 KB Output is correct
30 Correct 283 ms 47384 KB Output is correct
31 Correct 481 ms 47740 KB Output is correct
32 Correct 777 ms 48088 KB Output is correct
33 Correct 1321 ms 48976 KB Output is correct
34 Correct 232 ms 47244 KB Output is correct
35 Correct 1403 ms 48856 KB Output is correct
36 Correct 1271 ms 48908 KB Output is correct
37 Correct 1382 ms 48852 KB Output is correct
38 Correct 1365 ms 48808 KB Output is correct
39 Correct 1490 ms 48768 KB Output is correct
40 Correct 919 ms 48836 KB Output is correct
41 Correct 1395 ms 48820 KB Output is correct
42 Correct 1438 ms 48832 KB Output is correct
43 Correct 677 ms 48764 KB Output is correct
44 Correct 681 ms 48836 KB Output is correct
45 Correct 703 ms 48792 KB Output is correct
46 Correct 880 ms 48796 KB Output is correct
47 Correct 1095 ms 48964 KB Output is correct
48 Correct 1745 ms 48860 KB Output is correct
49 Correct 1607 ms 48824 KB Output is correct