#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef pair<int,int> pii;
vector<int>bit(100000);
int m;
void upd(int pos,int val){
for(int i=pos;i<=m;i+=i&(-i))bit[i]+=val;
}
int query(int pos){
int res = 0;
while(pos){
res+=bit[pos];
pos-=pos&(-pos);
}
return res;
}
vector<int> countScans(vector<int> a,vector<int> x,vector<int>v){
int q=sz(x);
int n = sz(a);
vector<int> answer(q);
vector<int>b;
for(int i=0;i<n;i++)b.push_back(a[i]);
for(int i=0;i<q;i++)b.push_back(v[i]);
sort(all(b));
b.resize(unique(all(b))-b.begin());
m = sz(b);
for(int i=0;i<n;i++)a[i] = lower_bound(all(b),a[i])-b.begin()+1;
for(int i=0;i<q;i++)v[i] = lower_bound(all(b),v[i])-b.begin()+1;
for (int j=0;j<q;j++) {
for(int i=1;i<=m;i++)bit[i] = 0;
a[x[j]] = v[j];
int mx = 0;
for(int i=0;i<n;i++){
mx = max(mx,query(m)-query(a[i]));
upd(a[i],1);
}
answer[j] = mx;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
716 KB |
Output is correct |
2 |
Correct |
24 ms |
716 KB |
Output is correct |
3 |
Correct |
133 ms |
716 KB |
Output is correct |
4 |
Correct |
141 ms |
716 KB |
Output is correct |
5 |
Correct |
135 ms |
716 KB |
Output is correct |
6 |
Correct |
132 ms |
716 KB |
Output is correct |
7 |
Correct |
127 ms |
716 KB |
Output is correct |
8 |
Correct |
128 ms |
716 KB |
Output is correct |
9 |
Correct |
128 ms |
716 KB |
Output is correct |
10 |
Correct |
134 ms |
804 KB |
Output is correct |
11 |
Correct |
137 ms |
716 KB |
Output is correct |
12 |
Correct |
131 ms |
716 KB |
Output is correct |
13 |
Correct |
121 ms |
716 KB |
Output is correct |
14 |
Correct |
118 ms |
816 KB |
Output is correct |
15 |
Correct |
112 ms |
716 KB |
Output is correct |
16 |
Correct |
127 ms |
804 KB |
Output is correct |
17 |
Correct |
126 ms |
716 KB |
Output is correct |
18 |
Correct |
125 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
716 KB |
Output is correct |
2 |
Correct |
24 ms |
716 KB |
Output is correct |
3 |
Correct |
133 ms |
716 KB |
Output is correct |
4 |
Correct |
141 ms |
716 KB |
Output is correct |
5 |
Correct |
135 ms |
716 KB |
Output is correct |
6 |
Correct |
132 ms |
716 KB |
Output is correct |
7 |
Correct |
127 ms |
716 KB |
Output is correct |
8 |
Correct |
128 ms |
716 KB |
Output is correct |
9 |
Correct |
128 ms |
716 KB |
Output is correct |
10 |
Correct |
134 ms |
804 KB |
Output is correct |
11 |
Correct |
137 ms |
716 KB |
Output is correct |
12 |
Correct |
131 ms |
716 KB |
Output is correct |
13 |
Correct |
121 ms |
716 KB |
Output is correct |
14 |
Correct |
118 ms |
816 KB |
Output is correct |
15 |
Correct |
112 ms |
716 KB |
Output is correct |
16 |
Correct |
127 ms |
804 KB |
Output is correct |
17 |
Correct |
126 ms |
716 KB |
Output is correct |
18 |
Correct |
125 ms |
800 KB |
Output is correct |
19 |
Correct |
2037 ms |
1160 KB |
Output is correct |
20 |
Correct |
2380 ms |
1228 KB |
Output is correct |
21 |
Correct |
2365 ms |
1228 KB |
Output is correct |
22 |
Correct |
2382 ms |
1236 KB |
Output is correct |
23 |
Correct |
2234 ms |
1188 KB |
Output is correct |
24 |
Correct |
2283 ms |
1180 KB |
Output is correct |
25 |
Correct |
2075 ms |
1184 KB |
Output is correct |
26 |
Correct |
2027 ms |
1176 KB |
Output is correct |
27 |
Correct |
2217 ms |
1176 KB |
Output is correct |
28 |
Correct |
2194 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1325 ms |
1268 KB |
Output is correct |
2 |
Execution timed out |
9103 ms |
2248 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
716 KB |
Output is correct |
2 |
Correct |
24 ms |
716 KB |
Output is correct |
3 |
Correct |
133 ms |
716 KB |
Output is correct |
4 |
Correct |
141 ms |
716 KB |
Output is correct |
5 |
Correct |
135 ms |
716 KB |
Output is correct |
6 |
Correct |
132 ms |
716 KB |
Output is correct |
7 |
Correct |
127 ms |
716 KB |
Output is correct |
8 |
Correct |
128 ms |
716 KB |
Output is correct |
9 |
Correct |
128 ms |
716 KB |
Output is correct |
10 |
Correct |
134 ms |
804 KB |
Output is correct |
11 |
Correct |
137 ms |
716 KB |
Output is correct |
12 |
Correct |
131 ms |
716 KB |
Output is correct |
13 |
Correct |
121 ms |
716 KB |
Output is correct |
14 |
Correct |
118 ms |
816 KB |
Output is correct |
15 |
Correct |
112 ms |
716 KB |
Output is correct |
16 |
Correct |
127 ms |
804 KB |
Output is correct |
17 |
Correct |
126 ms |
716 KB |
Output is correct |
18 |
Correct |
125 ms |
800 KB |
Output is correct |
19 |
Correct |
2037 ms |
1160 KB |
Output is correct |
20 |
Correct |
2380 ms |
1228 KB |
Output is correct |
21 |
Correct |
2365 ms |
1228 KB |
Output is correct |
22 |
Correct |
2382 ms |
1236 KB |
Output is correct |
23 |
Correct |
2234 ms |
1188 KB |
Output is correct |
24 |
Correct |
2283 ms |
1180 KB |
Output is correct |
25 |
Correct |
2075 ms |
1184 KB |
Output is correct |
26 |
Correct |
2027 ms |
1176 KB |
Output is correct |
27 |
Correct |
2217 ms |
1176 KB |
Output is correct |
28 |
Correct |
2194 ms |
1220 KB |
Output is correct |
29 |
Correct |
1325 ms |
1268 KB |
Output is correct |
30 |
Execution timed out |
9103 ms |
2248 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |