제출 #812973

#제출 시각아이디문제언어결과실행 시간메모리
812973SlavicGBubble Sort 2 (JOI18_bubblesort2)C++17
38 / 100
9070 ms2388 KiB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;

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);
	vector<int> cnt(n, 0);
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < i; ++j) {
			if(a[j] > a[i]) ++cnt[i];
		}
	}
	for(int k = 0; k < q; ++k) {
		int i = X[k];
		for(int j = i + 1; j < n; ++j) {
			if(a[i] > a[j]) --cnt[j];
		}
		a[i] = V[k];
		for(int j = i + 1; j < n; ++j) {
			if(a[i] > a[j]) ++cnt[j];
		}
		cnt[i] = 0;
		for(int j = 0; j < i; ++j) {
			if(a[j] > a[i]) ++cnt[i];
		}
		int mx = *max_element(cnt.begin(), cnt.end());
		ans[k] = mx;
	}
	return ans;
}
/*
4 2
1 2 3 4
0 3
2 1
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...