#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++;
}
// for(int i = 1; i <= n; i ++) cerr << a[i] << " ";
// cerr << " " << cnt << " x\n";
ans.push_back(cnt);
}
return ans;
}
}
namespace sub2{
int affect[N];
vector<int> solve(){
vector<int> ans;
for(int i = 1; i < n; i ++){
for(int j = i + 1; j <= n; j ++){
affect[j] += (a[i] > a[j]);
}
}
for(int k = 1; k <= q; k ++){
int x = _x[k], y = _y[k];
int cnt = 0;
for(int i = x + 1; i <= n; i ++) if(a[x] > a[i]) affect[i]--;
a[x] = y;
affect[x] = 0;
for(int i = 1; i < x; i ++) if(a[i] > a[x]) affect[x]++;
for(int i = x + 1; i <= n; i ++) if(a[x] > a[i]) affect[i]++;
int mx = 0;
for(int i = 1; i <= n; i ++) mx = max(mx, affect[i]);
ans.push_back(mx);
}
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 sub2 :: solve();
// 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
bubblesort2.cpp: In function 'std::vector<int> sub2::solve()':
bubblesort2.cpp:47:11: warning: unused variable 'cnt' [-Wunused-variable]
47 | int cnt = 0;
| ^~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:76:7: warning: unused variable 'ans' [-Wunused-variable]
76 | int ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
4 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6736 KB |
Output is correct |
4 |
Correct |
19 ms |
6480 KB |
Output is correct |
5 |
Correct |
16 ms |
6480 KB |
Output is correct |
6 |
Correct |
12 ms |
6480 KB |
Output is correct |
7 |
Correct |
13 ms |
6480 KB |
Output is correct |
8 |
Correct |
14 ms |
6716 KB |
Output is correct |
9 |
Correct |
16 ms |
6652 KB |
Output is correct |
10 |
Correct |
12 ms |
6704 KB |
Output is correct |
11 |
Correct |
12 ms |
6696 KB |
Output is correct |
12 |
Correct |
13 ms |
6648 KB |
Output is correct |
13 |
Correct |
13 ms |
6480 KB |
Output is correct |
14 |
Correct |
12 ms |
6648 KB |
Output is correct |
15 |
Correct |
11 ms |
6712 KB |
Output is correct |
16 |
Correct |
10 ms |
6480 KB |
Output is correct |
17 |
Correct |
10 ms |
6480 KB |
Output is correct |
18 |
Correct |
10 ms |
6712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
4 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6736 KB |
Output is correct |
4 |
Correct |
19 ms |
6480 KB |
Output is correct |
5 |
Correct |
16 ms |
6480 KB |
Output is correct |
6 |
Correct |
12 ms |
6480 KB |
Output is correct |
7 |
Correct |
13 ms |
6480 KB |
Output is correct |
8 |
Correct |
14 ms |
6716 KB |
Output is correct |
9 |
Correct |
16 ms |
6652 KB |
Output is correct |
10 |
Correct |
12 ms |
6704 KB |
Output is correct |
11 |
Correct |
12 ms |
6696 KB |
Output is correct |
12 |
Correct |
13 ms |
6648 KB |
Output is correct |
13 |
Correct |
13 ms |
6480 KB |
Output is correct |
14 |
Correct |
12 ms |
6648 KB |
Output is correct |
15 |
Correct |
11 ms |
6712 KB |
Output is correct |
16 |
Correct |
10 ms |
6480 KB |
Output is correct |
17 |
Correct |
10 ms |
6480 KB |
Output is correct |
18 |
Correct |
10 ms |
6712 KB |
Output is correct |
19 |
Correct |
234 ms |
6952 KB |
Output is correct |
20 |
Correct |
302 ms |
6992 KB |
Output is correct |
21 |
Correct |
201 ms |
6992 KB |
Output is correct |
22 |
Correct |
242 ms |
7012 KB |
Output is correct |
23 |
Correct |
180 ms |
6988 KB |
Output is correct |
24 |
Correct |
180 ms |
6976 KB |
Output is correct |
25 |
Correct |
162 ms |
6988 KB |
Output is correct |
26 |
Correct |
159 ms |
6980 KB |
Output is correct |
27 |
Correct |
135 ms |
6984 KB |
Output is correct |
28 |
Correct |
137 ms |
6984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
7048 KB |
Output is correct |
2 |
Correct |
4963 ms |
7972 KB |
Output is correct |
3 |
Execution timed out |
9041 ms |
10772 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
4 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6736 KB |
Output is correct |
4 |
Correct |
19 ms |
6480 KB |
Output is correct |
5 |
Correct |
16 ms |
6480 KB |
Output is correct |
6 |
Correct |
12 ms |
6480 KB |
Output is correct |
7 |
Correct |
13 ms |
6480 KB |
Output is correct |
8 |
Correct |
14 ms |
6716 KB |
Output is correct |
9 |
Correct |
16 ms |
6652 KB |
Output is correct |
10 |
Correct |
12 ms |
6704 KB |
Output is correct |
11 |
Correct |
12 ms |
6696 KB |
Output is correct |
12 |
Correct |
13 ms |
6648 KB |
Output is correct |
13 |
Correct |
13 ms |
6480 KB |
Output is correct |
14 |
Correct |
12 ms |
6648 KB |
Output is correct |
15 |
Correct |
11 ms |
6712 KB |
Output is correct |
16 |
Correct |
10 ms |
6480 KB |
Output is correct |
17 |
Correct |
10 ms |
6480 KB |
Output is correct |
18 |
Correct |
10 ms |
6712 KB |
Output is correct |
19 |
Correct |
234 ms |
6952 KB |
Output is correct |
20 |
Correct |
302 ms |
6992 KB |
Output is correct |
21 |
Correct |
201 ms |
6992 KB |
Output is correct |
22 |
Correct |
242 ms |
7012 KB |
Output is correct |
23 |
Correct |
180 ms |
6988 KB |
Output is correct |
24 |
Correct |
180 ms |
6976 KB |
Output is correct |
25 |
Correct |
162 ms |
6988 KB |
Output is correct |
26 |
Correct |
159 ms |
6980 KB |
Output is correct |
27 |
Correct |
135 ms |
6984 KB |
Output is correct |
28 |
Correct |
137 ms |
6984 KB |
Output is correct |
29 |
Correct |
517 ms |
7048 KB |
Output is correct |
30 |
Correct |
4963 ms |
7972 KB |
Output is correct |
31 |
Execution timed out |
9041 ms |
10772 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |