Submission #1264266

#TimeUsernameProblemLanguageResultExecution timeMemory
1264266tminhBubble Sort 2 (JOI18_bubblesort2)C++20
100 / 100
1103 ms38400 KiB
#include "bits/stdc++.h"
#include "bubblesort2.h"
using namespace std;

#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>


#define ep emplace_back
#define pb push_back
#define pf push_front


const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;
const int base = 19;




struct ST {
	int st[N << 2], data[N << 2];
	void update(int id, int l, int r, int u, int v, int val) {
		if (l > v || r < u) return;
		if (l >= u && r <= v) {
			st[id] += val;
			data[id] += val;
			return;
		}
		int mid = (l + r) >> 1;
		update(id << 1, l, mid, u, v, val);
		update(id << 1 | 1, mid + 1, r, u, v, val);
		st[id] = max(st[id << 1], st[id << 1 | 1]) + data[id];
	}
} st;
vector<pii> arr;
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	int n = sze(A);
	for (int i = 0; i < n; ++i) arr.pb(make_pair(A[i], i));
	int q = sze(X);
	for (int i = 0; i < q; ++i) arr.pb(make_pair(V[i], X[i]));
	sort(vall(arr));
	arr.erase(unique(vall(arr)), arr.end());
	
	int m = sze(arr);
	for (int i = 0; i < n; ++i) {
		int it = lower_bound(vall(arr), make_pair(A[i], i)) - arr.begin() + 1;
		st.update(1, 1, m, it, it, i);
		st.update(1, 1, m, it + 1, m, -1);
	}
	
	vector<int> answer(q);
	for (int i = 0; i < q; ++i) {
		int pos = X[i], val = V[i];
		int it = lower_bound(vall(arr), make_pair(A[pos], pos)) - arr.begin() + 1;
		st.update(1, 1, m, it, it, -pos);
		st.update(1, 1, m, it + 1, m, 1);
		
		it = lower_bound(vall(arr), make_pair(val, pos)) - arr.begin() + 1;
		
		st.update(1, 1, m, it, it, pos);
		st.update(1, 1, m, it + 1, m, -1);
		
		A[pos] = val;
		answer[i] = st.st[1];
	}

	return answer;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...