首页 > 编程语言 >(C++)树状数组和线段树的VSCode Snippet

(C++)树状数组和线段树的VSCode Snippet

时间:2024-03-11 22:47:22浏览次数:22  
标签:body snippet tint VSCode C++ Snippet int prefix tif

学都学了,肯定要往snippet里塞好东西嘛

{
	// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": {
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"SegmentTree": {
	 	"prefix": "SegmentTree",
		"body": [
				"class SegmentTree",
				"{",
				"private:",
					"\tstruct node{",
						"\t\tint l,r;",
						"\t\tint sum;",
					"\t};",
					"\tint size;",
					"\tstatic const int N=100010;",
					"\tnode t[N*4];",
					"\tint w[N];",
				"\n",
				"public:",
					"\tvoid getArray(vector<int> nu)",
					"\t{",
						"\t\tfor(int i : nu)",
						"\t\t{",
							"\t\t\tsize++;",
							"\t\t\tw[size] = i;",
						"\t\t}",
						"\t\tbuild(1, 1, size);",
					"\t}",
					"\tvoid build(int u, int l, int r)",
					"\t{",
						"\t\tif(l == r)",
							"\t\t\tt[u] = {l, r, w[r]};",
						"\t\telse",
						"\t\t{",
							"\t\t\tt[u] = {l,r};",
							"\t\t\tint mid = (l+r) >> 1;",
							"\t\t\tbuild(u<<1, l, mid);",
							"\t\t\tbuild(u<<1|1, mid+1, r);",
							"\t\t\tpushup(u);",
						"\t\t}",
					"\t}",
					"\tvoid pushup(int u)",
					"\t{",
						"\t\tt[u].sum = t[u<<1].sum + t[u<<1|1].sum;",
					"\t}",
					"\tint query(int u, int l, int r)",
					"\t{",
						"\t\tif(t[u].l >= l && t[u].r <= r)",
							"\t\t\treturn t[u].sum;",
						"\t\tint mid = (t[u].l + t[u].r) >> 1;",
						"\t\tint sum = 0;",
						"\t\tif(l<=mid)",
							"\t\t\tsum += query(u<<1, l, r);",
						"\t\tif(r > mid)",
							"\t\t\tsum += query(u<<1|1, l, r);",
						"\t\treturn sum;",
					"\t}",
					"\tvoid modify(int u, int x, int v)",
					"\t{",
						"\t\tif(t[u].l == t[u].r)",
							"\t\t\tt[u].sum += v;",
						"\t\telse",
						"\t\t{",
							"\t\t\tint mid = t[u].l + t[u].r >> 1;",
							"\t\t\tif(x <= mid)",
								"\t\t\t\tmodify(u<<1, x, v);",
							"\t\t\telse",
								"\t\t\t\tmodify(u<<1|1, x, v);",
							"\t\t\tpushup(u);",
						"\t\t}",
					"\t}",
				"};$0"
		 	],
		 	"description": "Instant Segment Tree"
		},
		"TreeArray": {
				"prefix": "TreeArray",
				"body": [
					"class TreeArray{",
					"private:",
					"    vector<int> tr;",
					"    int n;",
					"public:",
					"    void init(vector<int> g){",
					"        for(int i=1; i<=g.size(); i++)",
					"            tr.push_back(0);",
					"        n = tr.size();",
					"        for(int i=1; i<n; i++)",
					"            add(i, g[i]);",
					"    }",
					"    int lowbit(int x){",
					"        return x & -x;",
					"    }",
					"    void add(int x, int v){",
					"        for(int i=x; i<=n; i += lowbit(i))",
					"            tr[i]+=v;",
					"    }",
					"    int query(int x){",
					"        int res = 0;",
					"        for(int i=x; i; i -= lowbit(i))",
					"            res += tr[i];",
					"        return res;",
					"    }",
					"    int rangeQuery(int x, int y){",
					"        return query(y) - query(x-1);",
					"    }",
					"};"
				],
				"description": "Instant TreeArray"
			}
}

