답안 #161990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161990 2019-11-05T15:06:26 Z nvmdava 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
635 ms 55140 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 200005
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007LL

int s[N][2];

int t[N];

vector<int> seg[N << 2];

void build(int id, int l, int r){
	if(l == r){
		seg[id].push_back(t[l]);
		return;
	}
	int i1 = 0, i2 = 0, id1 = id << 1, id2 = id << 1 | 1, s1, s2;
	int m = (l + r) >> 1;
	build(id1, l, m);
	build(id2, m + 1, r);

	s1 = seg[id1].size();
	s2 = seg[id2].size();

	while(i1 != s1 && i2 != s2){
		if(seg[id1][i1] > seg[id2][i2])
			seg[id].push_back(seg[id2][i2++]);
		else
			seg[id].push_back(seg[id1][i1++]);
	}
	while(i1 != s1)
		seg[id].push_back(seg[id1][i1++]);
	while(i2 != s2)
		seg[id].push_back(seg[id2][i2++]);
}

pair<int, int> query(int id, int l, int r, int f, int s){
	auto it = lower_bound(seg[id].begin(), seg[id].end(), min(f, s));
	if(it == seg[id].end())
		return {0, 0};
	if(*it >= max(f, s))
		return {0, seg[id].end() - it};
	if(l == r)
		return {1, 0};
	int m = (l + r) >> 1;
	auto r2 = query(id << 1 | 1, m + 1, r, f, s);
	if(r2.ff == 1) return r2;
	auto r1 = query(id << 1, l, m, f, s);
	return {r1.ff, r1.ss ^ r2.ss};
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin>>n>>k;
    for(int i = 1; i <= n; i++)
    	cin>>s[i][0]>>s[i][1];
    
    for(int i = 1; i <= k; i++)
    	cin>>t[i];

    build(1, 1, k);
    ll res = 0;
    for(int i = 1; i <= n; i++){
    	auto w = query(1, 1, k, s[i][0], s[i][1]);

    	if(w.ff)
    		if(s[i][0] < s[i][1])
    			swap(s[i][0], s[i][1]);
    	res += s[i][w.ss & 1]; 
    }
    cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 33 ms 19320 KB Output is correct
5 Correct 21 ms 19320 KB Output is correct
6 Correct 21 ms 19320 KB Output is correct
7 Correct 21 ms 19320 KB Output is correct
8 Correct 20 ms 19320 KB Output is correct
9 Correct 22 ms 19320 KB Output is correct
10 Correct 21 ms 19192 KB Output is correct
11 Correct 21 ms 19320 KB Output is correct
12 Correct 21 ms 19192 KB Output is correct
13 Correct 22 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 33 ms 19320 KB Output is correct
5 Correct 21 ms 19320 KB Output is correct
6 Correct 21 ms 19320 KB Output is correct
7 Correct 21 ms 19320 KB Output is correct
8 Correct 20 ms 19320 KB Output is correct
9 Correct 22 ms 19320 KB Output is correct
10 Correct 21 ms 19192 KB Output is correct
11 Correct 21 ms 19320 KB Output is correct
12 Correct 21 ms 19192 KB Output is correct
13 Correct 22 ms 19320 KB Output is correct
14 Correct 38 ms 20856 KB Output is correct
15 Correct 60 ms 22748 KB Output is correct
16 Correct 80 ms 23996 KB Output is correct
17 Correct 107 ms 26476 KB Output is correct
18 Correct 109 ms 26488 KB Output is correct
19 Correct 104 ms 26408 KB Output is correct
20 Correct 112 ms 26488 KB Output is correct
21 Correct 93 ms 26428 KB Output is correct
22 Correct 74 ms 25976 KB Output is correct
23 Correct 77 ms 25976 KB Output is correct
24 Correct 76 ms 25976 KB Output is correct
25 Correct 74 ms 26172 KB Output is correct
26 Correct 75 ms 26360 KB Output is correct
27 Correct 126 ms 26488 KB Output is correct
28 Correct 77 ms 26460 KB Output is correct
29 Correct 100 ms 26488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 33 ms 19320 KB Output is correct
5 Correct 21 ms 19320 KB Output is correct
6 Correct 21 ms 19320 KB Output is correct
7 Correct 21 ms 19320 KB Output is correct
8 Correct 20 ms 19320 KB Output is correct
9 Correct 22 ms 19320 KB Output is correct
10 Correct 21 ms 19192 KB Output is correct
11 Correct 21 ms 19320 KB Output is correct
12 Correct 21 ms 19192 KB Output is correct
13 Correct 22 ms 19320 KB Output is correct
14 Correct 38 ms 20856 KB Output is correct
15 Correct 60 ms 22748 KB Output is correct
16 Correct 80 ms 23996 KB Output is correct
17 Correct 107 ms 26476 KB Output is correct
18 Correct 109 ms 26488 KB Output is correct
19 Correct 104 ms 26408 KB Output is correct
20 Correct 112 ms 26488 KB Output is correct
21 Correct 93 ms 26428 KB Output is correct
22 Correct 74 ms 25976 KB Output is correct
23 Correct 77 ms 25976 KB Output is correct
24 Correct 76 ms 25976 KB Output is correct
25 Correct 74 ms 26172 KB Output is correct
26 Correct 75 ms 26360 KB Output is correct
27 Correct 126 ms 26488 KB Output is correct
28 Correct 77 ms 26460 KB Output is correct
29 Correct 100 ms 26488 KB Output is correct
30 Correct 198 ms 49624 KB Output is correct
31 Correct 309 ms 50800 KB Output is correct
32 Correct 370 ms 52208 KB Output is correct
33 Correct 592 ms 54864 KB Output is correct
34 Correct 200 ms 49392 KB Output is correct
35 Correct 557 ms 54888 KB Output is correct
36 Correct 567 ms 55028 KB Output is correct
37 Correct 571 ms 54768 KB Output is correct
38 Correct 542 ms 54900 KB Output is correct
39 Correct 635 ms 54768 KB Output is correct
40 Correct 462 ms 54512 KB Output is correct
41 Correct 578 ms 54768 KB Output is correct
42 Correct 601 ms 54896 KB Output is correct
43 Correct 309 ms 54128 KB Output is correct
44 Correct 297 ms 54232 KB Output is correct
45 Correct 314 ms 54000 KB Output is correct
46 Correct 341 ms 52844 KB Output is correct
47 Correct 344 ms 52768 KB Output is correct
48 Correct 348 ms 54896 KB Output is correct
49 Correct 330 ms 55140 KB Output is correct