답안 #161992

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

int s[N][2];

int a[N];

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

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

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

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

pair<int, int> query(int id, int l, int r, int f, int s){
	auto it = lower_bound(t[id].begin(), t[id].end(), min(f, s));
	if(it == t[id].end())
		return {0, 0};
	if(*it >= max(f, s))
		return {0, t[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) 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>>a[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 && 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 21 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 22 ms 19320 KB Output is correct
4 Correct 21 ms 19320 KB Output is correct
5 Correct 22 ms 19320 KB Output is correct
6 Correct 22 ms 19324 KB Output is correct
7 Correct 21 ms 19228 KB Output is correct
8 Correct 21 ms 19320 KB Output is correct
9 Correct 20 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 19320 KB Output is correct
13 Correct 19 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 22 ms 19320 KB Output is correct
4 Correct 21 ms 19320 KB Output is correct
5 Correct 22 ms 19320 KB Output is correct
6 Correct 22 ms 19324 KB Output is correct
7 Correct 21 ms 19228 KB Output is correct
8 Correct 21 ms 19320 KB Output is correct
9 Correct 20 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 19320 KB Output is correct
13 Correct 19 ms 19320 KB Output is correct
14 Correct 39 ms 20856 KB Output is correct
15 Correct 61 ms 22648 KB Output is correct
16 Correct 82 ms 23544 KB Output is correct
17 Correct 108 ms 25720 KB Output is correct
18 Correct 108 ms 25768 KB Output is correct
19 Correct 103 ms 25592 KB Output is correct
20 Correct 111 ms 25604 KB Output is correct
21 Correct 96 ms 25848 KB Output is correct
22 Correct 76 ms 25720 KB Output is correct
23 Correct 73 ms 25720 KB Output is correct
24 Correct 74 ms 25616 KB Output is correct
25 Correct 73 ms 25720 KB Output is correct
26 Correct 73 ms 25720 KB Output is correct
27 Correct 124 ms 25596 KB Output is correct
28 Correct 80 ms 25732 KB Output is correct
29 Correct 100 ms 25720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19320 KB Output is correct
2 Correct 21 ms 19320 KB Output is correct
3 Correct 22 ms 19320 KB Output is correct
4 Correct 21 ms 19320 KB Output is correct
5 Correct 22 ms 19320 KB Output is correct
6 Correct 22 ms 19324 KB Output is correct
7 Correct 21 ms 19228 KB Output is correct
8 Correct 21 ms 19320 KB Output is correct
9 Correct 20 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 19320 KB Output is correct
13 Correct 19 ms 19320 KB Output is correct
14 Correct 39 ms 20856 KB Output is correct
15 Correct 61 ms 22648 KB Output is correct
16 Correct 82 ms 23544 KB Output is correct
17 Correct 108 ms 25720 KB Output is correct
18 Correct 108 ms 25768 KB Output is correct
19 Correct 103 ms 25592 KB Output is correct
20 Correct 111 ms 25604 KB Output is correct
21 Correct 96 ms 25848 KB Output is correct
22 Correct 76 ms 25720 KB Output is correct
23 Correct 73 ms 25720 KB Output is correct
24 Correct 74 ms 25616 KB Output is correct
25 Correct 73 ms 25720 KB Output is correct
26 Correct 73 ms 25720 KB Output is correct
27 Correct 124 ms 25596 KB Output is correct
28 Correct 80 ms 25732 KB Output is correct
29 Correct 100 ms 25720 KB Output is correct
30 Correct 205 ms 47904 KB Output is correct
31 Correct 281 ms 48240 KB Output is correct
32 Correct 383 ms 48596 KB Output is correct
33 Correct 567 ms 49392 KB Output is correct
34 Correct 182 ms 47856 KB Output is correct
35 Correct 579 ms 49392 KB Output is correct
36 Correct 574 ms 49396 KB Output is correct
37 Correct 582 ms 49604 KB Output is correct
38 Correct 556 ms 49392 KB Output is correct
39 Correct 594 ms 49392 KB Output is correct
40 Correct 432 ms 49396 KB Output is correct
41 Correct 580 ms 49552 KB Output is correct
42 Correct 596 ms 49364 KB Output is correct
43 Correct 306 ms 49392 KB Output is correct
44 Correct 298 ms 49392 KB Output is correct
45 Correct 310 ms 49324 KB Output is correct
46 Correct 327 ms 49520 KB Output is correct
47 Correct 348 ms 49492 KB Output is correct
48 Correct 348 ms 49264 KB Output is correct
49 Correct 320 ms 49264 KB Output is correct