
树状数组
AKone123456
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
树状数组维护LIS--------------------思维(树状数组)
注意: 必要时需要离散化#include<bits/stdc++.h>using namespace std;const int N=1e5+10000;int c[N];int n,a[N];int f[N];int lowbit(int x){ return x&(-x);}void add(int i,int val){ while(i<N) { c[i]=max(c[i],val); i+=lowbit(i); }}int su原创 2020-12-08 20:25:30 · 483 阅读 · 0 评论 -
J - YJJ‘s Salesman-----------------------思维(树状数组+dp)
题意:给定n个坐标,每个坐标都有一个属性值。问你从(0,0)走到(1e9,1e9)属性之和的最大值你可以向右,向下,向右下走。只有向右下走才能获得属性值?问最大是多少?解析:这道题以看就是个dp。如果是个二维dp 那么状态方程f[i][j]=max(f[i-1][j],f[i][j-1],f[i-1][j-1]+v[i][j])但是这样是不可取的。所以我们就不枚举行了。我们按照x轴排序,y列从大到小遍历然后用树状数组维护[y-1,0]的最大值即可 然后dp下去#include<..原创 2020-08-21 17:47:11 · 335 阅读 · 0 评论 -
The beautiful values of the palace---------------------------思维(树状数组+扫描线)
题意:给定一个n*n的螺旋矩阵,每个方格的权值为当前数字各位之和,现在给出m个宝殿的坐标。再给出q个询问,询问给出的矩形中宝典的权值之和解析:这道题最难的地方就是给定坐标求出螺旋矩阵对应的权值给出对应代码,细节大家自己看ll getval(ll x, ll y, ll n) { ll t = min(min(x, y), min(n - x + 1, n - y + 1)); ll ta = 4 * (t - 1) * (n - t + 1); if (x == n - t + 1) ...原创 2020-07-10 22:50:39 · 183 阅读 · 0 评论 -
问题 G: 鸽子 (gu)-------------------------思维(二维树状数组)
题目描述一共有n个人依次走进机房,第i个人的实力为ai。第i个人在走进机房时,会膜拜当前已经在机房里的人x,当且仅当ax>ai。同理,第i个人在走进机房时,会被当前已经在机房里的人x膜拜,当且仅当ax<ai。第i个人的音量为vi。设他在走进机房的时候,膜拜了k个人,那么,他会产生vi×k的噪音值。假设他走进机房时,膜拜他的人的集合为{s1,s2,s3,…,sm},那么这些人会产生***的噪音值。ctt2006巨佬想知道,每个人走进机房时,当前总共会产生多少噪音值。由于他忙着吊打集训队原创 2020-06-05 22:25:11 · 358 阅读 · 0 评论 -
换个角度思考-----------------------------思维(离线+树状数组)
解析:对于询问先离线处理,然后对于询问按照x从小到大排序。对于序列的数也要从小到大排序。对于每次询问,如果ai<=x 就让树状数组i位置上+1,然后区间查询即可#include<bits/stdc++.h>using namespace std;const int N=1e5+10000;int c[N];int n,q;int ans[N];struct node{ int l,r,x,pos; bool operator< (const node &a..原创 2020-05-13 21:36:40 · 172 阅读 · 0 评论 -
问题 A: 序列问题---------------------------------------------思维(树状数组+离散化+快速幂)
题目描述Tom 的梦想是成为世界冠军。因此他每天都在认真做题。某天他在学数学的时候又造出了一个新题,并准备以此为难你一下。给定长度为 n 的序列,正整数 k,可以定义两个函数:F(i)=iai mod kG(i)=aii mod k现在要求计算(l,r)数对的数量,其中 1≤l<r≤n, 且 f(l)>g®。输入第1行2个整数n,k。第2行读入n个整数a1,a2…an。...原创 2020-04-11 22:19:34 · 249 阅读 · 0 评论 -
问题 G: Above the Median------------------思维(套路)+树状数组
题目描述Farmer John has lined up his N (1 <= N <= 100,000) cows in a row to measure their heights; cow i has height H_i (1 <= H_i <= 1,000,000,000) nanometers–FJ believes in precise measureme...原创 2020-02-18 16:00:28 · 510 阅读 · 0 评论 -
问题 A: 子数列连续和
第二天叫醒我的不是闹钟,是梦想! 题目描述给定n个数列,规定有两种操作,一是修改某个元素,二是求子数列[a,b]的连续和。数列的元素个数最多10万个,询问操作最多10万次。输入第一行2个整数n,m(n表示输入n个数,m表示有m个操作)第二行输入n个数列。接下来m行,每行有三个数k,a,b(k=0表示求子数列[a,b]的和;k=1表示第a个数加b)。输出输出若干行数字,表示k=0时...原创 2019-11-27 17:11:37 · 225 阅读 · 0 评论 -
L - MooFest POJ - 1990
Every year, Farmer John’s N (1 <= N <= 20,000) cows attend “MooFest”,a social gathering of cows from around the world. MooFest involves a variety of events including haybale stacking, fence jump...原创 2019-11-10 14:55:10 · 161 阅读 · 0 评论 -
[SDOI2009]HH的项链
题目描述HH 有一串由各种漂亮的贝壳组成的项链。HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义。HH 不断地收集新的贝壳,因此,他的项链变得越来越长。有一天,他突然提出了一个问题:某一段贝壳中,包含了多少种不同的贝壳?这个问题很难回答……因为项链实在是太长了。于是,他只好求助睿智的你,来解决这个问题。输入格式第一行:一个整数N,表示项链的长度。...原创 2019-11-08 22:44:32 · 109 阅读 · 0 评论 -
HDU - 3874
Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beautiful value look the same, so if two or more balls have the same b...原创 2019-11-08 17:26:31 · 138 阅读 · 0 评论 -
HDU - 3743
第二天叫醒我的不是闹钟,是梦想! During Frosh Week, students play various fun games to get to know each other and compete against other teams. In one such game, all the frosh on a team stand in a line, and are then ...原创 2019-11-05 19:28:40 · 144 阅读 · 0 评论 -
HDU - 1394
The inversion number of a given number sequence a1, a2, …, an is the number of pairs (ai, aj) that satisfy i < j and ai > aj.For a given sequence of numbers a1, a2, …, an, if we move the first ...原创 2019-11-05 17:18:24 · 196 阅读 · 0 评论 -
POJ - 3067
第二天叫醒我的不是闹钟,是梦想! Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and M cities on the West coast (...原创 2019-11-04 13:54:05 · 165 阅读 · 0 评论 -
POJ - 2299
第二天叫醒我的不是闹钟,是梦想!In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the se...原创 2019-11-01 23:56:27 · 217 阅读 · 0 评论 -
UVA - 1428
第二天叫醒我的不是闹钟,是梦想!N (3 ≤ N ≤ 20000) ping pong players live along a west-east street(consider the street as a line segment).Each player has a unique skill rank. To improve their skill rank, they often...原创 2019-10-31 13:15:12 · 121 阅读 · 0 评论 -
HDU - 1541
第二天叫醒我的不是闹钟,是梦想!Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that a...原创 2019-10-31 10:43:35 · 135 阅读 · 0 评论 -
HDU - 1166
第二天叫醒我的不是闹钟,是梦想!C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情...原创 2019-10-30 18:42:23 · 165 阅读 · 0 评论 -
HDU - 1556
第二天叫醒我的不是闹钟,是梦想!N个气球排成一排,从左到右依次编号为1,2,3…N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?Input每个测试实例第一行为一个整数N,(N <= 100000).接下...原创 2019-10-30 17:18:09 · 167 阅读 · 0 评论