bzoj 2743 树状数组离线查询】的更多相关文章

我们按照询问的右端点排序,然后对于每一个位置,记录同颜色 上一个出现的位置,每次将上上位置出现的+1,上次出现的-1,然后 用树状数组维护就好了 /**************************************************************     Problem:     User: BLADEVIL     Language: Pascal     Result: Accepted     Time: ms     Memory: kb ***********…
思路参考 这里. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; ; struct node { int l, r; int idx; }; node Qry[MAXN]; //查询 int C[MAXN]; //树状数组 int vis[MAXN]; // i 的倍数上一次出现的位置 int num[MAXN]…
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/H [题意] 给定一个数组,查询任意区间内不同数字之和. (n<=30000,Q<=100000,每个数字<=1 000 000 000) [思路] 要算任意区间内不同数字之和,如果我们从左到右依次处理,每次只保留最右边出现的数字,处理以当前数字为右端点的查询,就能做到“不同数字之和”,即不重不漏.因此我们要离线处理查询,按记录每个数作为右端点的所有查询区间.这里要用到v…
题目大意: 询问区间内不同种类的数的数值之和 这里逐个添加最后在线查询,会因为相同的数在区间内导致冲突 我们总是希望之后添加的数不会影响前面,那么我们就在添加到第i个数的时候,把所有在1~i 的区间的询问全部处理完成即可 对于之前的冲突,我们可以不断记录上一次冲突的位置,给当前的前缀和添加一个当前的val 对于上一次之前的前缀和要减去那个val就不会产生冲突了(之所以离线也是因为这个地方,如果后面的数添加完成,那么之前可能减去那个位置的数就导致区间查询出错) 所以将询问区间优先右排序就行了 #i…
不能用分块. #include <bits/stdc++.h> using namespace std; ; struct Info{int l,r,Id;}Q[Maxn]; int a[Maxn],n,c,m,Last[Maxn],Next[Maxn],d[Maxn],Ans[Maxn]; inline bool Cmp(Info A,Info B) {return A.l>B.l;} inline int Lowbit(int x) {return x&(-x);} inli…
D-query Time Limit: 227MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submit Status Description English Vietnamese Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For e…
D-query SPOJ 树状数组+离线/莫队算法 题意 有一串正数,求一定区间中有多少个不同的数 解题思路--树状数组 说明一下,树状数组开始全部是零. 首先,我们存下所有需要查询的区间,然后根据右端点进行从小到大的排序.然后依次处理这个区间中的答案,仔细想一下,后面的区间答案不会受到影响. 怎么处理区间中的答案呢? 我们按照数字出现的顺序,向树状数组中加一,如果这个数字之前出现了,那么需要树状数组在这个数字上次出现的位置减一,这样可以保证在一定区间内,每个数字都有在树状数组中唯一对应的1,当…
Necklace 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 beautiful value, we just count…
http://acm.hdu.edu.cn/showproblem.php?pid=5792 1012 World is Exploding 题意:选四个数,满足a<b and A[a]<A[b]   c<d and A[c]>A[d] 问有几个这样的集合 思路: 树状数组+离线化 先处理出每个数左边比它小 大,右边比它大 小的数目,用cnt[][i]表示.最后统计一下减去重复的就可以 #include <iostream> #include <cstdio>…
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout) #define maxn 300000 using namespace std; struct OPT { int type; int a,b,c,tag; OPT(int type=0,int a=0,int…