답안 #405137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405137 2021-05-15T18:24:08 Z saarang123 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
299 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 200 * 1000 + 3;
int tree[MXN << 2], a[MXN], b[MXN], t[MXN], oga[MXN], ogb[MXN];
vector<int> coord, q[MXN];
int n, k, sz;

function<int(int, int)> comb = [] (int x, int y) {
	return max(x, y);
};

void update(int v, int tl, int tr, int pos, int x) {
	if(tl == tr)
		tree[v] = comb(tree[v], x);
	else {
		int tm = (tl + tr) >> 1;
		if(pos <= tm)
			update(v << 1, tl, tm, pos, x);
		else
			update(v << 1|1, tm + 1, tr, pos, x);
		tree[v] = comb(tree[v << 1], tree[v << 1|1]);
	}
}

void upd(int pos, int x) {
	update(1, 1, MXN - 2, pos, x);
}

int query(int v, int tl, int tr, int l, int r) {
	if(l > r)
		return 0;
	if(l <= tl && tr <= r)
		return tree[v];
	int tm = (tl + tr) >> 1;
	return comb(query(v << 1, tl, tm, l, min(tm, r)),
				query(v << 1|1, tm + 1, tr, max(tm + 1, l), r));
}

int query(int l, int r) {
	return query(1, 1, MXN - 2, l, r);
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
    	cin >> oga[i] >> ogb[i];
    	coord.push_back(oga[i]);
    	coord.push_back(ogb[i]);
    }
    for(int i = 1; i <= k; i++) {
    	cin >> t[i];
    	coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
    sz = coord.size();
    auto id = [&] (int x) {
    	return upper_bound(coord.begin(), coord.end(), x) - coord.begin();
    };
    for(int i = 1; i <= n; i++) {
    	a[i] = id(oga[i]);
    	b[i] = id(ogb[i]);
    }
    for(int i = 1; i <= k; i++) {
    	t[i] = id(t[i]);
    	upd(t[i], i);
    }

    for(int i = 1; i <= n; i++) {
    	int x = query(min(a[i], b[i]), max(a[i], b[i]) - 1);
    	q[x].push_back(i);
    }
    memset(tree, 0, sizeof tree);
    comb = [&] (int x, int y) {
    	return x + y;
    };
    long long ans = 0;
    for(int x = k; x >= 0; x--) {
    	for(int i : q[x]) {
    		int parity = query(max(a[i], b[i]), sz) & 1;
    		if(x)
    			parity ^= a[i] < b[i];
    		ans += parity ? ogb[i] : oga[i];
    	}
    	upd(t[x], 1);
    }

    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8104 KB Output is correct
2 Correct 7 ms 8140 KB Output is correct
3 Correct 8 ms 8152 KB Output is correct
4 Correct 8 ms 8264 KB Output is correct
5 Correct 8 ms 8244 KB Output is correct
6 Correct 8 ms 8236 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8140 KB Output is correct
9 Correct 9 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 9 ms 8232 KB Output is correct
12 Correct 8 ms 8140 KB Output is correct
13 Correct 8 ms 8232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8104 KB Output is correct
2 Correct 7 ms 8140 KB Output is correct
3 Correct 8 ms 8152 KB Output is correct
4 Correct 8 ms 8264 KB Output is correct
5 Correct 8 ms 8244 KB Output is correct
6 Correct 8 ms 8236 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8140 KB Output is correct
9 Correct 9 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 9 ms 8232 KB Output is correct
12 Correct 8 ms 8140 KB Output is correct
13 Correct 8 ms 8232 KB Output is correct
14 Correct 31 ms 8808 KB Output is correct
15 Correct 61 ms 9516 KB Output is correct
16 Correct 85 ms 10020 KB Output is correct
17 Correct 119 ms 10812 KB Output is correct
18 Correct 120 ms 10724 KB Output is correct
19 Correct 119 ms 10792 KB Output is correct
20 Correct 121 ms 10828 KB Output is correct
21 Correct 114 ms 10952 KB Output is correct
22 Correct 100 ms 10252 KB Output is correct
23 Correct 98 ms 10348 KB Output is correct
24 Correct 95 ms 10308 KB Output is correct
25 Correct 99 ms 10544 KB Output is correct
26 Correct 96 ms 10508 KB Output is correct
27 Correct 107 ms 10792 KB Output is correct
28 Correct 112 ms 10776 KB Output is correct
29 Correct 115 ms 10944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8104 KB Output is correct
2 Correct 7 ms 8140 KB Output is correct
3 Correct 8 ms 8152 KB Output is correct
4 Correct 8 ms 8264 KB Output is correct
5 Correct 8 ms 8244 KB Output is correct
6 Correct 8 ms 8236 KB Output is correct
7 Correct 8 ms 8140 KB Output is correct
8 Correct 8 ms 8140 KB Output is correct
9 Correct 9 ms 8152 KB Output is correct
10 Correct 7 ms 8140 KB Output is correct
11 Correct 9 ms 8232 KB Output is correct
12 Correct 8 ms 8140 KB Output is correct
13 Correct 8 ms 8232 KB Output is correct
14 Correct 31 ms 8808 KB Output is correct
15 Correct 61 ms 9516 KB Output is correct
16 Correct 85 ms 10020 KB Output is correct
17 Correct 119 ms 10812 KB Output is correct
18 Correct 120 ms 10724 KB Output is correct
19 Correct 119 ms 10792 KB Output is correct
20 Correct 121 ms 10828 KB Output is correct
21 Correct 114 ms 10952 KB Output is correct
22 Correct 100 ms 10252 KB Output is correct
23 Correct 98 ms 10348 KB Output is correct
24 Correct 95 ms 10308 KB Output is correct
25 Correct 99 ms 10544 KB Output is correct
26 Correct 96 ms 10508 KB Output is correct
27 Correct 107 ms 10792 KB Output is correct
28 Correct 112 ms 10776 KB Output is correct
29 Correct 115 ms 10944 KB Output is correct
30 Runtime error 299 ms 262148 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -