답안 #295390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295390 2020-09-09T16:17:23 Z patrikpavic2 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
180 ms 33648 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define PB push_back

using namespace std;

typedef long long ll;
typedef vector < int > vi;

const int N = 2e5 + 500;
const int OFF = (1 << 19);

int n, q, A[N], B[N], Q[N];
int loga[N], l_siz, izb[N];
vi saz, T[2 * OFF];

void add(int x){
	l_siz++;
	for(x += 5 ; x < N ; x += x & -x)
		loga[x]++;
}

int query(int x){
	x--;
	int ret = 0;
	for(x += 5 ; x ; x -= x & -x)
		ret += loga[x];
	return l_siz - ret;
}

ll sol = 0;

void izbaci(int i){
	if(izb[i]) return;
	izb[i] = 1;
	if(query(B[i]) & 1)
		sol += saz[min(A[i], B[i])];
	else
		sol += saz[max(A[i], B[i])];
}

void dodaj(int i, int a, int b, int lo, int hi, int x){
	if(lo <= a && b <= hi){
		T[i].PB(x); return;
	}	
	if(a > hi || b < lo) return;
	dodaj(2 * i, a, (a + b) / 2, lo, hi, x);
	dodaj(2 * i + 1, (a + b) / 2 + 1, b, lo, hi, x);
}

void unisti(int x){
	x += OFF;
	for(; x ; x /= 2){
		for(int y : T[x])
			izbaci(y);
		T[x].clear();
	}
}

int main(){
	scanf("%d%d", &n, &q);
	for(int i = 0;i < n;i++){
		scanf("%d%d", A + i, B + i);
		saz.PB(A[i]), saz.PB(B[i]);
	}
	for(int i = 0;i < q;i++){
		scanf("%d", Q + i);
		saz.PB(Q[i]);
	}
	sort(saz.begin(), saz.end());
	saz.erase(unique(saz.begin(), saz.end()), saz.end());
	for(int i = 0;i < n;i++){
		A[i] = lower_bound(saz.begin(), saz.end(), A[i]) - saz.begin();
		B[i] = lower_bound(saz.begin(), saz.end(), B[i]) - saz.begin();
	}
	for(int i = 0;i < q;i++){
		Q[i] = lower_bound(saz.begin(), saz.end(), Q[i]) - saz.begin();
	}
	for(int i = 0;i < n;i++){
		if(A[i] == B[i]){
			izb[i] = 1;
			sol += saz[A[i]]; continue;
		}
		dodaj(1, 0, OFF - 1, min(A[i], B[i]), max(A[i], B[i]) - 1, i);
	}
	for(int i = q - 1;i >= 0;i--){
		unisti(Q[i]); add(Q[i]);
	}
	for(int i = 0;i < n;i++){
		if(!izb[i]){
			if(query(B[i]) & 1)
				sol += saz[B[i]];
			else
				sol += saz[A[i]];
		}
	}
	printf("%lld\n", sol);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |   scanf("%d%d", A + i, B + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |   scanf("%d", Q + i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 25088 KB Output is correct
2 Correct 17 ms 25088 KB Output is correct
3 Correct 18 ms 25216 KB Output is correct
4 Correct 18 ms 25216 KB Output is correct
5 Correct 18 ms 25216 KB Output is correct
6 Correct 18 ms 25216 KB Output is correct
7 Correct 18 ms 25088 KB Output is correct
8 Correct 19 ms 25208 KB Output is correct
9 Correct 18 ms 25088 KB Output is correct
10 Correct 19 ms 25088 KB Output is correct
11 Correct 17 ms 25088 KB Output is correct
12 Correct 17 ms 25080 KB Output is correct
13 Correct 17 ms 25088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 25088 KB Output is correct
2 Correct 17 ms 25088 KB Output is correct
3 Correct 18 ms 25216 KB Output is correct
4 Correct 18 ms 25216 KB Output is correct
5 Correct 18 ms 25216 KB Output is correct
6 Correct 18 ms 25216 KB Output is correct
7 Correct 18 ms 25088 KB Output is correct
8 Correct 19 ms 25208 KB Output is correct
9 Correct 18 ms 25088 KB Output is correct
10 Correct 19 ms 25088 KB Output is correct
11 Correct 17 ms 25088 KB Output is correct
12 Correct 17 ms 25080 KB Output is correct
13 Correct 17 ms 25088 KB Output is correct
14 Correct 42 ms 27012 KB Output is correct
15 Correct 74 ms 29172 KB Output is correct
16 Correct 111 ms 31472 KB Output is correct
17 Correct 153 ms 33644 KB Output is correct
18 Correct 157 ms 33648 KB Output is correct
19 Correct 158 ms 33644 KB Output is correct
20 Correct 149 ms 33392 KB Output is correct
21 Correct 138 ms 32624 KB Output is correct
22 Correct 100 ms 31468 KB Output is correct
23 Correct 96 ms 31088 KB Output is correct
24 Correct 91 ms 30704 KB Output is correct
25 Correct 96 ms 31600 KB Output is correct
26 Correct 90 ms 29936 KB Output is correct
27 Correct 104 ms 30320 KB Output is correct
28 Correct 99 ms 30576 KB Output is correct
29 Correct 94 ms 29040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 25088 KB Output is correct
2 Correct 17 ms 25088 KB Output is correct
3 Correct 18 ms 25216 KB Output is correct
4 Correct 18 ms 25216 KB Output is correct
5 Correct 18 ms 25216 KB Output is correct
6 Correct 18 ms 25216 KB Output is correct
7 Correct 18 ms 25088 KB Output is correct
8 Correct 19 ms 25208 KB Output is correct
9 Correct 18 ms 25088 KB Output is correct
10 Correct 19 ms 25088 KB Output is correct
11 Correct 17 ms 25088 KB Output is correct
12 Correct 17 ms 25080 KB Output is correct
13 Correct 17 ms 25088 KB Output is correct
14 Correct 42 ms 27012 KB Output is correct
15 Correct 74 ms 29172 KB Output is correct
16 Correct 111 ms 31472 KB Output is correct
17 Correct 153 ms 33644 KB Output is correct
18 Correct 157 ms 33648 KB Output is correct
19 Correct 158 ms 33644 KB Output is correct
20 Correct 149 ms 33392 KB Output is correct
21 Correct 138 ms 32624 KB Output is correct
22 Correct 100 ms 31468 KB Output is correct
23 Correct 96 ms 31088 KB Output is correct
24 Correct 91 ms 30704 KB Output is correct
25 Correct 96 ms 31600 KB Output is correct
26 Correct 90 ms 29936 KB Output is correct
27 Correct 104 ms 30320 KB Output is correct
28 Correct 99 ms 30576 KB Output is correct
29 Correct 94 ms 29040 KB Output is correct
30 Incorrect 180 ms 31724 KB Output isn't correct
31 Halted 0 ms 0 KB -