답안 #751552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751552 2023-05-31T18:20:56 Z aebov 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
1529 ms 54736 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]);
      |                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 13 ms 19260 KB Output is correct
4 Correct 13 ms 19156 KB Output is correct
5 Correct 14 ms 19276 KB Output is correct
6 Correct 15 ms 19156 KB Output is correct
7 Correct 15 ms 19252 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 14 ms 19264 KB Output is correct
12 Correct 15 ms 19156 KB Output is correct
13 Correct 15 ms 19268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 13 ms 19260 KB Output is correct
4 Correct 13 ms 19156 KB Output is correct
5 Correct 14 ms 19276 KB Output is correct
6 Correct 15 ms 19156 KB Output is correct
7 Correct 15 ms 19252 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 14 ms 19264 KB Output is correct
12 Correct 15 ms 19156 KB Output is correct
13 Correct 15 ms 19268 KB Output is correct
14 Correct 57 ms 20840 KB Output is correct
15 Correct 100 ms 22672 KB Output is correct
16 Correct 152 ms 23876 KB Output is correct
17 Correct 228 ms 26428 KB Output is correct
18 Correct 229 ms 26352 KB Output is correct
19 Correct 193 ms 26424 KB Output is correct
20 Correct 259 ms 26476 KB Output is correct
21 Correct 159 ms 26316 KB Output is correct
22 Correct 142 ms 25932 KB Output is correct
23 Correct 141 ms 25948 KB Output is correct
24 Correct 144 ms 25820 KB Output is correct
25 Correct 118 ms 25916 KB Output is correct
26 Correct 226 ms 26344 KB Output is correct
27 Correct 292 ms 26412 KB Output is correct
28 Correct 215 ms 26428 KB Output is correct
29 Correct 379 ms 26420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 13 ms 19156 KB Output is correct
3 Correct 13 ms 19260 KB Output is correct
4 Correct 13 ms 19156 KB Output is correct
5 Correct 14 ms 19276 KB Output is correct
6 Correct 15 ms 19156 KB Output is correct
7 Correct 15 ms 19252 KB Output is correct
8 Correct 13 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 14 ms 19264 KB Output is correct
12 Correct 15 ms 19156 KB Output is correct
13 Correct 15 ms 19268 KB Output is correct
14 Correct 57 ms 20840 KB Output is correct
15 Correct 100 ms 22672 KB Output is correct
16 Correct 152 ms 23876 KB Output is correct
17 Correct 228 ms 26428 KB Output is correct
18 Correct 229 ms 26352 KB Output is correct
19 Correct 193 ms 26424 KB Output is correct
20 Correct 259 ms 26476 KB Output is correct
21 Correct 159 ms 26316 KB Output is correct
22 Correct 142 ms 25932 KB Output is correct
23 Correct 141 ms 25948 KB Output is correct
24 Correct 144 ms 25820 KB Output is correct
25 Correct 118 ms 25916 KB Output is correct
26 Correct 226 ms 26344 KB Output is correct
27 Correct 292 ms 26412 KB Output is correct
28 Correct 215 ms 26428 KB Output is correct
29 Correct 379 ms 26420 KB Output is correct
30 Correct 306 ms 49528 KB Output is correct
31 Correct 522 ms 50640 KB Output is correct
32 Correct 767 ms 51888 KB Output is correct
33 Correct 1341 ms 54736 KB Output is correct
34 Correct 236 ms 49280 KB Output is correct
35 Correct 1458 ms 54636 KB Output is correct
36 Correct 1305 ms 54672 KB Output is correct
37 Correct 1381 ms 54656 KB Output is correct
38 Correct 1354 ms 54648 KB Output is correct
39 Correct 1504 ms 54732 KB Output is correct
40 Correct 875 ms 54400 KB Output is correct
41 Correct 1423 ms 54656 KB Output is correct
42 Correct 1486 ms 54612 KB Output is correct
43 Correct 662 ms 53956 KB Output is correct
44 Correct 691 ms 53956 KB Output is correct
45 Correct 693 ms 53848 KB Output is correct
46 Correct 783 ms 52804 KB Output is correct
47 Correct 1026 ms 52660 KB Output is correct
48 Correct 1529 ms 54664 KB Output is correct
49 Correct 1345 ms 54724 KB Output is correct