답안 #66459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66459 2018-08-10T15:58:47 Z zadrga Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3018 ms 149432 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (int) (2 * 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1000111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

struct segtree{
	int seg[4 * maxn], lazy[4 * maxn];

	void push(int x, int l, int d){
		seg[x] += lazy[x];
		if(l != d){
			lazy[2 * x] += lazy[x];
			lazy[2 * x + 1] += lazy[x];	
		}
		lazy[x] = 0;
	}

	void update(int x, int l, int d, int i, int j, int val){
		push(x, l, d);
		if(l > d || l > j || d < i)
			return;

		if(i <= l && d <= j){
			lazy[x] += val;
			push(x, l, d);
			return;
		}

		int mid = (l + d) / 2;
		update(2 * x, l, mid, i, j, val);
		update(2 * x + 1, mid + 1, d, i, j, val);
		seg[x] = max(seg[2 * x], seg[2 * x + 1]);
	}

	int get(int x, int l, int d){
		push(x, l, d);
		return seg[x];
	}

} seg;

int arr[maxn];
int n;

void remove(int x, int pos){
	seg.update(1, 1, n, x, x, -(INF + pos));
	seg.update(1, 1, n, x + 1, n, 1);
}

void add(int x, int pos){
	seg.update(1, 1, n, x, x, INF + pos);
	seg.update(1, 1, n, x + 1, n, -1);
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	vector<int> ans;
	int q = X.size();

	vector<pii> v;
	for(int i = 0; i < A.size(); i++)
		v.pb(mp(A[i], i));

	for(int i = 0; i < q; i++)
		v.pb(mp(V[i], X[i]));

	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));

	n = v.size();
	seg.update(1, 1, n, 1, n, -INF);

	for(int i = 0; i < A.size(); i++){
		A[i] = lower_bound(v.begin(), v.end(), mp(A[i], i)) - v.begin() + 1;
		add(A[i], i);
		arr[i] = A[i];
	}

	for(int i = 0; i < q; i++){
		V[i] = lower_bound(v.begin(), v.end(), mp(V[i], X[i])) - v.begin() + 1;
		int pos = X[i];
		remove(arr[pos], pos);
		add(V[i], pos);
		arr[pos] = V[i];
		ans.pb(seg.get(1, 1, n));
	}

	return ans;
}

/*
4 2
1 2 3 4
0 3
2 1
*/

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:72:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < A.size(); i++)
                 ~~^~~~~~~~~~
