답안 #813205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813205 2023-08-07T14:16:01 Z SlavicG Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1927 ms 176688 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
const ll inf = 1e9;
const int N = 4e6 + 5;
ll t[4 * N], lazy[4 * N];
void push(int i, int l, int r) {
	if(!lazy[i]) return;
	t[i] += lazy[i];
	if(l != r) {
		lazy[2 * i] += lazy[i];
		lazy[2 * i + 1] += lazy[i];
	}
	lazy[i] = 0;
}
void modif(int i, int l, int r, int tl, int tr, ll val) {
	push(i, l, r);
	if(l > tr || r < tl) return;
	if(l >= tl && r <= tr) {
		lazy[i] += val;
		push(i, l,r);
		return;
	}
	int mid = l + r >> 1;
	modif(2 * i, l, mid, tl, tr, val);
	modif(2 * i + 1, mid + 1, r, tl, tr, val);
	t[i] = max(t[2 * i], t[2 * i + 1]);
}
std::vector<int> countScans(vector<int> a, vector<int> X, vector<int> V){
	int n = a.size();
	int q = X.size();
	vector<int> ans(q);
	//compresam coordonatele si ne asiguram sa nu avem duplicate
	vector<ll> vals;
	for(int i = 0; i < n; ++i) {
		vals.push_back(inf * (ll)a[i] + i); 
	}
	for(int k = 0; k < q; ++k) {
		int i = X[k];
		ll newval = inf * V[k] + i;
		vals.push_back(newval);
	}
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());
	for(int i = 0; i < n; ++i) {
		a[i] = lower_bound(vals.begin(), vals.end(), (ll)a[i] * (ll)inf + i) - vals.begin();
	}
	for(int k = 0; k < q; ++k) {
		int i = X[k];
		ll newval = inf * (ll)V[k] + i;
		V[k] = lower_bound(vals.begin(), vals.end(), newval) - vals.begin();
	}
 
 
	//acum rezolvam problema dupa ce am compresat tot
	for(int i = 0; i < 4 * N; ++i) t[i] = -inf;
 
	for(int i = 0; i < n; ++i) {
		modif(1, 0, N - 1, a[i], a[i], inf + i);
	}
	for(int i = 0; i < n; ++i) {
		modif(1, 0, N - 1, a[i] + 1, N - 1, -1);
	}
	for(int k = 0; k < q; ++k) {
		int i = X[k], newval = V[k];
		modif(1, 0, N - 1, a[i] + 1, N - 1, +1);
		modif(1, 0, N - 1, a[i], a[i], -inf - i);
		a[i] = newval;
		modif(1, 0, N - 1, a[i], a[i], inf + i);
		modif(1, 0, N - 1, a[i] + 1, N - 1, -1);
		push(1, 0, N - 1);
		ans[k] = (int)max(0LL, t[1]); 
	}
 
 
	return ans;
}
/*
4 2
1 2 3 4
0 3
2 1
*/

Compilation message

