Submission #52253

# Submission time Handle Problem Language Result Execution time Memory
52253 2018-06-25T06:34:17 Z 0^0(#1340) Fortune Telling 2 (JOI14_fortune_telling2) C++11
100 / 100
937 ms 61392 KB
#include <bits/stdc++.h>
using namespace std;
struct SGT{
	int n;
	vector<int> tree;
	SGT(int n) :n(n) {
		tree = vector<int>(n * 4, -1);
	}
	void update(int idx, int val, int nodele, int noderi, int node) {
		if (idx < nodele || noderi < idx)return;
		if (nodele == noderi) {
			tree[node] = val;
			return;
		}
		int mid = (nodele + noderi) / 2;
		update(idx, val, nodele, mid, node * 2);
		update(idx, val, mid + 1, noderi, node * 2 + 1);
		tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
	}
	void update(int idx, int val) {
		update(idx, val, 0, n - 1, 1);
	}
	int query(int le, int ri, int nodele, int noderi, int node) {
		if (ri<nodele || le>noderi)return -1;
		if (le <= nodele && noderi <= ri)return tree[node];
		int mid = (nodele + noderi) / 2;
		return max(query(le, ri, nodele, mid, node * 2), query(le, ri, mid + 1, noderi, node * 2 + 1));
	}
	int query(int le, int ri) {
		return query(le, ri, 0, n - 1, 1);
	}
};
struct SGT2 {
	int n;
	vector<vector<int> >tree;
	SGT2(int n,int arr[]) :n(n) {
		tree = vector<vector<int> >(n * 4);
		init(arr, 0, n - 1, 1);
	}
	void init(int arr[], int le, int ri, int node) {
		if (le == ri) {
			tree[node].push_back(arr[le]);
			return;
		}
		int mid = (le + ri) / 2;
		init(arr, le, mid, node * 2);
		init(arr, mid + 1, ri, node * 2 + 1);
		for (auto x : tree[node * 2])
			tree[node].push_back(x);
		for (auto x : tree[node * 2 + 1])
			tree[node].push_back(x);
		sort(tree[node].begin(), tree[node].end());
	}
	int query(int le, int ri,int val, int nodele, int noderi, int node) {
		if (ri<nodele || le>noderi)return 0;
		if (le <= nodele && noderi <= ri)return tree[node].size() - (lower_bound(tree[node].begin(), tree[node].end(), val) - tree[node].begin());
		int mid = (nodele + noderi) / 2;
		return query(le, ri,val, nodele, mid, node * 2)+query(le, ri,val, mid + 1, noderi, node * 2 + 1);
	}
	int query(int le, int ri,int val) {
		return query(le, ri, val, 0, n - 1, 1);
	}
};
int n, k;
pair<int, int> arr[200005];
int t[200005];
vector<int> xidx;

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &arr[i].first, &arr[i].second);
		xidx.push_back(arr[i].first);
		xidx.push_back(arr[i].second);
	}
	for (int i = 0; i < k; i++) {
		scanf("%d", &t[i]);
		xidx.push_back(t[i]); 
	}
	sort(xidx.begin(), xidx.end());
	xidx.erase(unique(xidx.begin(), xidx.end()), xidx.end());
	SGT sgt(xidx.size());
	SGT2 sgt2(k, t);
	for (int i = 0; i < k; i++) {
		int idx = lower_bound(xidx.begin(), xidx.end(), t[i]) - xidx.begin();
		sgt.update(idx, i);
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int a = min(arr[i].first, arr[i].second);
		int b = max(arr[i].first, arr[i].second);
		int idx = sgt.query(lower_bound(xidx.begin(), xidx.end(), a) - xidx.begin(), lower_bound(xidx.begin(), xidx.end(), b) - xidx.begin() - 1);
		int cnt = sgt2.query(idx + 1, k - 1, b);
		if (idx >= 0)ans += (cnt & 1 ? a : b);
		else ans += (cnt & 1 ? arr[i].second : arr[i].first);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:70: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:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &arr[i].first, &arr[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &t[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 616 KB Output is correct
3 Correct 4 ms 692 KB Output is correct
4 Correct 6 ms 840 KB Output is correct
5 Correct 4 ms 840 KB Output is correct
6 Correct 4 ms 868 KB Output is correct
7 Correct 4 ms 920 KB Output is correct
8 Correct 4 ms 920 KB Output is correct
9 Correct 4 ms 920 KB Output is correct
10 Correct 4 ms 920 KB Output is correct
11 Correct 4 ms 920 KB Output is correct
12 Correct 4 ms 920 KB Output is correct
13 Correct 4 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 616 KB Output is correct
3 Correct 4 ms 692 KB Output is correct
4 Correct 6 ms 840 KB Output is correct
5 Correct 4 ms 840 KB Output is correct
6 Correct 4 ms 868 KB Output is correct
7 Correct 4 ms 920 KB Output is correct
8 Correct 4 ms 920 KB Output is correct
9 Correct 4 ms 920 KB Output is correct
10 Correct 4 ms 920 KB Output is correct
11 Correct 4 ms 920 KB Output is correct
12 Correct 4 ms 920 KB Output is correct
13 Correct 4 ms 1016 KB Output is correct
14 Correct 35 ms 3612 KB Output is correct
15 Correct 67 ms 6592 KB Output is correct
16 Correct 108 ms 9080 KB Output is correct
17 Correct 134 ms 12856 KB Output is correct
18 Correct 134 ms 12916 KB Output is correct
19 Correct 132 ms 12916 KB Output is correct
20 Correct 139 ms 12916 KB Output is correct
21 Correct 132 ms 12928 KB Output is correct
22 Correct 110 ms 12928 KB Output is correct
23 Correct 127 ms 12928 KB Output is correct
24 Correct 112 ms 12928 KB Output is correct
25 Correct 104 ms 12928 KB Output is correct
26 Correct 107 ms 12928 KB Output is correct
27 Correct 172 ms 12928 KB Output is correct
28 Correct 111 ms 12928 KB Output is correct
29 Correct 139 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 616 KB Output is correct
3 Correct 4 ms 692 KB Output is correct
4 Correct 6 ms 840 KB Output is correct
5 Correct 4 ms 840 KB Output is correct
6 Correct 4 ms 868 KB Output is correct
7 Correct 4 ms 920 KB Output is correct
8 Correct 4 ms 920 KB Output is correct
9 Correct 4 ms 920 KB Output is correct
10 Correct 4 ms 920 KB Output is correct
11 Correct 4 ms 920 KB Output is correct
12 Correct 4 ms 920 KB Output is correct
13 Correct 4 ms 1016 KB Output is correct
14 Correct 35 ms 3612 KB Output is correct
15 Correct 67 ms 6592 KB Output is correct
16 Correct 108 ms 9080 KB Output is correct
17 Correct 134 ms 12856 KB Output is correct
18 Correct 134 ms 12916 KB Output is correct
19 Correct 132 ms 12916 KB Output is correct
20 Correct 139 ms 12916 KB Output is correct
21 Correct 132 ms 12928 KB Output is correct
22 Correct 110 ms 12928 KB Output is correct
23 Correct 127 ms 12928 KB Output is correct
24 Correct 112 ms 12928 KB Output is correct
25 Correct 104 ms 12928 KB Output is correct
26 Correct 107 ms 12928 KB Output is correct
27 Correct 172 ms 12928 KB Output is correct
28 Correct 111 ms 12928 KB Output is correct
29 Correct 139 ms 12928 KB Output is correct
30 Correct 504 ms 52464 KB Output is correct
31 Correct 583 ms 54172 KB Output is correct
32 Correct 653 ms 56680 KB Output is correct
33 Correct 874 ms 61392 KB Output is correct
34 Correct 515 ms 61392 KB Output is correct
35 Correct 932 ms 61392 KB Output is correct
36 Correct 920 ms 61392 KB Output is correct
37 Correct 937 ms 61392 KB Output is correct
38 Correct 874 ms 61392 KB Output is correct
39 Correct 928 ms 61392 KB Output is correct
40 Correct 816 ms 61392 KB Output is correct
41 Correct 862 ms 61392 KB Output is correct
42 Correct 869 ms 61392 KB Output is correct
43 Correct 643 ms 61392 KB Output is correct
44 Correct 611 ms 61392 KB Output is correct
45 Correct 598 ms 61392 KB Output is correct
46 Correct 639 ms 61392 KB Output is correct
47 Correct 605 ms 61392 KB Output is correct
48 Correct 764 ms 61392 KB Output is correct
49 Correct 672 ms 61392 KB Output is correct