// 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();
vector<int> ans(Q, 0);
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;
}
//
/*
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
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 1; i < f.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
420 KB |
Output is correct |
2 |
Correct |
665 ms |
436 KB |
Output is correct |
3 |
Correct |
8846 ms |
476 KB |
Output is correct |
4 |
Correct |
8793 ms |
472 KB |
Output is correct |
5 |
Correct |
3957 ms |
592 KB |
Output is correct |
6 |
Correct |
673 ms |
468 KB |
Output is correct |
7 |
Correct |
1632 ms |
592 KB |
Output is correct |
8 |
Correct |
2403 ms |
472 KB |
Output is correct |
9 |
Correct |
3965 ms |
472 KB |
Output is correct |
10 |
Correct |
6716 ms |
476 KB |
Output is correct |
11 |
Correct |
6725 ms |
468 KB |
Output is correct |
12 |
Correct |
6850 ms |
476 KB |
Output is correct |
13 |
Correct |
7046 ms |
472 KB |
Output is correct |
14 |
Correct |
6671 ms |
472 KB |
Output is correct |
15 |
Correct |
6673 ms |
480 KB |
Output is correct |
16 |
Correct |
6701 ms |
472 KB |
Output is correct |
17 |
Correct |
6666 ms |
468 KB |
Output is correct |
18 |
Correct |
6664 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
420 KB |
Output is correct |
2 |
Correct |
665 ms |
436 KB |
Output is correct |
3 |
Correct |
8846 ms |
476 KB |
Output is correct |
4 |
Correct |
8793 ms |
472 KB |
Output is correct |
5 |
Correct |
3957 ms |
592 KB |
Output is correct |
6 |
Correct |
673 ms |
468 KB |
Output is correct |
7 |
Correct |
1632 ms |
592 KB |
Output is correct |
8 |
Correct |
2403 ms |
472 KB |
Output is correct |
9 |
Correct |
3965 ms |
472 KB |
Output is correct |
10 |
Correct |
6716 ms |
476 KB |
Output is correct |
11 |
Correct |
6725 ms |
468 KB |
Output is correct |
12 |
Correct |
6850 ms |
476 KB |
Output is correct |
13 |
Correct |
7046 ms |
472 KB |
Output is correct |
14 |
Correct |
6671 ms |
472 KB |
Output is correct |
15 |
Correct |
6673 ms |
480 KB |
Output is correct |
16 |
Correct |
6701 ms |
472 KB |
Output is correct |
17 |
Correct |
6666 ms |
468 KB |
Output is correct |
18 |
Correct |
6664 ms |
472 KB |
Output is correct |
19 |
Execution timed out |
9048 ms |
600 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
9027 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
420 KB |
Output is correct |
2 |
Correct |
665 ms |
436 KB |
Output is correct |
3 |
Correct |
8846 ms |
476 KB |
Output is correct |
4 |
Correct |
8793 ms |
472 KB |
Output is correct |
5 |
Correct |
3957 ms |
592 KB |
Output is correct |
6 |
Correct |
673 ms |
468 KB |
Output is correct |
7 |
Correct |
1632 ms |
592 KB |
Output is correct |
8 |
Correct |
2403 ms |
472 KB |
Output is correct |
9 |
Correct |
3965 ms |
472 KB |
Output is correct |
10 |
Correct |
6716 ms |
476 KB |
Output is correct |
11 |
Correct |
6725 ms |
468 KB |
Output is correct |
12 |
Correct |
6850 ms |
476 KB |
Output is correct |
13 |
Correct |
7046 ms |
472 KB |
Output is correct |
14 |
Correct |
6671 ms |
472 KB |
Output is correct |
15 |
Correct |
6673 ms |
480 KB |
Output is correct |
16 |
Correct |
6701 ms |
472 KB |
Output is correct |
17 |
Correct |
6666 ms |
468 KB |
Output is correct |
18 |
Correct |
6664 ms |
472 KB |
Output is correct |
19 |
Execution timed out |
9048 ms |
600 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |