Submission #1139819

#TimeUsernameProblemLanguageResultExecution timeMemory
1139819SmuggingSpunBubble Sort 2 (JOI18_bubblesort2)C++20
38 / 100
6233 ms664 KiB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
template<class T>void maximize(T& a, T b){
	if(a < b){
		a = b;
	}
}
vector<int>countScans(vector<int>a, vector<int>x, vector<int>v){
	int n = a.size(), q = x.size();
	vector<int>ans(q, 0);
	if(n <= 2000 && q <= 2000){
		for(int _i = 0; _i < q; _i++){
			a[x[_i]] = v[_i];
			vector<int>A = a;
			while(true){
				bool swapped = false;
				for(int i = 1; i < n; i++){
					if(A[i - 1] > A[i]){
						swap(A[i - 1], A[i]);
						swapped = true;
					}
				}
				if(!swapped){
					break;
				}
				ans[_i]++;
			}
		}
	}
	else if(n <= 8000 && q <= 8000){
		vector<int>p(n);
		iota(p.begin(), p.end(), 0);
		for(int _i = 0; _i < q; _i++){
			a[x[_i]] = v[_i];
			sort(p.begin(), p.end(), [&] (int i, int j) -> bool{
				return a[i] < a[j] || (a[i] == a[j] && i < j);	
			});
			for(int i = 0; i < n; i++){
				maximize(ans[_i], p[i] - i);
			}
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...