답안 #668667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668667 2022-12-04T11:24:47 Z Kahou 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
325 ms 37060 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int inf = 1e9;
const int N = 2e5 + 50;
int n, k, T[N];
bool vis[N];
pair<pii, int> P[N];
vector<pii> fenmx[N];
int fen[N];

int getmx(int i) {
	int id = 0;
	for (; i > 0; i -= i&-i) {
		while (vis[fenmx[i].back().S]) fenmx[i].pop_back();
		if (fenmx[i].back().F > P[id].F.S) id = fenmx[i].back().S;
	}
	return id;
}
int get(int i) {
	int out = fen[0];
	for (; i > 0; i -= i&-i) {
		out += fen[i];
	}
	return out;
}
void upd(int i, int x) {
	if (!i) fen[i] += x;
	else for (; i <= n; i += i&-i) {
		fen[i] += x;
	}
}

void solve() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		fenmx[i].push_back({0, 0});
	}
	for (int i = 1; i <= n; i++) {
		cin >> P[i].F.F >> P[i].F.S;
		P[i].S = (P[i].F.F > P[i].F.S);
		if (P[i].S) swap(P[i].F.F, P[i].F.S);
	}
	sort(P+1, P+n+1);
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += j&-j) {
			fenmx[j].push_back({P[i].F.S, i});
		}
	}
	for (int i = 1; i <= n; i++) {
		sort(fenmx[i].begin(), fenmx[i].end());
	}
	for (int i = 1; i <= k; i++) {
		cin >> T[i];
	}
	for (int i = k; i >= 1; i--) {
		int id = upper_bound(P+1, P+n+1, mk(mk(T[i], inf), inf))-P-1;
		int t = getmx(id);
		while (P[t].F.S > T[i]) {
			P[t].S = (get(t)^1)&1;
			vis[t] = 1;
			t = getmx(id);
		}
		upd(0, +1);
		upd(id+1, -1);
	}
	int t = getmx(n);
	while (t) {
		P[t].S ^= (get(t)&1);
		vis[t] = 1;
		t = getmx(n);
	}
	
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (P[i].S? P[i].F.S: P[i].F.F);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5156 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5156 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 12 ms 6380 KB Output is correct
15 Correct 24 ms 7892 KB Output is correct
16 Correct 36 ms 9296 KB Output is correct
17 Correct 49 ms 10968 KB Output is correct
18 Correct 49 ms 10888 KB Output is correct
19 Correct 47 ms 10868 KB Output is correct
20 Correct 54 ms 10944 KB Output is correct
21 Correct 44 ms 10940 KB Output is correct
22 Correct 43 ms 11004 KB Output is correct
23 Correct 34 ms 10860 KB Output is correct
24 Correct 34 ms 10944 KB Output is correct
25 Correct 31 ms 10988 KB Output is correct
26 Correct 32 ms 9932 KB Output is correct
27 Correct 38 ms 10944 KB Output is correct
28 Correct 35 ms 10748 KB Output is correct
29 Correct 41 ms 10892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5156 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 12 ms 6380 KB Output is correct
15 Correct 24 ms 7892 KB Output is correct
16 Correct 36 ms 9296 KB Output is correct
17 Correct 49 ms 10968 KB Output is correct
18 Correct 49 ms 10888 KB Output is correct
19 Correct 47 ms 10868 KB Output is correct
20 Correct 54 ms 10944 KB Output is correct
21 Correct 44 ms 10940 KB Output is correct
22 Correct 43 ms 11004 KB Output is correct
23 Correct 34 ms 10860 KB Output is correct
24 Correct 34 ms 10944 KB Output is correct
25 Correct 31 ms 10988 KB Output is correct
26 Correct 32 ms 9932 KB Output is correct
27 Correct 38 ms 10944 KB Output is correct
28 Correct 35 ms 10748 KB Output is correct
29 Correct 41 ms 10892 KB Output is correct
30 Correct 54 ms 7128 KB Output is correct
31 Correct 121 ms 13412 KB Output is correct
32 Correct 181 ms 21160 KB Output is correct
33 Correct 302 ms 37060 KB Output is correct
34 Correct 23 ms 6008 KB Output is correct
35 Correct 301 ms 36976 KB Output is correct
36 Correct 299 ms 36920 KB Output is correct
37 Correct 325 ms 36924 KB Output is correct
38 Correct 276 ms 36916 KB Output is correct
39 Correct 303 ms 37000 KB Output is correct
40 Correct 243 ms 36992 KB Output is correct
41 Correct 241 ms 36952 KB Output is correct
42 Correct 300 ms 37028 KB Output is correct
43 Correct 151 ms 36520 KB Output is correct
44 Correct 155 ms 36740 KB Output is correct
45 Correct 153 ms 36792 KB Output is correct
46 Correct 199 ms 36976 KB Output is correct
47 Correct 232 ms 36988 KB Output is correct
48 Correct 197 ms 36288 KB Output is correct
49 Correct 178 ms 36140 KB Output is correct