답안 #835224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835224 2023-08-23T10:39:35 Z jmyszka2007 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1702 ms 65336 KB
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
//#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x) 
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
constexpr int base = (1 << 20);
int tri[2 * base];
int lazy[2 * base];
int nr[2 * base];
int nr2[2 * base];
void spl(int v) {
	tri[2 * v] += lazy[v];
	tri[2 * v + 1] += lazy[v];
	lazy[2 * v] += lazy[v];
	lazy[2 * v + 1] += lazy[v];
	lazy[v] = 0;
}
void upd(int v, int l, int r, int a, int b, int x) {
	if(b < l || r < a) {
		return;
	}
	if(a <= l && r <= b) {
		tri[v] += x;
		lazy[v] += x;
		return;
	}
	spl(v);
	int mid = (l + r) / 2;
	upd(2 * v, l, mid, a, b, x);
	upd(2 * v + 1, mid + 1, r, a, b, x);
	tri[v] = max(tri[2 * v], tri[2 * v + 1]);
}
int que(int v, int l, int r, int a, int b) {
	if(b < l || r < a) {
		return 0;
	}
	if(a <= l && r <= b) {
		return tri[v];
	}
	spl(v);
	int mid = (l + r) / 2;
	int ans = 0;
	ans = max(ans, que(2 * v, l, mid, a, b));
	ans = max(ans, que(2 * v + 1, mid + 1, r, a, b));
	tri[v] = max(tri[2 * v], tri[2 * v + 1]);
	return ans;
}
vi countScans(vi tab, vi zaps1, vi zaps2) {
	//ifstream cin("nazwa.in");
	//ofstream cout("nazwa.out");
	int n, t;
	n = sz(tab), t = sz(zaps1);
	vector<tuple<int, int, int> >evs;
	for(int i = 0; i < n; i++) {
		int x;
		x = tab[i];
		evs.eb(x, i, 0);
	}
	vector<pi>zap;
	for(int i = 1; i <= t; i++) {
		int a, b;
		a = zaps1[i - 1], b = zaps2[i - 1];
		evs.eb(b, a, i);
		zap.eb(a, b);
	}
	sort(all(evs));
	debug(evs);
	for(int i = 0; i < 2 * base; i++) {
		tri[i] = -1e9;
	}
	int k = 0;
	for(auto [a, b, i] : evs) {
		if(i) {
			nr[i] = k++;
		}
		else {
			nr2[b] = k++;
		}
	}
	vi pop(n);
	vi val(n);
	for(int i = 0; i < n; i++) {
		val[i] = 1e9 + i;
		upd(1, 0, base - 1, nr2[i], nr2[i], val[i]);
		upd(1, 0, base - 1, nr2[i] + 1, k, -1);
		debug(nr2[i], nr2[i]);
		pop[i] = nr2[i];
	}
	vi res;
	for(int i = 1; i <= t; i++) {
		auto [a, b] = zap[i - 1];
		upd(1, 0, base - 1, pop[a], pop[a], -val[a]);
		upd(1, 0, base - 1, pop[a] + 1, k, 1);
		pop[a] = nr[i];
		upd(1, 0, base - 1, pop[a], pop[a], val[a]);
		upd(1, 0, base - 1, pop[a] + 1, k, -1);
		res.eb(que(1, 0, base - 1, 0, k));
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 6 ms 8660 KB Output is correct
3 Correct 8 ms 8744 KB Output is correct
4 Correct 8 ms 8788 KB Output is correct
5 Correct 8 ms 8804 KB Output is correct
6 Correct 8 ms 8812 KB Output is correct
7 Correct 8 ms 8788 KB Output is correct
8 Correct 11 ms 8788 KB Output is correct
9 Correct 8 ms 8772 KB Output is correct
10 Correct 8 ms 8788 KB Output is correct
11 Correct 8 ms 8788 KB Output is correct
12 Correct 8 ms 8768 KB Output is correct
13 Correct 8 ms 8788 KB Output is correct
14 Correct 8 ms 8808 KB Output is correct
15 Correct 9 ms 8776 KB Output is correct
16 Correct 8 ms 8788 KB Output is correct
17 Correct 8 ms 8768 KB Output is correct
18 Correct 8 ms 8804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 6 ms 8660 KB Output is correct
3 Correct 8 ms 8744 KB Output is correct
4 Correct 8 ms 8788 KB Output is correct
5 Correct 8 ms 8804 KB Output is correct
6 Correct 8 ms 8812 KB Output is correct
7 Correct 8 ms 8788 KB Output is correct
8 Correct 11 ms 8788 KB Output is correct
9 Correct 8 ms 8772 KB Output is correct
10 Correct 8 ms 8788 KB Output is correct
11 Correct 8 ms 8788 KB Output is correct
12 Correct 8 ms 8768 KB Output is correct
13 Correct 8 ms 8788 KB Output is correct
14 Correct 8 ms 8808 KB Output is correct
15 Correct 9 ms 8776 KB Output is correct
16 Correct 8 ms 8788 KB Output is correct
17 Correct 8 ms 8768 KB Output is correct
18 Correct 8 ms 8804 KB Output is correct
19 Correct 19 ms 9420 KB Output is correct
20 Correct 23 ms 9508 KB Output is correct
21 Correct 22 ms 9496 KB Output is correct
22 Correct 22 ms 9508 KB Output is correct
23 Correct 22 ms 9472 KB Output is correct
24 Correct 22 ms 9492 KB Output is correct
25 Correct 30 ms 9472 KB Output is correct
26 Correct 22 ms 9496 KB Output is correct
27 Correct 22 ms 9456 KB Output is correct
28 Correct 21 ms 9496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 9900 KB Output is correct
2 Correct 75 ms 11844 KB Output is correct
3 Correct 129 ms 13920 KB Output is correct
4 Correct 139 ms 13972 KB Output is correct
5 Correct 129 ms 13948 KB Output is correct
6 Correct 127 ms 13932 KB Output is correct
7 Correct 126 ms 13940 KB Output is correct
8 Correct 128 ms 13876 KB Output is correct
9 Correct 135 ms 13880 KB Output is correct
10 Correct 128 ms 14016 KB Output is correct
11 Correct 126 ms 13976 KB Output is correct
12 Correct 122 ms 13956 KB Output is correct
13 Correct 128 ms 14172 KB Output is correct
14 Correct 126 ms 13936 KB Output is correct
15 Correct 122 ms 14016 KB Output is correct
16 Correct 125 ms 14040 KB Output is correct
17 Correct 121 ms 14008 KB Output is correct
18 Correct 120 ms 13924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 6 ms 8660 KB Output is correct
3 Correct 8 ms 8744 KB Output is correct
4 Correct 8 ms 8788 KB Output is correct
5 Correct 8 ms 8804 KB Output is correct
6 Correct 8 ms 8812 KB Output is correct
7 Correct 8 ms 8788 KB Output is correct
8 Correct 11 ms 8788 KB Output is correct
9 Correct 8 ms 8772 KB Output is correct
10 Correct 8 ms 8788 KB Output is correct
11 Correct 8 ms 8788 KB Output is correct
12 Correct 8 ms 8768 KB Output is correct
13 Correct 8 ms 8788 KB Output is correct
14 Correct 8 ms 8808 KB Output is correct
15 Correct 9 ms 8776 KB Output is correct
16 Correct 8 ms 8788 KB Output is correct
17 Correct 8 ms 8768 KB Output is correct
18 Correct 8 ms 8804 KB Output is correct
19 Correct 19 ms 9420 KB Output is correct
20 Correct 23 ms 9508 KB Output is correct
21 Correct 22 ms 9496 KB Output is correct
22 Correct 22 ms 9508 KB Output is correct
23 Correct 22 ms 9472 KB Output is correct
24 Correct 22 ms 9492 KB Output is correct
25 Correct 30 ms 9472 KB Output is correct
26 Correct 22 ms 9496 KB Output is correct
27 Correct 22 ms 9456 KB Output is correct
28 Correct 21 ms 9496 KB Output is correct
29 Correct 27 ms 9900 KB Output is correct
30 Correct 75 ms 11844 KB Output is correct
31 Correct 129 ms 13920 KB Output is correct
32 Correct 139 ms 13972 KB Output is correct
33 Correct 129 ms 13948 KB Output is correct
34 Correct 127 ms 13932 KB Output is correct
35 Correct 126 ms 13940 KB Output is correct
36 Correct 128 ms 13876 KB Output is correct
37 Correct 135 ms 13880 KB Output is correct
38 Correct 128 ms 14016 KB Output is correct
39 Correct 126 ms 13976 KB Output is correct
40 Correct 122 ms 13956 KB Output is correct
41 Correct 128 ms 14172 KB Output is correct
42 Correct 126 ms 13936 KB Output is correct
43 Correct 122 ms 14016 KB Output is correct
44 Correct 125 ms 14040 KB Output is correct
45 Correct 121 ms 14008 KB Output is correct
46 Correct 120 ms 13924 KB Output is correct
47 Correct 469 ms 26780 KB Output is correct
48 Correct 1702 ms 61752 KB Output is correct
49 Correct 1651 ms 65336 KB Output is correct
50 Correct 1630 ms 65244 KB Output is correct
51 Correct 1598 ms 65176 KB Output is correct
52 Correct 1616 ms 65264 KB Output is correct
53 Correct 1636 ms 65268 KB Output is correct
54 Correct 1598 ms 65172 KB Output is correct
55 Correct 1582 ms 65224 KB Output is correct
56 Correct 1562 ms 65196 KB Output is correct
57 Correct 1658 ms 65220 KB Output is correct
58 Correct 1541 ms 65248 KB Output is correct
59 Correct 1511 ms 65296 KB Output is correct
60 Correct 1483 ms 65168 KB Output is correct
61 Correct 1489 ms 65260 KB Output is correct
62 Correct 1430 ms 65176 KB Output is correct
63 Correct 1456 ms 65264 KB Output is correct
64 Correct 1487 ms 65236 KB Output is correct
65 Correct 1425 ms 65228 KB Output is correct
66 Correct 1413 ms 65228 KB Output is correct
67 Correct 1449 ms 65260 KB Output is correct