Submission #1013428

# Submission time Handle Problem Language Result Execution time Memory
1013428 2024-07-03T14:20:02 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
4596 ms 1116 KB
// #include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
vector<int> v;
int n;
vector<int> countScans(vector<int> A,vector<int> x,vector<int> y){
	v=A;
	n=v.size();
	int q=x.size();
	vector<int> Ans(q);
	auto dist = [&](int x,int a,int b){
		return min(abs(x-a),abs(x-b));
	};
	for(int i=0;i<q;i++){
		vector<int> c=v;
		c[x[i]]=y[i];
		vector<int> t=c;
		sort(all(c));
		int ans=0;
		map<int,int> a,b;
		for(int i=0;i<n;i++){
			if(a.count(c[i])==0){
				a[c[i]]=i;
			}
			b[c[i]]=i;
		}
		for(int i=0;i<n;i++){
			ans=max(ans,dist(i,a[t[i]],b[t[i]]));
		}
		Ans[i]=ans;
		v=t;
	}
	return Ans;
}



#ifdef IOI
// #include "bubblesort2.h"

// #include <cstdio>
// #include <cstdlib>
// #include <vector>

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();
	
	vector<int> A(N);
	for(int i=0;i<N;i++)
		A[i]=readInt();
	
	vector<int> X(Q),V(Q);
	for(int j=0;j<Q;j++){
		X[j]=readInt();
		V[j]=readInt();
	}
	
	vector<int> res=countScans(A,X,V);
	
	for(int j=0;j<int(res.size());j++)
		printf("%d\n",res[j]);
}

#endif
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4596 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -