#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std ;
const int N = 2e5 + 7 ;
int n;
int tree[N * 4] , lazy[N * 4] ;
void update(int node , int L , int R , int l , int r , int val){
if(l > R || r < L || l > r)
return ;
if(L>=l && R<=r){
lazy[node] += val ;
return ;
}
int mid = (L + R) >>1 ;
update(node*2+1 , L , mid , l , r , val) ;
update(node*2+2 , mid+1 , R , l , r, val) ;
tree[node] = min(tree[node *2 +1] + lazy[node*2+1] , tree[node*2+2] + lazy[node *2+2] );
}
int query(int node , int L , int R , int l , int r ){
if(l > R || r < L || l > r)
return 1e8 ;
if(L>=l && R<=r)
return tree[node] + lazy[node];
int mid = (L+R) >> 1 ;
int s1 = query(node*2+1 , L , mid , l , r) ;
int s2 = query(node*2+2 , mid+1 , R , l , r ) ;
return min(s1 , s2) + lazy[node] ;
}
void add(int ix , int val){
}
void del(int ix , int val){
}
map<int , int > com ;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int Q=X.size();
n = (int) A.size() ;
std::vector<int> answer(Q);
vector<int> aux ;
for(auto u : A)
aux.push_back(u) ;
for(auto u : V)
aux.push_back(u) ;
sort(aux.begin() , aux.end()) ;
int l = 0 , now = 0 ;
for(int i = 0 ;i < (int) aux.size() ;i++){
if(aux[i] > l)
now ++ ;
com[aux[i]] = now ;
l = aux[i] ;
}
for(int i = 0 ; i < n; i++){
A[i] = com[A[i]] ;
}
for(int i = 0 ;i < Q ;i++){
V[i] = com[V[i]] ;
}
for(int i = 0 ; i < n; i++){
update( 0 , 1 , N , A[i] +1 , N , 1) ;
}
for (int j=0;j<Q;j++) {
if(V[j] >=A[X[j]]){
update( 0 , 1 , N , A[X[j]] +1 , V[j] , -1) ;
}
else{
update( 0 , 1 ,N , V[j] +1 , A[X[j]] , 1) ;
}
A[ X[j] ] = V[ j ] ;
for(int i = 0 ;i < n;i++){
int k = 0 ;
answer[j] = max(answer[j] , i - query(0 , 1 , N , A[i] , A[i] ) ) ;
}
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:95:29: warning: unused variable 'k' [-Wunused-variable]
int k = 0 ;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
572 KB |
Output is correct |
2 |
Correct |
133 ms |
512 KB |
Output is correct |
3 |
Correct |
788 ms |
888 KB |
Output is correct |
4 |
Correct |
755 ms |
888 KB |
Output is correct |
5 |
Correct |
743 ms |
888 KB |
Output is correct |
6 |
Correct |
674 ms |
888 KB |
Output is correct |
7 |
Correct |
704 ms |
888 KB |
Output is correct |
8 |
Correct |
728 ms |
768 KB |
Output is correct |
9 |
Correct |
736 ms |
816 KB |
Output is correct |
10 |
Correct |
691 ms |
888 KB |
Output is correct |
11 |
Correct |
694 ms |
768 KB |
Output is correct |
12 |
Correct |
682 ms |
768 KB |
Output is correct |
13 |
Correct |
686 ms |
760 KB |
Output is correct |
14 |
Correct |
668 ms |
760 KB |
Output is correct |
15 |
Correct |
699 ms |
760 KB |
Output is correct |
16 |
Correct |
662 ms |
740 KB |
Output is correct |
17 |
Correct |
670 ms |
888 KB |
Output is correct |
18 |
Correct |
651 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
572 KB |
Output is correct |
2 |
Correct |
133 ms |
512 KB |
Output is correct |
3 |
Correct |
788 ms |
888 KB |
Output is correct |
4 |
Correct |
755 ms |
888 KB |
Output is correct |
5 |
Correct |
743 ms |
888 KB |
Output is correct |
6 |
Correct |
674 ms |
888 KB |
Output is correct |
7 |
Correct |
704 ms |
888 KB |
Output is correct |
8 |
Correct |
728 ms |
768 KB |
Output is correct |
9 |
Correct |
736 ms |
816 KB |
Output is correct |
10 |
Correct |
691 ms |
888 KB |
Output is correct |
11 |
Correct |
694 ms |
768 KB |
Output is correct |
12 |
Correct |
682 ms |
768 KB |
Output is correct |
13 |
Correct |
686 ms |
760 KB |
Output is correct |
14 |
Correct |
668 ms |
760 KB |
Output is correct |
15 |
Correct |
699 ms |
760 KB |
Output is correct |
16 |
Correct |
662 ms |
740 KB |
Output is correct |
17 |
Correct |
670 ms |
888 KB |
Output is correct |
18 |
Correct |
651 ms |
768 KB |
Output is correct |
19 |
Execution timed out |
9088 ms |
1664 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9084 ms |
896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
572 KB |
Output is correct |
2 |
Correct |
133 ms |
512 KB |
Output is correct |
3 |
Correct |
788 ms |
888 KB |
Output is correct |
4 |
Correct |
755 ms |
888 KB |
Output is correct |
5 |
Correct |
743 ms |
888 KB |
Output is correct |
6 |
Correct |
674 ms |
888 KB |
Output is correct |
7 |
Correct |
704 ms |
888 KB |
Output is correct |
8 |
Correct |
728 ms |
768 KB |
Output is correct |
9 |
Correct |
736 ms |
816 KB |
Output is correct |
10 |
Correct |
691 ms |
888 KB |
Output is correct |
11 |
Correct |
694 ms |
768 KB |
Output is correct |
12 |
Correct |
682 ms |
768 KB |
Output is correct |
13 |
Correct |
686 ms |
760 KB |
Output is correct |
14 |
Correct |
668 ms |
760 KB |
Output is correct |
15 |
Correct |
699 ms |
760 KB |
Output is correct |
16 |
Correct |
662 ms |
740 KB |
Output is correct |
17 |
Correct |
670 ms |
888 KB |
Output is correct |
18 |
Correct |
651 ms |
768 KB |
Output is correct |
19 |
Execution timed out |
9088 ms |
1664 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |