#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);
for(int i=0;i<n;i++){
update(s_p+A[i], -1);
}
}
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 |
Runtime error |
61 ms |
133812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
133812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4528 ms |
66688 KB |
Output is correct |
2 |
Execution timed out |
9035 ms |
67288 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
133812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |