Submission #852924

#TimeUsernameProblemLanguageResultExecution timeMemory
852924vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
39 / 100
8537 ms4180 KiB
// by me
#include "bubblesort2.h"

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()

std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
	int Q = X.size();
	int N = A.size();
	vector<int> ans(Q, 0);
	if(N <= 2000){
		for(int i = 0; i < Q; i++){
			A[X[i]] = V[i];
			auto f = A;
			while(!is_sorted(all(f))){
				ans[i]++;
				for(int i = 1; i < f.size(); i++){
					if(f[i] < f[i - 1]) swap(f[i], f[i - 1]);
				}
			}
	    }
		return ans;
	}
	vector<set<int>> f(101);
	for(int i = 0; i < N; i++){
		f[A[i]].insert(i);
	}
	for(int i = 0; i < Q; i++){
		f[A[X[i]]].erase(X[i]);
		A[X[i]] = V[i];
		f[A[X[i]]].insert(X[i]);
		int x = 0;
		for(auto &st : f){
			if(st.empty()) continue;
			x += st.size();
			int mx = *st.rbegin();
			ans[i] = max(ans[i], mx - x + 1);
		}
	}
	return ans;
}

//
/*
int readInt(){
	int i;
	if(scanf("%d",&i)!=1){
		fprintf(stderr,"Error while reading input\n");
		exit(1);
	}
	return i;
}

int main(){
	int N,Q;
	N=readInt();
	Q=readInt();

	std::vector<int> A(N);
	for(int i=0;i<N;i++)
		A[i]=readInt();

	std::vector<int> X(Q),V(Q);
	for(int j=0;j<Q;j++){
		X[j]=readInt();
		V[j]=readInt();
	}

	std::vector<int> res=countScans(A,X,V);

	for(int j=0;j<int(res.size());j++)
		printf("%d\n",res[j]);
}
//*/
// by me

Compilation message (stderr)

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 1; i < f.size(); i++){
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...