Skip to content

Instantly share code, notes, and snippets.

View Abreto's full-sized avatar
🔋
Charging

Abreto Abreto

🔋
Charging
View GitHub Profile

大家好,我是div.2的垫底选手,本期由我来为大家介绍一个实用的区间信息维护与查询的数据结构——二叉索引树,又名树状数组,Fenwick。

(->)

对于动态连续和查询问题。给定一个n个元素的数组A1.A2,...,An,我们想设计一种数据结构,支持以下两种操作:Add(x,d)...和Query(L,R)...,并且让Query和Add都快速完成。如果用简单的前缀和来做的话,预处理会花费O(n)的时间,这样虽然查询是O(1)的,但每次Add操作却是O(n)的,总的时间复杂度是平方级的,还是会很慢。本期要介绍的二叉索引树就可以很好地解决这个问题。

(->)

我们先来理解一下树状数组中的"树状"的意思。这是一个下标从下向上生长的数组,下标已经用二进制表示出来(0,1,2...)。注意,下标0我们丢弃不用,他不是树的一部分。

#!/bin/bash
show_help()
{
echo "Usage: ./install-ss-panel-v3-mod.sh -n <site name> -d <domain> -u <mysql user&database> -p <mysql password>"
exit 1
}
declare -i nargs=0
while getopts "n:d:u:p:" opt
@Abreto
Abreto / MappingABC2.cpp
Created January 21, 2017 17:22
Single Round Match 706
#include <vector>
#define TOMOD 1000000007
using namespace std;
typedef long long int ll;
class MappingABC2
{
public:
int countStrings(vector <int> t)
{
int i = 0; int N = t.size();
@Abreto
Abreto / a.md
Created September 21, 2016 23:59
cnss2016普及赛writeup

时间: 20160915 - 20160921 地点: 电子科技大学

Keybase proof

I hereby claim:

  • I am Abreto on github.
  • I am abreto (https://keybase.io/abreto) on keybase.
  • I have a public key whose fingerprint is 257A D45F 4F50 75E2 8504 82A0 F169 E654 C156 84C1

To claim this, I am signing this object:

@Abreto
Abreto / uva706.c
Last active August 29, 2015 14:05
UVa 706 - 液晶显示屏{LC-Display}
/* Programming Challenges 110104 - LC-Display */
#include <stdio.h>
#include <string.h>
const char cdigits[10][5][3] = {
{
{' ','-',' '},
{'|',' ','|'},
{' ',' ',' '},
{'|',' ','|'},
@Abreto
Abreto / uva10137.c
Created August 9, 2014 13:39
UVa 10137 - 旅行{The Trip}
/* Programming-challenges 110103 - The Trip . Abreto. */
#include <stdio.h>
int main(void)
{
int i = 0;
int n = 0;
while( scanf("%d", &n) != EOF )
{
@Abreto
Abreto / a-backuper-dropbox-python.md
Last active August 29, 2015 14:04
自动备份-Dropbox-python-linux

这个文件只是为了阻止access_token成为第一个文件。

@Abreto
Abreto / gist:7291649
Last active December 27, 2015 07:49
Wikioi Problem 1004
/* Wikioi - Problem 1004. */
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define QUEUE_MAXSIZE 65535
#define QUEUE_DELTASZ 65535
#define BOARD_SIZE 4
typedef long long llint;
@Abreto
Abreto / gist:7266948
Last active December 27, 2015 04:29
A testing queue.
/* A code for queue. */
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 5
#define DELTA_SIZE 5
typedef struct _queue
{
int size;
int *data;