답안 #673495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673495 2022-12-20T17:22:31 Z 406 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1721 ms 38860 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50;
int mx[4 * N], delta[4 * N];
vector<pair<int, int>> D;
void add(int v, int l, int r, int L, int R, int d) {
	if (R <= L || R <= l || r <= L) return;
	if (l >= L && r <= R) {
		mx[v] += d, delta[v] += d;
		return;
	}
	int m = l + r >> 1;
	add(v<<1, l, m, L, R, d);
	add(v<<1|1, m, r, L, R, d);
	mx[v] = max(mx[v<<1], mx[v<<1|1]) + delta[v];
}
int loc(pair<int, int> p) {return lower_bound(D.begin(), D.end(), p) - D.begin();}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	int Q = X.size();
	int n = A.size();
	D.reserve(Q + n);
	for (int i = 0; i < n; i++)
		D.emplace_back(A[i], i);
	for (int i = 0; i < Q; i++)
		D.emplace_back(V[i], X[i]);
	sort(D.begin(), D.end()), D.resize(unique(D.begin(), D.end()) - D.begin());
	for (int i = 0; i < n; i++) {
		int ind = loc({A[i], i});
		add(1, 0, D.size(), ind, ind + 1, +i);
		add(1, 0, D.size(), ind + 1, D.size(), -1);
	}
	vector<int> answer(Q);
	for (int i = 0; i < Q; i++) {
		int ind = loc({A[X[i]], X[i]});
		add(1, 0, D.size(), ind, ind + 1, -X[i]);	
		add(1, 0, D.size(), ind + 1, D.size(), +1);
		ind = loc({V[i], X[i]});
		add(1, 0, D.size(), ind, ind + 1, +X[i]);
		add(1, 0, D.size(), ind + 1, D.size(), -1);
		A[X[i]] = V[i];
		answer[i] = max(mx[1], 0);
	}
	return answer;
}

Compilation message

bubblesort2.cpp: In function 'void add(int, int, int, int, int, int)':
bubblesort2.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |  int m = l + r >> 1;
      |          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 448 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 4 ms 448 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 444 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 456 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 448 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 448 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 4 ms 448 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 444 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 456 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 448 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 13 ms 1060 KB Output is correct
20 Correct 15 ms 1108 KB Output is correct
21 Correct 14 ms 1100 KB Output is correct
22 Correct 16 ms 1108 KB Output is correct
23 Correct 16 ms 1092 KB Output is correct
24 Correct 14 ms 996 KB Output is correct
25 Correct 13 ms 1108 KB Output is correct
26 Correct 14 ms 988 KB Output is correct
27 Correct 14 ms 980 KB Output is correct
28 Correct 14 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1416 KB Output is correct
2 Correct 58 ms 2792 KB Output is correct
3 Correct 109 ms 4868 KB Output is correct
4 Correct 104 ms 4812 KB Output is correct
5 Correct 109 ms 4952 KB Output is correct
6 Correct 101 ms 4868 KB Output is correct
7 Correct 102 ms 4812 KB Output is correct
8 Correct 105 ms 4912 KB Output is correct
9 Correct 101 ms 4832 KB Output is correct
10 Correct 87 ms 3840 KB Output is correct
11 Correct 86 ms 3868 KB Output is correct
12 Correct 87 ms 3876 KB Output is correct
13 Correct 85 ms 3916 KB Output is correct
14 Correct 83 ms 3752 KB Output is correct
15 Correct 82 ms 3788 KB Output is correct
16 Correct 80 ms 3876 KB Output is correct
17 Correct 85 ms 3840 KB Output is correct
18 Correct 83 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 448 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 4 ms 448 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 444 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 456 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 448 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 13 ms 1060 KB Output is correct
20 Correct 15 ms 1108 KB Output is correct
21 Correct 14 ms 1100 KB Output is correct
22 Correct 16 ms 1108 KB Output is correct
23 Correct 16 ms 1092 KB Output is correct
24 Correct 14 ms 996 KB Output is correct
25 Correct 13 ms 1108 KB Output is correct
26 Correct 14 ms 988 KB Output is correct
27 Correct 14 ms 980 KB Output is correct
28 Correct 14 ms 1108 KB Output is correct
29 Correct 20 ms 1416 KB Output is correct
30 Correct 58 ms 2792 KB Output is correct
31 Correct 109 ms 4868 KB Output is correct
32 Correct 104 ms 4812 KB Output is correct
33 Correct 109 ms 4952 KB Output is correct
34 Correct 101 ms 4868 KB Output is correct
35 Correct 102 ms 4812 KB Output is correct
36 Correct 105 ms 4912 KB Output is correct
37 Correct 101 ms 4832 KB Output is correct
38 Correct 87 ms 3840 KB Output is correct
39 Correct 86 ms 3868 KB Output is correct
40 Correct 87 ms 3876 KB Output is correct
41 Correct 85 ms 3916 KB Output is correct
42 Correct 83 ms 3752 KB Output is correct
43 Correct 82 ms 3788 KB Output is correct
44 Correct 80 ms 3876 KB Output is correct
45 Correct 85 ms 3840 KB Output is correct
46 Correct 83 ms 3788 KB Output is correct
47 Correct 375 ms 15192 KB Output is correct
48 Correct 1623 ms 37052 KB Output is correct
49 Correct 1679 ms 38732 KB Output is correct
50 Correct 1689 ms 38744 KB Output is correct
51 Correct 1678 ms 38736 KB Output is correct
52 Correct 1690 ms 38652 KB Output is correct
53 Correct 1721 ms 38648 KB Output is correct
54 Correct 1639 ms 38652 KB Output is correct
55 Correct 1597 ms 38704 KB Output is correct
56 Correct 1514 ms 38860 KB Output is correct
57 Correct 1577 ms 38652 KB Output is correct
58 Correct 1563 ms 38660 KB Output is correct
59 Correct 1406 ms 38648 KB Output is correct
60 Correct 1412 ms 38660 KB Output is correct
61 Correct 1401 ms 38656 KB Output is correct
62 Correct 1394 ms 38768 KB Output is correct
63 Correct 1350 ms 38652 KB Output is correct
64 Correct 1325 ms 38576 KB Output is correct
65 Correct 1242 ms 38212 KB Output is correct
66 Correct 1242 ms 38212 KB Output is correct
67 Correct 1240 ms 38264 KB Output is correct