#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int pr=23, s_p=1<<pr, e_p=(1<<(pr+1))-1;
int n;
vector<int>S_sum;
void pre(){
S_sum.clear();
S_sum.resize(1<<(pr+1));
}
void update(int ind, int c){
S_sum[ind]+=c;
while(ind/=2)
S_sum[ind]+=c;
}
int get(int id, int u, int v, int l, int r){
if(l>v || r<u)
return 0;
if(l>=u && r<=v)
return S_sum[id];
int md=(l+r)/2;
return get(id*2, u, v, l, md)+get(id*2+1, u, v, md+1, r);
}
vector<int> countScans(vector<int>A, vector<int>X, vector<int>V){
vector<int>S, All, Cur(A.size());
n=A.size();
int q=X.size();
for(int i=0;i<n;i++){
All.push_back(A[i]);
}
for(int i=0;i<q;i++){
All.push_back(V[i]);
}
sort(all(All));
int cur=1;
map<int, int>mp;
for(int i=0;i<All.size();i++){
if(i==All.size()-1 || All[i]!=All[i+1])
mp[All[i]]=cur++;
}
for(int i=0;i<n;i++){
A[i]=mp[A[i]];
}
pre();
for(int i=0;i<n;i++){
int cur=get(1, s_p+A[i]+1, e_p, s_p, e_p);
Cur[i]=cur;
update(s_p+A[i], 1);
}
for(int i=0;i<n;i++){
update(s_p+A[i], -1);
}
for(int k=0;k<q;k++){
int ind=X[k], val=V[k];
bool larger=(val>A[ind]);
int fir=min(A[ind], val), sec=max(A[ind], val);
A[ind]=val;
int mx=0, inc=0;
for(int i=0;i<ind;i++){
if(!larger){
inc+=(A[i]<=sec && A[i]>fir);
}
else{
inc-=(A[i]>fir && A[i]<=sec);
}
}
Cur[ind]+=inc;
for(int i=ind+1;i<n;i++){
if(!larger){
Cur[i]-=(A[i]<sec && A[i]>=fir);
}
else{
Cur[i]+=(A[i]>=fir && A[i]<sec);
}
}
for(int i=0;i<n;i++){
mx=max(mx, Cur[i]);
}
S.push_back(mx);
}
return S;
}
//int main(){
// ios_base::sync_with_stdio(0);cin.tie(0);
// int n, q;
// cin>>n>>q;
// vector<int>A(n), X(q), V(q);
// for(int i=0;i<n;i++){
// cin>>A[i];
// }
// for(int j=0;j<q;j++){
// cin>>X[j]>>V[j];
// }
// vector<int>Ans=countScans(A, X, V);
// for(int i=0;i<q;i++){
// cout<<Ans[i]<<endl;
// }
//}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<All.size();i++){
| ~^~~~~~~~~~~
bubblesort2.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(i==All.size()-1 || All[i]!=All[i+1])
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
66140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
66140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
66684 KB |
Output is correct |
2 |
Correct |
2168 ms |
67568 KB |
Output is correct |
3 |
Correct |
5539 ms |
69156 KB |
Output is correct |
4 |
Correct |
5586 ms |
69340 KB |
Output is correct |
5 |
Correct |
5548 ms |
69100 KB |
Output is correct |
6 |
Correct |
5547 ms |
68956 KB |
Output is correct |
7 |
Correct |
5537 ms |
69104 KB |
Output is correct |
8 |
Correct |
5624 ms |
68876 KB |
Output is correct |
9 |
Correct |
5633 ms |
69340 KB |
Output is correct |
10 |
Correct |
5450 ms |
69528 KB |
Output is correct |
11 |
Correct |
5462 ms |
68812 KB |
Output is correct |
12 |
Correct |
5473 ms |
68988 KB |
Output is correct |
13 |
Correct |
5455 ms |
68980 KB |
Output is correct |
14 |
Correct |
5422 ms |
69328 KB |
Output is correct |
15 |
Correct |
5463 ms |
68896 KB |
Output is correct |
16 |
Correct |
5428 ms |
69260 KB |
Output is correct |
17 |
Correct |
5364 ms |
68940 KB |
Output is correct |
18 |
Correct |
5498 ms |
68960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
66140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |