This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#include "bubblesort2.h"
using namespace std;
const int N = 1e6 + 5;
int n, q, a[N], _x[N], _y[N], kq[N];
namespace sub1{
int b[N];
vector<int> solve(){
vector<int> ans;
for(int k = 1; k <= q; k ++){
int x = _x[k], y = _y[k];
a[x] = y;
int cnt = 0;
for(int i = 1; i <= n; i ++) b[i] = a[i];
while(true){
bool ff = true;
for(int i = 1; i < n; i ++) if(b[i] > b[i + 1]){
swap(b[i], b[i + 1]);
ff = false;
}
if(ff) break;
cnt++;
}
ans.push_back(cnt);
}
return ans;
}
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
n = A.size();
for(int i = 0; i < n; i ++) a[i + 1] = A[i];
q = X.size();
for(int k = 0; k < q; k ++){
_x[k + 1] = X[k] + 1, _y[k + 1] = V[k];
}
return sub1 :: solve();
int ans = 0;
std::vector<int> answer(q);
for(int j = 0; j < q; j ++) {
answer[j] = kq[j];
}
return answer;
}
//#define LOCAL
#ifdef LOCAL
int _n, _q;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> _n >> _q;
std::vector<int> A(_n);
for(int i = 0; i < _n; i ++)
cin >> A[i];
std::vector<int> X(_q),V(_q);
for(int j = 0; j < _q ; j++){
cin >> X[j] >> V[j];
}
std::vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
cout << res[j] << "\n";
}
/*
4 2
1 2 3 4
0 3
2 1
*/
#endif // LOCAL
Compilation message (stderr)
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:48:7: warning: unused variable 'ans' [-Wunused-variable]
48 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |