"A Simple Problem with Integers" 这道题目只涉及区间修改以及区间查询,所以只要我们利
原创
2022-11-03 15:21:33
26阅读
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 99895 Accepted: 31162 Case Time Limit: 2000MS Description Y
转载
2016-10-30 21:59:00
67阅读
2评论
C - A Simple Problem with Integers POJ - 3468 C - A Simple Problem with Integers POJ - 3468 C - A Simple Problem with Integers 思路:线段树区间修改区间查询。又出现了 C++
转载
2018-02-24 14:03:00
36阅读
http://poj.org/problem?id=3468 1 #include 2 #include 3 #include 4 #define maxn 100100 5 using namespace std; 6 7 __int64 a[maxn],c; 8 int N,Q,x,y; 9 struct node 10 { 11 int l; 12 int r; 13 __int64 sum; 14 __int64 add; 15 } p[maxn*4]; 16 17 void build_tree(int i,int l,in...
转载
2014-02-20 08:30:00
16阅读
2评论
POJ_3468
现在用的方法还是比较慢的,因为YTQ给我那个PPT还没深入研究透,PPT上面对这种的题的解法是用维护前缀和的前缀和以及{n*An}的前缀和来实现的,而我用的方法就是比较朴素的做lazy标记,来标识该区间内每个元素增加了多少。如果需要查询子区间时,再更新子区间的和,并将lazy标记传递下去。
#include<stdio.h>#include<strin
转载
2011-11-01 01:09:00
18阅读
2评论
A Simple Problem with Integers(树状数组)
用树状数组实现 区间更新,区间查询。
用两个数组维护区间和。
因为∑i=1nai=d1+(d1+d2)⋯+(d1+d2⋯+dn)=n∑i=1ndi−(0×d1+1×d1+⋯+(n−1)×dn=n∑i=1ndi−∑i=1n(i−1)×di\sum\limits_{i=1}^n a_i=d_1+(d_1+d_2)\dots+(d_1+d_2\dots+d_n)=n\sum\limits_{i=1}^nd_i-(0\times d_1+1\
原创
2022-01-22 13:45:11
64阅读
线段树
原创
2023-02-16 08:21:54
55阅读
A Simple Problem with IntegersTime Limit: 5000MS
原创
2023-02-19 09:28:51
44阅读
A Simple Problem with IntegersTime Limit:5000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 3468DescriptionYou have N integers, A1, A2
原创
2023-04-20 21:15:18
15阅读
题目链接:http://poj.org/problem?id=3468在HDOJ上有一个名字和这道题一模一样的题,在分类上也都是分到了数据结构里,小编我以为是同一道题,粘了自己HDOJ上的代码,怎么样都是WA,后来才发现题不一样=.=。题意:给我们n个整数,然后会有m次操作,如果操作是C,输入三个数a,b,c,表示从a到b之间的数加上c,如果操作是Q,输入两个数a,b,输出从a到b之间的所
原创
2022-08-30 10:56:40
54阅读
Problem DescriptionLet A1, A2, ... , AN be N elements. You need to
原创
2022-11-09 18:49:27
45阅读
Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 106771 Accepted: 33308 Case Time Limit: 2000MS Description You have N integers, A1, A2, ..
原创
2021-07-28 10:20:45
50阅读
A Simple Problem with IntegersTime Limit: 5000/1500 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1038Accepted Submission(s): 371Problem DescriptionLet A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a giv
原创
2021-07-29 16:25:21
82阅读
A Simple Problem with Integers(树状数组)用树状数组实现 区间更新,区间查询。用两个数组维护区间和。因为∑i=1nai=d1+(d1+d2)⋯+(d1+d2⋯+dn)=n∑i=1ndi−(0×d1+1×d1+⋯+(n−1)×dn=n∑i=1ndi−∑i=1n(i−1)×di\sum\limits_{i=1}^n a_i=d_1+(d_1+d_2)\dots+(d_1+d_2\dots+d_n)=n\sum\limits_{i=1}^nd_i-(0\times d_1+1\
原创
2021-08-10 10:08:23
36阅读
// 题意: 序列A[1-N], (1) C a b c 表示区间[a,b]里的数都加上c, (2) Q a b 查询区间[a,b]各个数的和#include <iostream> // 线段树, 修改和查询区间using namespace std;struct segment{ int l,r; __int64 sum,off; // sum记录该区间的和, 当覆盖范围为整个区间时,off记录所有的偏移量c, off初始化默认为0}tree[400000];int arr[100005],c;void built_tree(int n, int s,int...
转载
2011-07-18 00:10:00
14阅读
2评论
HDU_4267
根据k的值建立10类树状数组,每类中根据i%k的不同建立k棵树状数组,也就是55棵树状数组,这样每次修改操作只对其中1棵树状数组进行操作,所以是O(logN)的复杂度,每次查询只对其中10棵树状数组统计增量和,所以是O(10*logN)的复杂度。
#include<stdio.h>
#include<string.h>
#define MAXD
转载
2012-09-08 21:33:00
12阅读
2评论
A Simple Problem with IntegersTime Limit: 5000msMemory Limit: 131072KBThis problem will be judged onPKU. Original ID:346864-bit integer IO format:%lld...
转载
2015-09-05 22:36:00
34阅读
原题链接 考察:树状数组+差分 上一道题的加强版,但还是结合差分数组 思路: 操作一:"C a b c"表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 10000)。 这里还是得用到差分,设b数组为原数组的差分数组,那么此操作就转化为单点修改 操作二:"Q a b" 询问[a,
转载
2021-05-15 10:01:00
62阅读
2评论
线段树的指针表示法。代码还有待消化。。代码里面多次用到了函数递归,感觉这次对递归又有了深一层的理解。 1 #define LOCAL 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct CNode...
转载
2014-07-15 15:43:00
28阅读
2评论
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB bit IO Format:%Id & %Iu Submit Status Description You have N integers, A1
转载
2017-07-17 10:33:00
43阅读