#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=5e5+5;
int dp[nx];
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int Q=X.size(), N=A.size();
for (int i=0; i<N; i++) dp[i]=0;
vector<int> answer(Q);
for (int i=0; i<N; i++) for (int j=0; j<i; j++) if (A[j]>A[i]) dp[i]++;
for (int i=0; i<Q; i++) {
int idx=X[i], vl=V[i], ans=0;
for (int j=idx+1; j<N; j++) if (A[idx]>A[j]) dp[j]--;
dp[idx]=0;
A[idx]=vl;
for (int j=0; j<idx; j++) if (A[j]>A[idx]) dp[idx]++;
for (int j=idx+1; j<N; j++) if (A[idx]>A[j]) dp[j]++;
for (int j=0; j<N; j++) ans=max(ans, dp[j]);
answer[i]=ans;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
472 KB |
Output is correct |
3 |
Correct |
26 ms |
348 KB |
Output is correct |
4 |
Correct |
26 ms |
560 KB |
Output is correct |
5 |
Correct |
21 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
556 KB |
Output is correct |
7 |
Correct |
20 ms |
692 KB |
Output is correct |
8 |
Correct |
18 ms |
348 KB |
Output is correct |
9 |
Correct |
20 ms |
348 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
536 KB |
Output is correct |
13 |
Correct |
13 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
348 KB |
Output is correct |
15 |
Correct |
13 ms |
508 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
348 KB |
Output is correct |
18 |
Correct |
12 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
472 KB |
Output is correct |
3 |
Correct |
26 ms |
348 KB |
Output is correct |
4 |
Correct |
26 ms |
560 KB |
Output is correct |
5 |
Correct |
21 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
556 KB |
Output is correct |
7 |
Correct |
20 ms |
692 KB |
Output is correct |
8 |
Correct |
18 ms |
348 KB |
Output is correct |
9 |
Correct |
20 ms |
348 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
536 KB |
Output is correct |
13 |
Correct |
13 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
348 KB |
Output is correct |
15 |
Correct |
13 ms |
508 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
348 KB |
Output is correct |
18 |
Correct |
12 ms |
544 KB |
Output is correct |
19 |
Correct |
325 ms |
604 KB |
Output is correct |
20 |
Correct |
417 ms |
856 KB |
Output is correct |
21 |
Correct |
254 ms |
860 KB |
Output is correct |
22 |
Correct |
341 ms |
1108 KB |
Output is correct |
23 |
Correct |
228 ms |
840 KB |
Output is correct |
24 |
Correct |
230 ms |
828 KB |
Output is correct |
25 |
Correct |
205 ms |
856 KB |
Output is correct |
26 |
Correct |
215 ms |
832 KB |
Output is correct |
27 |
Correct |
182 ms |
824 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1315 ms |
780 KB |
Output is correct |
2 |
Correct |
7042 ms |
1700 KB |
Output is correct |
3 |
Execution timed out |
9095 ms |
2392 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
472 KB |
Output is correct |
3 |
Correct |
26 ms |
348 KB |
Output is correct |
4 |
Correct |
26 ms |
560 KB |
Output is correct |
5 |
Correct |
21 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
556 KB |
Output is correct |
7 |
Correct |
20 ms |
692 KB |
Output is correct |
8 |
Correct |
18 ms |
348 KB |
Output is correct |
9 |
Correct |
20 ms |
348 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
536 KB |
Output is correct |
13 |
Correct |
13 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
348 KB |
Output is correct |
15 |
Correct |
13 ms |
508 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
348 KB |
Output is correct |
18 |
Correct |
12 ms |
544 KB |
Output is correct |
19 |
Correct |
325 ms |
604 KB |
Output is correct |
20 |
Correct |
417 ms |
856 KB |
Output is correct |
21 |
Correct |
254 ms |
860 KB |
Output is correct |
22 |
Correct |
341 ms |
1108 KB |
Output is correct |
23 |
Correct |
228 ms |
840 KB |
Output is correct |
24 |
Correct |
230 ms |
828 KB |
Output is correct |
25 |
Correct |
205 ms |
856 KB |
Output is correct |
26 |
Correct |
215 ms |
832 KB |
Output is correct |
27 |
Correct |
182 ms |
824 KB |
Output is correct |
28 |
Correct |
182 ms |
848 KB |
Output is correct |
29 |
Correct |
1315 ms |
780 KB |
Output is correct |
30 |
Correct |
7042 ms |
1700 KB |
Output is correct |
31 |
Execution timed out |
9095 ms |
2392 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |