답안 #117166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117166 2019-06-15T06:03:00 Z Just_Solve_The_Problem 운세 보기 2 (JOI14_fortune_telling2) C++11
35 / 100
331 ms 16488 KB
#include <bits/stdc++.h>

#define ll long long
#define ok puts("ok");

using namespace std;

const int N = (int)4e5 + 7;

struct T {
	int tree[N * 4];
	T() {
		memset(tree, -1, sizeof tree);
	}
	void upd(int pos, int val, int v = 1, int tl = -1, int tr = 2e5) {
		if (tl == tr) {
			tree[v] = val;
			return ;
		}
		int mid = (tl + tr) >> 1;
		if (pos <= mid) {
			upd(pos, val, v + v, tl, mid);
		} else {
			upd(pos, val, v + v + 1, mid + 1, tr);
		}
		tree[v] = max(tree[v + v], tree[v + v + 1]);
	}
	int get(int l, int r, int v = 1, int tl = -1, int tr = 2e5) {
		if (tl > r || tr < l) return -1;
		if (l <= tl && tr <= r) return tree[v];
		int mid = (tl + tr) >> 1;
		return max(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
	}
};
T tr;

struct fen {
	int tree[N];
	fen() {
		memset(tree, 0, sizeof tree);
	}
	void upd(int pos, int val) {
		pos = max(pos, 0);
		while (pos < N) {
			tree[pos] += val;
			pos = pos | (pos + 1);
		}
	}
	int get(int r) {
		int res = 0;
		while (r >= 0) {
			res += tree[r];
			r = (r & (r + 1)) - 1;
		}
		return res;
	}
};
fen bit1;

int n, k;
int flip[N];
int a[N], b[N], q[N], border[N];
ll sum = 0;

main() {
	scanf("%d %d", &n, &k);
	vector<int> vec;
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &a[i], &b[i]);
		vec.push_back(a[i]);
		vec.push_back(b[i]);
		if (a[i] > b[i]) {
			swap(a[i], b[i]);
			flip[i] = 1;
		}
	}
	for (int i = 1; i <= k; i++) {
		scanf("%d", &q[i]);
	}
	sort(vec.begin(), vec.end());
	vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
	for (int i = 1; i <= n; i++) {
		a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
		b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin();
	}
	for (int i = 1; i <= k; i++) {
		q[i] = upper_bound(vec.begin(), vec.end(), q[i]) - vec.begin() - 1;
		tr.upd(q[i], i);
	}
	vector<pair<int, int>> v1;
	for (int i = 1; i <= n; i++) {
		border[i] = tr.get(a[i], b[i] - 1);
		v1.push_back({border[i] + 1, i});
		if (border[i] > 0) {
			flip[i] = 1;
		}
	}
	sort(v1.begin(), v1.end());
	int sz = k;
	for (int i = v1.size() - 1; i >= 0; i--) {
		while (sz >= v1[i].first) {
			bit1.upd(q[sz], 1);
			sz--;
		}
		flip[v1[i].second] ^= ((k - sz - bit1.get(b[v1[i].second] - 1)) & 1);
	}
	for (int i = 1; i <= n; i++) {
		sum += (flip[i] ? vec[b[i]] : vec[a[i]]);
	}
	printf("%lld\n", sum);
}

Compilation message

fortune_telling2.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:66: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:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &q[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8192 KB Output is correct
2 Correct 8 ms 8192 KB Output is correct
3 Correct 9 ms 8192 KB Output is correct
4 Correct 9 ms 8192 KB Output is correct
5 Correct 9 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 9 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8164 KB Output is correct
10 Correct 8 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8192 KB Output is correct
2 Correct 8 ms 8192 KB Output is correct
3 Correct 9 ms 8192 KB Output is correct
4 Correct 9 ms 8192 KB Output is correct
5 Correct 9 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 9 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8164 KB Output is correct
10 Correct 8 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 22 ms 8704 KB Output is correct
15 Correct 38 ms 9076 KB Output is correct
16 Correct 51 ms 9332 KB Output is correct
17 Correct 68 ms 9968 KB Output is correct
18 Correct 68 ms 9968 KB Output is correct
19 Correct 70 ms 9968 KB Output is correct
20 Correct 68 ms 10096 KB Output is correct
21 Correct 61 ms 10096 KB Output is correct
22 Correct 46 ms 9964 KB Output is correct
23 Correct 45 ms 9964 KB Output is correct
24 Correct 45 ms 9968 KB Output is correct
25 Correct 43 ms 9968 KB Output is correct
26 Correct 47 ms 9884 KB Output is correct
27 Correct 57 ms 10096 KB Output is correct
28 Correct 54 ms 10068 KB Output is correct
29 Correct 61 ms 10116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8192 KB Output is correct
2 Correct 8 ms 8192 KB Output is correct
3 Correct 9 ms 8192 KB Output is correct
4 Correct 9 ms 8192 KB Output is correct
5 Correct 9 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 9 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8164 KB Output is correct
10 Correct 8 ms 8192 KB Output is correct
11 Correct 10 ms 8192 KB Output is correct
12 Correct 9 ms 8192 KB Output is correct
13 Correct 10 ms 8192 KB Output is correct
14 Correct 22 ms 8704 KB Output is correct
15 Correct 38 ms 9076 KB Output is correct
16 Correct 51 ms 9332 KB Output is correct
17 Correct 68 ms 9968 KB Output is correct
18 Correct 68 ms 9968 KB Output is correct
19 Correct 70 ms 9968 KB Output is correct
20 Correct 68 ms 10096 KB Output is correct
21 Correct 61 ms 10096 KB Output is correct
22 Correct 46 ms 9964 KB Output is correct
23 Correct 45 ms 9964 KB Output is correct
24 Correct 45 ms 9968 KB Output is correct
25 Correct 43 ms 9968 KB Output is correct
26 Correct 47 ms 9884 KB Output is correct
27 Correct 57 ms 10096 KB Output is correct
28 Correct 54 ms 10068 KB Output is correct
29 Correct 61 ms 10116 KB Output is correct
30 Correct 84 ms 9364 KB Output is correct
31 Correct 149 ms 10920 KB Output is correct
32 Correct 235 ms 12872 KB Output is correct
33 Incorrect 331 ms 16488 KB Output isn't correct
34 Halted 0 ms 0 KB -