답안 #113728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113728 2019-05-28T06:18:30 Z khsoo01 운세 보기 2 (JOI14_fortune_telling2) C++11
100 / 100
364 ms 25316 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 200005, L = 524288;

int n, q, a[N], b[N], c[N], lst[N], cnt[N];
long long ans;
vector<int> cpr;
vector<pii> swp[N];

struct maxseg {
	int v[2*L];
	void upd (int P, int V) {
		if(P < 0) return;
		P += L;
		while(P) {
			v[P] = max(v[P], V);
			P /= 2;
		}
	}
	int get (int S, int E) {
		S += L; E += L;
		int R = 0;
		while(S <= E) {
			if(S%2 == 1) R = max(R, v[S++]);
			if(E%2 == 0) R = max(R, v[E--]);
			S /= 2; E /= 2;
		}
		return R;
	}
} seg1;

struct sumseg {
	int v[2*L];
	void upd (int P, int V) {
		if(P < 0) return;
		P += L;
		while(P) {
			v[P] += V;
			P /= 2;
		}
	}
	int get (int S, int E) {
		S += L; E += L;
		int R = 0;
		while(S <= E) {
			if(S%2 == 1) R += v[S++];
			if(E%2 == 0) R += v[E--];
			S /= 2; E /= 2;
		}
		return R;
	}
} seg2;

int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&a[i],&b[i]);
		cpr.push_back(a[i]);
		cpr.push_back(b[i]);
	}
	sort(cpr.begin(), cpr.end());
	cpr.erase(unique(cpr.begin(), cpr.end()), cpr.end());
	for(int i=1;i<=n;i++) {
		a[i] = lower_bound(cpr.begin(), cpr.end(), a[i]) - cpr.begin();
		b[i] = lower_bound(cpr.begin(), cpr.end(), b[i]) - cpr.begin();
	}
	for(int i=1;i<=q;i++) {
		scanf("%d", &c[i]);
		c[i] = upper_bound(cpr.begin(), cpr.end(), c[i]) - cpr.begin() - 1;
		seg1.upd(c[i], i);
	}
	for(int i=1;i<=n;i++) {
		lst[i] = seg1.get(min(a[i], b[i]), max(a[i], b[i])-1);
		swp[lst[i]+1].push_back({max(a[i], b[i]), i});
	}
	for(int i=q;i>=1;i--) {
		seg2.upd(c[i], 1);
		for(auto &T : swp[i]) {
			int A, B;
			tie(A, B) = T;
			cnt[B] += seg2.get(A, L-1);
		}
	}
	for(int i=1;i<=n;i++) {
		int X = (lst[i] && a[i] < b[i]) + cnt[i];
		ans += cpr[X % 2 ? b[i] : a[i]];
	}
	printf("%lld\n", ans);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
fortune_telling2.cpp:59: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:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &c[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 18 ms 6144 KB Output is correct
15 Correct 31 ms 7156 KB Output is correct
16 Correct 44 ms 8052 KB Output is correct
17 Correct 58 ms 9072 KB Output is correct
18 Correct 61 ms 9196 KB Output is correct
19 Correct 59 ms 9200 KB Output is correct
20 Correct 61 ms 9200 KB Output is correct
21 Correct 53 ms 9456 KB Output is correct
22 Correct 42 ms 8560 KB Output is correct
23 Correct 41 ms 8304 KB Output is correct
24 Correct 43 ms 8236 KB Output is correct
25 Correct 38 ms 8428 KB Output is correct
26 Correct 44 ms 8048 KB Output is correct
27 Correct 49 ms 8556 KB Output is correct
28 Correct 49 ms 8560 KB Output is correct
29 Correct 57 ms 8816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 6 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 18 ms 6144 KB Output is correct
15 Correct 31 ms 7156 KB Output is correct
16 Correct 44 ms 8052 KB Output is correct
17 Correct 58 ms 9072 KB Output is correct
18 Correct 61 ms 9196 KB Output is correct
19 Correct 59 ms 9200 KB Output is correct
20 Correct 61 ms 9200 KB Output is correct
21 Correct 53 ms 9456 KB Output is correct
22 Correct 42 ms 8560 KB Output is correct
23 Correct 41 ms 8304 KB Output is correct
24 Correct 43 ms 8236 KB Output is correct
25 Correct 38 ms 8428 KB Output is correct
26 Correct 44 ms 8048 KB Output is correct
27 Correct 49 ms 8556 KB Output is correct
28 Correct 49 ms 8560 KB Output is correct
29 Correct 57 ms 8816 KB Output is correct
30 Correct 76 ms 8824 KB Output is correct
31 Correct 128 ms 12148 KB Output is correct
32 Correct 193 ms 16384 KB Output is correct
33 Correct 337 ms 25316 KB Output is correct
34 Correct 62 ms 7800 KB Output is correct
35 Correct 356 ms 25316 KB Output is correct
36 Correct 333 ms 25052 KB Output is correct
37 Correct 362 ms 25008 KB Output is correct
38 Correct 345 ms 25060 KB Output is correct
39 Correct 357 ms 24932 KB Output is correct
40 Correct 298 ms 23412 KB Output is correct
41 Correct 364 ms 24804 KB Output is correct
42 Correct 362 ms 24676 KB Output is correct
43 Correct 164 ms 19172 KB Output is correct
44 Correct 164 ms 20040 KB Output is correct
45 Correct 165 ms 21516 KB Output is correct
46 Correct 214 ms 21340 KB Output is correct
47 Correct 188 ms 19556 KB Output is correct
48 Correct 263 ms 21704 KB Output is correct
49 Correct 262 ms 22272 KB Output is correct