bubblesort2.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < A.size(); i++){
                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 7 ms 672 KB Output is correct
4 Correct 9 ms 672 KB Output is correct
5 Correct 7 ms 804 KB Output is correct
6 Correct 7 ms 804 KB Output is correct
7 Correct 7 ms 860 KB Output is correct
8 Correct 7 ms 860 KB Output is correct
9 Correct 7 ms 860 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 8 ms 876 KB Output is correct
13 Correct 6 ms 940 KB Output is correct
14 Correct 6 ms 940 KB Output is correct
15 Correct 7 ms 940 KB Output is correct
16 Correct 7 ms 940 KB Output is correct
17 Correct 7 ms 940 KB Output is correct
18 Correct 10 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 7 ms 672 KB Output is correct
4 Correct 9 ms 672 KB Output is correct
5 Correct 7 ms 804 KB Output is correct
6 Correct 7 ms 804 KB Output is correct
7 Correct 7 ms 860 KB Output is correct
8 Correct 7 ms 860 KB Output is correct
9 Correct 7 ms 860 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 8 ms 876 KB Output is correct
13 Correct 6 ms 940 KB Output is correct
14 Correct 6 ms 940 KB Output is correct
15 Correct 7 ms 940 KB Output is correct
16 Correct 7 ms 940 KB Output is correct
17 Correct 7 ms 940 KB Output is correct
18 Correct 10 ms 940 KB Output is correct
19 Correct 21 ms 1340 KB Output is correct
20 Correct 25 ms 1340 KB Output is correct
21 Correct 25 ms 1340 KB Output is correct
22 Correct 30 ms 1392 KB Output is correct
23 Correct 22 ms 1392 KB Output is correct
24 Correct 21 ms 1392 KB Output is correct
25 Correct 26 ms 1392 KB Output is correct
26 Correct 22 ms 1444 KB Output is correct
27 Correct 26 ms 1444 KB Output is correct
28 Correct 23 ms 1444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1932 KB Output is correct
2 Correct 90 ms 3252 KB Output is correct
3 Correct 178 ms 5264 KB Output is correct
4 Correct 176 ms 5296 KB Output is correct
5 Correct 186 ms 5312 KB Output is correct
6 Correct 171 ms 5436 KB Output is correct
7 Correct 179 ms 5436 KB Output is correct
8 Correct 182 ms 5436 KB Output is correct
9 Correct 177 ms 5436 KB Output is correct
10 Correct 141 ms 5436 KB Output is correct
11 Correct 136 ms 5436 KB Output is correct
12 Correct 137 ms 5436 KB Output is correct
13 Correct 159 ms 5436 KB Output is correct
14 Correct 138 ms 5436 KB Output is correct
15 Correct 153 ms 5436 KB Output is correct
16 Correct 142 ms 5436 KB Output is correct
17 Correct 124 ms 5436 KB Output is correct
18 Correct 122 ms 5436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 7 ms 672 KB Output is correct
4 Correct 9 ms 672 KB Output is correct
5 Correct 7 ms 804 KB Output is correct
6 Correct 7 ms 804 KB Output is correct
7 Correct 7 ms 860 KB Output is correct
8 Correct 7 ms 860 KB Output is correct
9 Correct 7 ms 860 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 8 ms 876 KB Output is correct
13 Correct 6 ms 940 KB Output is correct
14 Correct 6 ms 940 KB Output is correct
15 Correct 7 ms 940 KB Output is correct
16 Correct 7 ms 940 KB Output is correct
17 Correct 7 ms 940 KB Output is correct
18 Correct 10 ms 940 KB Output is correct
19 Correct 21 ms 1340 KB Output is correct
20 Correct 25 ms 1340 KB Output is correct
21 Correct 25 ms 1340 KB Output is correct
22 Correct 30 ms 1392 KB Output is correct
23 Correct 22 ms 1392 KB Output is correct
24 Correct 21 ms 1392 KB Output is correct
25 Correct 26 ms 1392 KB Output is correct
26 Correct 22 ms 1444 KB Output is correct
27 Correct 26 ms 1444 KB Output is correct
28 Correct 23 ms 1444 KB Output is correct
29 Correct 33 ms 1932 KB Output is correct
30 Correct 90 ms 3252 KB Output is correct
31 Correct 178 ms 5264 KB Output is correct
32 Correct 176 ms 5296 KB Output is correct
33 Correct 186 ms 5312 KB Output is correct
34 Correct 171 ms 5436 KB Output is correct
35 Correct 179 ms 5436 KB Output is correct
36 Correct 182 ms 5436 KB Output is correct
37 Correct 177 ms 5436 KB Output is correct
38 Correct 141 ms 5436 KB Output is correct
39 Correct 136 ms 5436 KB Output is correct
40 Correct 137 ms 5436 KB Output is correct
41 Correct 159 ms 5436 KB Output is correct
42 Correct 138 ms 5436 KB Output is correct
43 Correct 153 ms 5436 KB Output is correct
44 Correct 142 ms 5436 KB Output is correct
45 Correct 124 ms 5436 KB Output is correct
46 Correct 122 ms 5436 KB Output is correct
47 Correct 724 ms 16984 KB Output is correct
48 Correct 2615 ms 52852 KB Output is correct
49 Correct 2965 ms 67412 KB Output is correct
50 Correct 2925 ms 80440 KB Output is correct
51 Correct 3018 ms 93156 KB Output is correct
52 Correct 3009 ms 106164 KB Output is correct
53 Correct 2947 ms 119084 KB Output is correct
54 Correct 2776 ms 131992 KB Output is correct
55 Correct 2770 ms 145056 KB Output is correct
56 Correct 2619 ms 149304 KB Output is correct
57 Correct 2859 ms 149304 KB Output is correct
58 Correct 2624 ms 149304 KB Output is correct
59 Correct 2600 ms 149304 KB Output is correct
60 Correct 2440 ms 149304 KB Output is correct
61 Correct 2551 ms 149328 KB Output is correct
62 Correct 2517 ms 149328 KB Output is correct
63 Correct 2382 ms 149432 KB Output is correct
64 Correct 2469 ms 149432 KB Output is correct
65 Correct 2284 ms 149432 KB Output is correct
66 Correct 2359 ms 149432 KB Output is correct
67 Correct 2465 ms 149432 KB Output is correct