bubblesort2.cpp: In function 'void modif(int, int, int, int, int, long long int)':
bubblesort2.cpp:27:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |  int mid = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 125616 KB Output is correct
2 Correct 45 ms 125636 KB Output is correct
3 Correct 56 ms 125760 KB Output is correct
4 Correct 60 ms 125728 KB Output is correct
5 Correct 48 ms 125784 KB Output is correct
6 Correct 48 ms 125688 KB Output is correct
7 Correct 49 ms 125748 KB Output is correct
8 Correct 49 ms 125684 KB Output is correct
9 Correct 54 ms 125896 KB Output is correct
10 Correct 48 ms 125736 KB Output is correct
11 Correct 49 ms 125688 KB Output is correct
12 Correct 50 ms 125708 KB Output is correct
13 Correct 50 ms 125676 KB Output is correct
14 Correct 49 ms 125784 KB Output is correct
15 Correct 48 ms 125748 KB Output is correct
16 Correct 49 ms 125744 KB Output is correct
17 Correct 49 ms 125720 KB Output is correct
18 Correct 49 ms 125728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 125616 KB Output is correct
2 Correct 45 ms 125636 KB Output is correct
3 Correct 56 ms 125760 KB Output is correct
4 Correct 60 ms 125728 KB Output is correct
5 Correct 48 ms 125784 KB Output is correct
6 Correct 48 ms 125688 KB Output is correct
7 Correct 49 ms 125748 KB Output is correct
8 Correct 49 ms 125684 KB Output is correct
9 Correct 54 ms 125896 KB Output is correct
10 Correct 48 ms 125736 KB Output is correct
11 Correct 49 ms 125688 KB Output is correct
12 Correct 50 ms 125708 KB Output is correct
13 Correct 50 ms 125676 KB Output is correct
14 Correct 49 ms 125784 KB Output is correct
15 Correct 48 ms 125748 KB Output is correct
16 Correct 49 ms 125744 KB Output is correct
17 Correct 49 ms 125720 KB Output is correct
18 Correct 49 ms 125728 KB Output is correct
19 Correct 59 ms 126204 KB Output is correct
20 Correct 63 ms 126264 KB Output is correct
21 Correct 62 ms 126320 KB Output is correct
22 Correct 62 ms 126284 KB Output is correct
23 Correct 73 ms 126300 KB Output is correct
24 Correct 62 ms 126192 KB Output is correct
25 Correct 61 ms 126284 KB Output is correct
26 Correct 61 ms 126200 KB Output is correct
27 Correct 62 ms 126240 KB Output is correct
28 Correct 61 ms 126220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 126600 KB Output is correct
2 Correct 112 ms 128068 KB Output is correct
3 Correct 161 ms 129436 KB Output is correct
4 Correct 163 ms 129472 KB Output is correct
5 Correct 172 ms 129516 KB Output is correct
6 Correct 165 ms 129472 KB Output is correct
7 Correct 161 ms 129448 KB Output is correct
8 Correct 161 ms 129412 KB Output is correct
9 Correct 172 ms 129484 KB Output is correct
10 Correct 145 ms 128676 KB Output is correct
11 Correct 148 ms 129344 KB Output is correct
12 Correct 143 ms 129340 KB Output is correct
13 Correct 146 ms 129364 KB Output is correct
14 Correct 155 ms 129384 KB Output is correct
15 Correct 183 ms 129344 KB Output is correct
16 Correct 149 ms 129360 KB Output is correct
17 Correct 148 ms 129432 KB Output is correct
18 Correct 155 ms 129340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 125616 KB Output is correct
2 Correct 45 ms 125636 KB Output is correct
3 Correct 56 ms 125760 KB Output is correct
4 Correct 60 ms 125728 KB Output is correct
5 Correct 48 ms 125784 KB Output is correct
6 Correct 48 ms 125688 KB Output is correct
7 Correct 49 ms 125748 KB Output is correct
8 Correct 49 ms 125684 KB Output is correct
9 Correct 54 ms 125896 KB Output is correct
10 Correct 48 ms 125736 KB Output is correct
11 Correct 49 ms 125688 KB Output is correct
12 Correct 50 ms 125708 KB Output is correct
13 Correct 50 ms 125676 KB Output is correct
14 Correct 49 ms 125784 KB Output is correct
15 Correct 48 ms 125748 KB Output is correct
16 Correct 49 ms 125744 KB Output is correct
17 Correct 49 ms 125720 KB Output is correct
18 Correct 49 ms 125728 KB Output is correct
19 Correct 59 ms 126204 KB Output is correct
20 Correct 63 ms 126264 KB Output is correct
21 Correct 62 ms 126320 KB Output is correct
22 Correct 62 ms 126284 KB Output is correct
23 Correct 73 ms 126300 KB Output is correct
24 Correct 62 ms 126192 KB Output is correct
25 Correct 61 ms 126284 KB Output is correct
26 Correct 61 ms 126200 KB Output is correct
27 Correct 62 ms 126240 KB Output is correct
28 Correct 61 ms 126220 KB Output is correct
29 Correct 72 ms 126600 KB Output is correct
30 Correct 112 ms 128068 KB Output is correct
31 Correct 161 ms 129436 KB Output is correct
32 Correct 163 ms 129472 KB Output is correct
33 Correct 172 ms 129516 KB Output is correct
34 Correct 165 ms 129472 KB Output is correct
35 Correct 161 ms 129448 KB Output is correct
36 Correct 161 ms 129412 KB Output is correct
37 Correct 172 ms 129484 KB Output is correct
38 Correct 145 ms 128676 KB Output is correct
39 Correct 148 ms 129344 KB Output is correct
40 Correct 143 ms 129340 KB Output is correct
41 Correct 146 ms 129364 KB Output is correct
42 Correct 155 ms 129384 KB Output is correct
43 Correct 183 ms 129344 KB Output is correct
44 Correct 149 ms 129360 KB Output is correct
45 Correct 148 ms 129432 KB Output is correct
46 Correct 155 ms 129340 KB Output is correct
47 Correct 514 ms 140600 KB Output is correct
48 Correct 1771 ms 172496 KB Output is correct
49 Correct 1927 ms 176556 KB Output is correct
50 Correct 1862 ms 176580 KB Output is correct
51 Correct 1799 ms 176556 KB Output is correct
52 Correct 1855 ms 176564 KB Output is correct
53 Correct 1818 ms 176524 KB Output is correct
54 Correct 1666 ms 176676 KB Output is correct
55 Correct 1735 ms 176676 KB Output is correct
56 Correct 1671 ms 176684 KB Output is correct
57 Correct 1692 ms 176688 KB Output is correct
58 Correct 1624 ms 176652 KB Output is correct
59 Correct 1524 ms 173312 KB Output is correct
60 Correct 1568 ms 173284 KB Output is correct
61 Correct 1683 ms 173340 KB Output is correct
62 Correct 1552 ms 172152 KB Output is correct
63 Correct 1465 ms 172192 KB Output is correct
64 Correct 1754 ms 172144 KB Output is correct
65 Correct 1368 ms 171000 KB Output is correct
66 Correct 1457 ms 170924 KB Output is correct
67 Correct 1376 ms 170976 KB Output is correct