답안 #52241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52241 2018-06-25T05:52:36 Z ainta(#1342) 운세 보기 2 (JOI14_fortune_telling2) C++11
100 / 100
422 ms 21500 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#define SZ 524288
using namespace std;
int n, K;
struct point {
	int a, b;
}w[201000], ori[201000];
int X[401000], P[201000], Q[201000], IT[SZ + SZ];
vector<int>G[401000];
int BIT[SZ];
void Ins(int a, int b) {
	a += SZ;
	while (a) {
		IT[a] = max(IT[a], b);
		a >>= 1;
	}
}
void Add(int a, int b) {
	while (a < SZ) {
		BIT[a] += b;
		a += (a&-a);
	}
}
int Sum(int a) {
	int r = 0;
	while (a) {
		r += BIT[a];
		a -= (a&-a);
	}
	return r;
}
int Max(int b, int e) {
	b += SZ, e += SZ;
	int r = 0;
	while (b <= e) {
		r = max(r, max(IT[b], IT[e]));
		b = (b + 1) >> 1, e = (e - 1) >> 1;
	}
	return r;
}
long long res;
int main() {
	int i, a;
	scanf("%d%d", &n, &K);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i].a, &w[i].b);
		X[i] = w[i].a, X[n + i] = w[i].b;
		ori[i] = w[i];
	}
	sort(X + 1, X + n + n + 1);
	for (i = 1; i <= n; i++) {
		w[i].a = lower_bound(X + 1, X + n + n + 1, w[i].a) - X;
		w[i].b = lower_bound(X + 1, X + n + n + 1, w[i].b) - X;
	}
	for (i = 1; i <= K; i++) {
		scanf("%d", &a);
		a = lower_bound(X + 1, X + n + n + 1, a + 1) - X;
		Q[i] = a;
		Ins(a, i);
	}
	for (i = 1; i <= n; i++) {
		int mn = min(w[i].a, w[i].b), mx = max(w[i].a, w[i].b);
		G[Max(mn + 1, mx)].push_back(i);
	}
	for (i = K; i >= 0; i--) {
		for (auto &x : G[i]) {
			int ck = ((K - i) - Sum(w[x].b)) % 2;
			if (i) {
				if (ck)res += min(ori[x].a, ori[x].b);
				else res += max(ori[x].a, ori[x].b);
			}
			else {
				if (ck)res += ori[x].b;
				else res += ori[x].a;
			}
		}
		if (!i)break;
		Add(Q[i], 1);
	}
	printf("%lld\n", res);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &K);
  ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &w[i].a, &w[i].b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Correct 10 ms 9956 KB Output is correct
3 Correct 11 ms 10032 KB Output is correct
4 Correct 11 ms 10080 KB Output is correct
5 Correct 11 ms 10080 KB Output is correct
6 Correct 11 ms 10080 KB Output is correct
7 Correct 11 ms 10080 KB Output is correct
8 Correct 11 ms 10080 KB Output is correct
9 Correct 10 ms 10092 KB Output is correct
10 Correct 11 ms 10112 KB Output is correct
11 Correct 11 ms 10240 KB Output is correct
12 Correct 11 ms 10240 KB Output is correct
13 Correct 11 ms 10240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Correct 10 ms 9956 KB Output is correct
3 Correct 11 ms 10032 KB Output is correct
4 Correct 11 ms 10080 KB Output is correct
5 Correct 11 ms 10080 KB Output is correct
6 Correct 11 ms 10080 KB Output is correct
7 Correct 11 ms 10080 KB Output is correct
8 Correct 11 ms 10080 KB Output is correct
9 Correct 10 ms 10092 KB Output is correct
10 Correct 11 ms 10112 KB Output is correct
11 Correct 11 ms 10240 KB Output is correct
12 Correct 11 ms 10240 KB Output is correct
13 Correct 11 ms 10240 KB Output is correct
14 Correct 23 ms 10548 KB Output is correct
15 Correct 37 ms 11188 KB Output is correct
16 Correct 53 ms 11732 KB Output is correct
17 Correct 74 ms 12260 KB Output is correct
18 Correct 70 ms 12392 KB Output is correct
19 Correct 69 ms 12392 KB Output is correct
20 Correct 69 ms 12392 KB Output is correct
21 Correct 63 ms 12392 KB Output is correct
22 Correct 46 ms 12392 KB Output is correct
23 Correct 68 ms 12396 KB Output is correct
24 Correct 51 ms 12396 KB Output is correct
25 Correct 45 ms 12396 KB Output is correct
26 Correct 50 ms 12396 KB Output is correct
27 Correct 62 ms 12396 KB Output is correct
28 Correct 57 ms 12396 KB Output is correct
29 Correct 81 ms 12540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Correct 10 ms 9956 KB Output is correct
3 Correct 11 ms 10032 KB Output is correct
4 Correct 11 ms 10080 KB Output is correct
5 Correct 11 ms 10080 KB Output is correct
6 Correct 11 ms 10080 KB Output is correct
7 Correct 11 ms 10080 KB Output is correct
8 Correct 11 ms 10080 KB Output is correct
9 Correct 10 ms 10092 KB Output is correct
10 Correct 11 ms 10112 KB Output is correct
11 Correct 11 ms 10240 KB Output is correct
12 Correct 11 ms 10240 KB Output is correct
13 Correct 11 ms 10240 KB Output is correct
14 Correct 23 ms 10548 KB Output is correct
15 Correct 37 ms 11188 KB Output is correct
16 Correct 53 ms 11732 KB Output is correct
17 Correct 74 ms 12260 KB Output is correct
18 Correct 70 ms 12392 KB Output is correct
19 Correct 69 ms 12392 KB Output is correct
20 Correct 69 ms 12392 KB Output is correct
21 Correct 63 ms 12392 KB Output is correct
22 Correct 46 ms 12392 KB Output is correct
23 Correct 68 ms 12396 KB Output is correct
24 Correct 51 ms 12396 KB Output is correct
25 Correct 45 ms 12396 KB Output is correct
26 Correct 50 ms 12396 KB Output is correct
27 Correct 62 ms 12396 KB Output is correct
28 Correct 57 ms 12396 KB Output is correct
29 Correct 81 ms 12540 KB Output is correct
30 Correct 92 ms 12540 KB Output is correct
31 Correct 151 ms 13548 KB Output is correct
32 Correct 228 ms 16104 KB Output is correct
33 Correct 378 ms 21224 KB Output is correct
34 Correct 74 ms 21224 KB Output is correct
35 Correct 380 ms 21408 KB Output is correct
36 Correct 374 ms 21408 KB Output is correct
37 Correct 377 ms 21408 KB Output is correct
38 Correct 374 ms 21408 KB Output is correct
39 Correct 422 ms 21500 KB Output is correct
40 Correct 319 ms 21500 KB Output is correct
41 Correct 380 ms 21500 KB Output is correct
42 Correct 375 ms 21500 KB Output is correct
43 Correct 162 ms 21500 KB Output is correct
44 Correct 166 ms 21500 KB Output is correct
45 Correct 162 ms 21500 KB Output is correct
46 Correct 246 ms 21500 KB Output is correct
47 Correct 357 ms 21500 KB Output is correct
48 Correct 347 ms 21500 KB Output is correct
49 Correct 311 ms 21500 KB Output is correct