Submission #1329537

#TimeUsernameProblemLanguageResultExecution timeMemory
1329537namiousBubble Sort 2 (JOI18_bubblesort2)C++20
38 / 100
9092 ms2000 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lc (id*2)
#define rc (id*2+1)
#define mid (r+l)/2
#define pb push_back
#define pii pair<int,int>
#pragma GCC optimize("O3,unroll-loops")
#define fast_io ios_base::sync_with_stdio(0) ,cin.tie(0),cout.tie(0);

vector <int> countScans(vector<int> A , vector<int> X , vector<int> V){
	int n = A.size(); int q = X.size(); vector <int> output;
	vector <int> inv; for(int i = 0 ; i < n ; i++) inv.pb(0);
	for(int i = 1 ; i < n ; i++){
		for(int j = 0 ; j < i ; j++){
			if(A[j] > A[i]) inv[i]++;
		}
	}
	for(int i = 0 ; i < q ; i++){
		for(int j = X[i]+1 ; j < n ; j++) if(A[X[i]] > A[j]) inv[j]--;
		A[X[i]] = V[i]; inv[X[i]] = 0;
		for(int j = X[i]+1 ; j < n ; j++) if(A[X[i]] > A[j]) inv[j]++;
		for(int j = 0 ; j < X[i] ; j++) if(A[j] > A[X[i]]) inv[X[i]]++;
		int ans = 0; for(int j = 0 ; j < n ; j++) ans = max(ans,inv[j]);
		output.pb(ans);
	}
	return output;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...