답안 #52266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52266 2018-06-25T07:23:18 Z ics0503 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
3000 ms 16036 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
struct xy { int x, y; }a[212121];
bool sort_x(xy a, xy b) { if (a.x != b.x)return a.x < b.x; return a.y < b.y; }
int Q[212121], ALL[414141], an, tn, tree[1212121], P[212121];
vector<int>T[212121], R;
int oper(int a, int b, int tp) {if (tp == 1) { if (a < b)return b; return a; }else return a + b;}
void insert_g(int w, int g, int tp) { for (int i = w + tn; i > 0; i /= 2)tree[i] = oper(tree[i], g, tp); }
int search_g(int ss, int ee,int tp) {
	int s = ss + tn, e = ee + tn, res = tp==1?-1:0;
	while (s <= e) {
		if (s % 2 == 1)res = oper(res, tree[s++],tp);
		if (e % 2 == 0)res = oper(res, tree[e--],tp);
		s /= 2; e /= 2;
	}
	return res;
}
int main() {
	int n, m, i, j; scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)scanf("%d%d", &a[i].x, &a[i].y), ALL[an++] = a[i].x, ALL[an++] = a[i].y;
	for (i = 0; i < m; i++)scanf("%d", &Q[i]), ALL[an++] = Q[i];
	sort(ALL, ALL + an);
	an = unique(ALL, ALL + an) - ALL;
	for (i = 0; i < n; i++)a[i] = { lower_bound(ALL, ALL + an, a[i].x) - ALL,lower_bound(ALL, ALL + an, a[i].y) - ALL };
	for (i = 0; i < m; i++)Q[i] = lower_bound(ALL, ALL + an, Q[i]) - ALL;
	for (tn = 1; tn < an; tn *= 2);
	for (i = 0; i < tn * 2; i++)tree[i] = -1;
	for (i = 0; i < m; i++)insert_g(Q[i], i,1);
	for (i = 0; i < n; i++) {
		int s = min(a[i].x, a[i].y), e = max(a[i].x, a[i].y);
		P[i] = search_g(s, e - 1,1);
		if (P[i] == -1)R.push_back(i);
		else T[P[i]].push_back(i);
	}
	for (i = 0; i < tn * 2; i++)tree[i] = 0;
	long long ans = 0;
	for (i = m - 1; i >= 0; i--) {
		for (j = 0; j < T[i].size(); j++) {
			int now = T[i][j];
			if (search_g(max(a[now].x, a[now].y), an - 1, 0) % 2 == 0)ans += ALL[max(a[now].x, a[now].y)];
			else ans += ALL[min(a[now].x, a[now].y)];
		}
		insert_g(Q[i], 1, 0);
	}
	for (i = 0; i < R.size(); i++) {
		int now = R[i];
		if (search_g(a[now].x, an - 1, 0) % 2 == 0)ans += ALL[a[now].x];
		else ans += ALL[a[now].y];
	}
	printf("%lld", ans);
	return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:26:69: warning: narrowing conversion of '((((long int)std::lower_bound<int*, int>(((int*)(& ALL)), (((int*)(& ALL)) + ((sizetype)(((long unsigned int)an) * 4))), a[i].xy::x)) - ((long int)((int*)(& ALL)))) (ceiling /) 4)' from 'long int' to 'int' inside { } [-Wnarrowing]
  for (i = 0; i < n; i++)a[i] = { lower_bound(ALL, ALL + an, a[i].x) - ALL,lower_bound(ALL, ALL + an, a[i].y) - ALL };
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
fortune_telling2.cpp:26:110: warning: narrowing conversion of '((((long int)std::lower_bound<int*, int>(((int*)(& ALL)), (((int*)(& ALL)) + ((sizetype)(((long unsigned int)an) * 4))), a[i].xy::y)) - ((long int)((int*)(& ALL)))) (ceiling /) 4)' from 'long int' to 'int' inside { } [-Wnarrowing]
  for (i = 0; i < n; i++)a[i] = { lower_bound(ALL, ALL + an, a[i].x) - ALL,lower_bound(ALL, ALL + an, a[i].y) - ALL };
                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
