void init()
{
  int i , ins , sx , sy , ans , del , tmp , k;
  
  //memset( idt , 0 , sizeof( idt ) );
  //memset( a , 0 , sizeof( a ) );

  //cin>>n>>m>>wide;
  scanf( "%d%d%d" , &n , &m , &wide );
  
  for( i = 1 ; i <= n ; ++ i )
    idt[ i ] = 0;

  for( i = 1 ; i <= n ; ++ i )
    {
      scanf( "%d" , &a[ i ] );
      bit_update( i , a[ i ] );
    }

  for( i = 1 ; i <= m ; ++ i )
    {
      scanf( "%d%d%d" , &ins , &sx , &sy );
      //cin>>ins>>sx>>sy;
      if( not ins )
        {
          bit_update( sx , sy - a[ sx ] );
          a[ sx ] = sy;
        }
      else if( ins == 1 )
        {
          bit_update( sx , a[ sy ] - a[ sx ] );
          bit_update( sy , a[ sx ] - a[ sy ] );
          tmp = a[ sx ];
          a[ sx ] = a[ sy ];
          a[ sy ] = a[ sx ];
          
        }
      else
        {
          ans = -INF;
          for( k = sy - wide + 1 ; k >= sx ; -- k )
            {
              del = getsum( k + wide - 1 ) - getsum( k - 1 );
              ans = ans > del ? ans : del;
            }
          printf( "%d\n" , ans );
          //cout<<ans<<"\n";
        }
    }
 
  return ;
}
Exemple #2
0
int inverse_by_bit(vector<int>& arr){
	vector<int> tmp(arr.begin(), arr.end());

	sort(tmp.begin(), tmp.end());
	for (int i = 0; i < tmp.size(); ++i){
		int rank = int(lower_bound(tmp.begin(), tmp.end(), arr[i]) - tmp.begin()+1);
		arr[i] = rank;
	}

	int cnt = 0;
	for (int i = arr.size()-1; i >= 0; --i){
		cnt += bit_read(arr[i] - 1);
		bit_update(arr[i], 1);
	}

	return cnt;
}
Exemple #3
0
int main() {
    int N; 
    long long K; 
    scanf("%d %lld", &N, &K);
    for(int i = 1; i <= N; i++) 
        scanf("%d", &A[i]);
    build_tree(1, N, 0);
    for(int i = 1; i <= N; ){
        if(bit_query(i, i) == 1){
          i++;
          continue;
        }
        int L = i;
        int R_L = L, R_R = N;
        while(R_L < R_R) {
          int mid = (R_L + R_R + 1)/2;
          if((mid - L) - bit_query(L, mid) <= K) {
            R_L = mid;
          }
          else {
            R_R = mid - 1;
          }
        }
        int R = R_L;
        pair it = query(1, N, 0, L, R);
        int max_val = it.first, max_ind = it.second;
        if(max_ind == i) {
          printf("%d ", A[i]);
          i++;
          continue;
        }
        printf("%d ", max_val);
        K -= (max_ind - i) - bit_query(i, max_ind);
        update(1, N, 0, max_ind, INT_MIN/2);
        bit_update(max_ind, 1);
    }
    puts("");
}
Exemple #4
0
inline void _insert(int p, int d) {
	bit_update(B, p, p*d);
	bit_update2(C, p-1, d);
}