hdu 3333 树状数组+离线处理】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=3333 不错的题,想了非常久不知道怎么处理,并且答案没看懂,然后找个样例模拟下别人的代码立即懂了---以后看不懂的话就拿个样例模拟下别人的代码 举个样例:1 3 3 5 3 5 查询 a, 2 4 b, 2 5 最初是这么想的:对于a查询,倘若把第二个数第三个数变成1个3.那么到b查询,又出现了两个3,再做处理似乎还是O(n),并且假设先出现2,5查询,后出现2,4查询.那么还须要把删除的数补回来.....o(…
题目大意: 询问区间内不同种类的数的数值之和 这里逐个添加最后在线查询,会因为相同的数在区间内导致冲突 我们总是希望之后添加的数不会影响前面,那么我们就在添加到第i个数的时候,把所有在1~i 的区间的询问全部处理完成即可 对于之前的冲突,我们可以不断记录上一次冲突的位置,给当前的前缀和添加一个当前的val 对于上一次之前的前缀和要减去那个val就不会产生冲突了(之所以离线也是因为这个地方,如果后面的数添加完成,那么之前可能减去那个位置的数就导致区间查询出错) 所以将询问区间优先右排序就行了 #i…
Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3847    Accepted Submission(s): 1306 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems a…
After inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because Turing Tree could easily have the solution. As well, wily 3xian made lots of new problems about intervals. So, today, this sick thing happens again..…
思路:定义一个map容器用来记录数ai上次出现的位置.将查询区间按右边界升序进行排序,当插入第i个数ai时,pre[ai]+1---->i的区间就会多一个不同的数,其值就是ai,那么可以用update(pre[ai]+1,ai)来保存,但又不能影响i之后的位置,故用update(i,-ai)来消除.每次对于右边界时i的查询区间,只要对其左边界求和就行了,即Sum(qt[i].l). #include<iostream> #include<cstdio> #include<…
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>…
Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1959    Accepted Submission(s): 1006 Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i…
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1999    Accepted Submission(s): 689 Problem Description Long long ago, there was an ancient rabbit kingdom in the forest. Every ra…
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…