Submission #1013455

#TimeUsernameProblemLanguageResultExecution timeMemory
1013455vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
38 / 100
9005 ms2672 KiB
// #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((x-a),(x-b));
	};
	for(int i=0;i<q;i++){
		v[x[i]]=y[i];
		vector<int> c=v;
		vector<pair<int,int>> k;
		for(int i=0;i<n;i++){
			k.pb({v[i],i});
		}
		sort(all(k));
		int ans=0;
		for(int i=0;i<n;i++){
			ans=max(ans,k[i].S-i);
		}
		Ans[i]=ans;
	}
	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

Compilation message (stderr)

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:40:7: warning: variable 'dist' set but not used [-Wunused-but-set-variable]
   40 |  auto dist = [&](int x,int a,int b){
      |       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...