标签:body,snippet,tint,VSCode,C++,Snippet,int,prefix,tif
From: https://www.cnblogs.com/ComputerEngine/p/18067272

相关文章

  • vscode-verilble
    参数名称说明默认值--column_limit目标行长度限制,用于指定格式化后的代码每行的最大字符数100--indentation_spaces每个缩进级别增加的空格数2--line_break_penalty每引入一行换行符的惩罚值2--over_column_limit_penalty超出列限制的基线惩罚值,超出此......
  • 用c++实现净现值的计算
    我是用c++实现的,我是把贴现率保留了四位小数。下面是我写的代码:#include<iostream>#include<cmath>usingnamespacestd;floatjst(intj,floatm,floatlv){while(j!=0){m*=(1+lv);j--;}return1.0/m;}i......
  • vscode搭建Renesas开发环境,编译并下载调试
    0windows下安装环境安装pyocd,libusbpipinstallpyocdpipinstalllibusb1使用RASC创建工程(1)创建工程(2)选择CMake(3)创建demo例程,可以先选择NoRTOS,最后点击Finish,创建完成(4)适用于vscode的例程已经创建完成,可以在vscode中打开,进行代码编写2VSCode配置(1)编辑Config......
  • C++ 津津的储蓄计划
    描述津津的零花钱一直都是自己管理。每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同。为了让津津学习如何储蓄,妈妈提出,津津可以随时把整百的钱存在她那里,到了年末她会加上20%还给津津。因此津津制定了一个储蓄计划:每个月的月初,在得到妈妈......
  • C++ 雇佣兵
    描述雇佣兵的体力最大值为M,初始体力值为0、战斗力为N、拥有X个能量元素。当雇佣兵的体力值恰好为M时,才可以参加一个为期M天的战斗期,战斗期结束体力值将为0。在同一个战斗期内,雇佣兵每连续战斗n天,战斗力就会上升1点,n为当前战斗期开始时的战斗力。一个战斗期结束后,雇佣兵需要用若......
  • [3] C++面向对象编程
    Day1函数指针数组简写函数指针typedeftypedefint(*FunPtr)(int,int);FunPtrFunArr[1]={Add};内联函数#pragmaregion内联函数//避免函数跳转对于程序的额外开销//有两种写法1).h中写实现文件(在.h中同时写声明和实现)//2)inline关键字......
  • C++学习笔记
    第一章认识C++1.1命名空间1.1.1命名空间的基本格式命名空间是一个由用户自己定义的作用域,在不同作用域中定义相同变量,不会冲突。命名空间中可以存放以下类型,这些定义/声明在结构体中的内容成为实体变量常量函数(可以是定义或声明)结构体类模板命名空间(可以嵌套定义)......
  • 运行golang测试无法读取环境变量[vscode]
    使用vscode运行golang测试,通常我们会发现无法读取到设置在系统的环境变量,其本质原因是使用vscode启动testing并不是常规的subshell,无法正常读取到系统的环境变量;解决方案:方案1:将环境变量配置在setting.json(适用于变量较少情况)"go.testEnvVars":{"NAME":"zimskyzeng",},......
  • vscode+cmake开发,头文件显示找不到(转载)
    原文地址:https://blog.csdn.net/lizy_fish/article/details/106376080 vsc在cmake开发当中会遇到,编辑器的插件判断头文件包含路径有问题。但是实际上通过cmake编译是正常的。特别是qt+vscode开发的时候,这个问题会导致编辑器的智能提示完全没有或者有误(比如包含这个文件的容......
  • 使用vscode插件生成小型c项目
    VScode生成c小型项目1.VScode安装C/C++projectcreator2.在磁盘任意位置创建一个文件夹名称(最好易懂)3.vscode顶部菜单栏点击文件或者快捷键f打开刚创建的文件夹​3.1在vscode界面下按ctrl+shift+p输入createC++Project​3.2生成的文件夹&文件有include------......