HDU 4417 离线+树状数组
Super Mario
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6174 Accepted Submission(s): 2675
For each test data:
The first line contains two integers n, m (1 <= n <=10^5, 1 <= m <= 10^5), n is the length of the road, m is the number of queries.
Next line contains n integers, the height of each brick, the range is [0, 1000000000].
Next m lines, each line contains three integers L, R,H.( 0 <= L <= R < n 0 <= H <= 1000000000.)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
int t;
int n,m;
int tree[];
int ans[];
int lowbit(int tt)
{
return tt&(-tt);
}
void add(int x,int y)
{
for(int i=x; i<=n; i+=lowbit(i))
tree[i]+=y;
}
int getsum(int x)
{
int ans=;
for(int i=x; i>; i-=lowbit(i))
ans+=tree[i];
return ans;
}
struct node
{
int w;
int pos;
} N[];
struct xx
{
int l,r;
int x;
int pos;
} M[];
bool cmp1 (struct node aa,struct node bb)
{
return aa.w<bb.w;
}
bool cmp2 (struct xx aa,struct xx bb)
{
return aa.x<bb.x;
}
int main()
{
scanf("%d",&t);
for(int i=; i<=t; i++)
{
memset(tree,,sizeof(tree));
scanf("%d %d",&n,&m);
for(int j=; j<=n; j++)
{
scanf("%d",&N[j].w);
N[j].pos=j;
}
sort(N+,N++n,cmp1);
for(int j=; j<=m; j++)
{
scanf("%d %d %d",&M[j].l,&M[j].r,&M[j].x);
M[j].l++;
M[j].r++;
M[j].pos=j;
}
sort(M+,M++m,cmp2);
int exm=;
for(int j=; j<=m; j++)
{
while(exm<=n&&N[exm].w<=M[j].x)
{
add(N[exm].pos,);
exm++;
}
ans[M[j].pos]=getsum(M[j].r)-getsum(M[j].l-);
}
printf("Case %d:\n",i);
for(int j=; j<=m; j++)
printf("%d\n",ans[j]);
}
return ;
}
HDU 4417 离线+树状数组的更多相关文章
- 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组
题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...
- 区间的关系的计数 HDU 4638 离线+树状数组
题目大意:给你n个人,每个人都有一个id,有m个询问,每次询问一个区间[l,r],问该区间内部有多少的id是连续的(单独的也算是一个) 思路:做了那么多离线+树状数组的题目,感觉这种东西就是一个模板了 ...
- HDU - 4777 离线树状数组
离线树状数组搞一搞. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #de ...
- 区间gcd问题 HDU 5869 离线+树状数组
题目大意:长度n的序列, m个询问区间[L, R], 问区间内的所有子段的不同GCD值有多少种. 子段就是表示是要连续的a[] 思路:固定右端点,预处理出所有的gcd,每次都和i-1的gcd比较,然后 ...
- HDU 5249 离线树状数组求第k大+离散化
KPI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 5869 (离线+树状数组)
Problem Different GCD Subarray Query 题目大意 给定n个数的序列,有q个询问,每次询问一个区间中所有子区间所形成不同的gcd的数量. 解题分析 由于固定一个数为右端 ...
- hdu 4605 Magic Ball Game (在线主席树/离线树状数组)
版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4605 题意: 有一颗树,根节点为1,每一个节点要么有两个子节点,要么没有,每个节点都有一个权值wi .然后,有一个球,附带值x . 球 ...
- HDU 2852 KiKi's K-Number(离线+树状数组)
题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...
- POJ 3416 Crossing --离线+树状数组
题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...
随机推荐
- JVM--内存模型与线程
一.硬件与效率的一致性 计算机的存储设备与处理器的运算速度存在几个数量级的差距,现在计算机系统不得不在内存和处理器之间增加一层高速缓存(cache)来作为缓冲.将运算需要的数据复制到缓存中,让运算能够 ...
- 372. Delete Node in a Linked List【LintCode java】
Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...
- [leetcode-666-Path Sum IV]
If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...
- BZOJ 3790 神奇项链 hash/后缀自动机+贪心
Description 母亲节就要到了,小 H 准备送给她一个特殊的项链.这个项链可以看作一个用小写字母组成的字符串,每个小写字母表示一种颜色. 为了制作这个项链,小 H 购买了两个机器.第一个机器可 ...
- SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)
Description You are given N circles and expected to calculate the area of the union of the circles ! ...
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- eg_1
1. 编写一个程序,输出一个字符串中的大写英文字母个数,小写英文字母个数以及非英文字母个数. 第一种方法: public class Test { public static void main(St ...
- ACM 第十四天
字符串: 1.KMP算法(模式串达到1e6) 模式串达到1e4直接暴力即可. 字符串哈希 字符串Hash的种类还是有很多种的,不过在信息学竞赛中只会用到一种名为“BKDR Hash”的字符串Hash算 ...
- ios::sync_with_stdio(false)提高C++读写速度
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:ios::sync_with_stdio(false)提高C++读写速度 本文地址:h ...
- WebService部署服务器调试时提示 “测试窗体只能用于来自本地计算机的请求”解决方法
原因:没有开启服务器访问权限! 解决方法: 在web.config的<system.web></system.web>中加入如下配置节内容即可解决 <webService ...