fortune_telling2.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j = 0; j < T[i].size(); j++) {
               ~~^~~~~~~~~~~~~
fortune_telling2.cpp:47:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < R.size(); i++) {
              ~~^~~~~~~~~~
fortune_telling2.cpp:21:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, m, i, j; scanf("%d%d", &n, &m);
                  ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:22:76: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < n; i++)scanf("%d%d", &a[i].x, &a[i].y), ALL[an++] = a[i].x, ALL[an++] = a[i].y;
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:23:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < m; i++)scanf("%d", &Q[i]), ALL[an++] = Q[i];
                         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5368 KB Output is correct
2 Correct 7 ms 5368 KB Output is correct
3 Correct 9 ms 5428 KB Output is correct
4 Correct 9 ms 5484 KB Output is correct
5 Correct 7 ms 5536 KB Output is correct
6 Correct 7 ms 5664 KB Output is correct
7 Correct 7 ms 5664 KB Output is correct
8 Correct 7 ms 5664 KB Output is correct
9 Correct 9 ms 5664 KB Output is correct
10 Correct 7 ms 5664 KB Output is correct
11 Correct 7 ms 5680 KB Output is correct
12 Correct 10 ms 5680 KB Output is correct
13 Correct 7 ms 5680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5368 KB Output is correct
2 Correct 7 ms 5368 KB Output is correct
3 Correct 9 ms 5428 KB Output is correct
4 Correct 9 ms 5484 KB Output is correct
5 Correct 7 ms 5536 KB Output is correct
6 Correct 7 ms 5664 KB Output is correct
7 Correct 7 ms 5664 KB Output is correct
8 Correct 7 ms 5664 KB Output is correct
9 Correct 9 ms 5664 KB Output is correct
10 Correct 7 ms 5664 KB Output is correct
11 Correct 7 ms 5680 KB Output is correct
12 Correct 10 ms 5680 KB Output is correct
13 Correct 7 ms 5680 KB Output is correct
14 Correct 21 ms 6124 KB Output is correct
15 Correct 38 ms 6764 KB Output is correct
16 Correct 56 ms 7580 KB Output is correct
17 Correct 75 ms 7916 KB Output is correct
18 Correct 77 ms 7940 KB Output is correct
19 Correct 74 ms 7940 KB Output is correct
20 Correct 73 ms 7940 KB Output is correct
21 Correct 72 ms 8300 KB Output is correct
22 Correct 51 ms 8300 KB Output is correct
23 Correct 51 ms 8300 KB Output is correct
24 Correct 50 ms 8300 KB Output is correct
25 Correct 53 ms 8300 KB Output is correct
26 Correct 54 ms 8300 KB Output is correct
27 Correct 69 ms 8300 KB Output is correct
28 Correct 62 ms 8300 KB Output is correct
29 Correct 67 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5368 KB Output is correct
2 Correct 7 ms 5368 KB Output is correct
3 Correct 9 ms 5428 KB Output is correct
4 Correct 9 ms 5484 KB Output is correct
5 Correct 7 ms 5536 KB Output is correct
6 Correct 7 ms 5664 KB Output is correct
7 Correct 7 ms 5664 KB Output is correct
8 Correct 7 ms 5664 KB Output is correct
9 Correct 9 ms 5664 KB Output is correct
10 Correct 7 ms 5664 KB Output is correct
11 Correct 7 ms 5680 KB Output is correct
12 Correct 10 ms 5680 KB Output is correct
13 Correct 7 ms 5680 KB Output is correct
14 Correct 21 ms 6124 KB Output is correct
15 Correct 38 ms 6764 KB Output is correct
16 Correct 56 ms 7580 KB Output is correct
17 Correct 75 ms 7916 KB Output is correct
18 Correct 77 ms 7940 KB Output is correct
19 Correct 74 ms 7940 KB Output is correct
20 Correct 73 ms 7940 KB Output is correct
21 Correct 72 ms 8300 KB Output is correct
22 Correct 51 ms 8300 KB Output is correct
23 Correct 51 ms 8300 KB Output is correct
24 Correct 50 ms 8300 KB Output is correct
25 Correct 53 ms 8300 KB Output is correct
26 Correct 54 ms 8300 KB Output is correct
27 Correct 69 ms 8300 KB Output is correct
28 Correct 62 ms 8300 KB Output is correct
29 Correct 67 ms 8300 KB Output is correct
30 Correct 126 ms 9504 KB Output is correct
31 Correct 191 ms 12540 KB Output is correct
32 Correct 279 ms 13732 KB Output is correct
33 Execution timed out 3053 ms 16036 KB Time limit exceeded
34 Halted 0 ms 0 KB -