nyoj 600:花儿朵朵(树状数组+坐标离散化)
http://acm.nyist.net/JudgeOnline/problem.php?pid=600
只附代码好了
#include<bits/stdc++.h>
using namespace std;
;
struct node
{
int num,id;
} s[N];
int s1[N],a[N];
bool cmp(node x,node y)
{
return x.num<y.num;
}
int lowbit(int x)
{
return x&-x;
}
void add(int i,int x)
{
while(i<N)
{
a[i]+=x;
i+=lowbit(i);
}
}
int sum(int i)
{
;
while(i)
{
ret+=a[i];
i-=lowbit(i);
}
return ret;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
int n,m;
scanf("%d%d",&n,&m);
n<<=;m+=n;
;i<=m;i++)
{
scanf("%d",&s[i].num);
s[i].id=i;
}
sort(s+,s+m+,cmp);
;
s1[s[].id]=++cnt;
;i<=m;i++)
].num)
s1[s[i].id]=++cnt;
else
s1[s[i].id]=cnt;
;i<=n;)
add(s1[i++],),add(s1[i++]+,-);
;i<=m;i++)
printf("%d\n",sum(s1[i]));
}
}
nyoj 600:花儿朵朵(树状数组+坐标离散化)的更多相关文章
- nyoj_600:花儿朵朵(树状数组+坐标离散化)
http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...
- WUSTOJ 1337: Car race game(C)树状数组,离散化
题目链接:1337: Car race game 参考资料:⑴ Car race game 树状数组 棋煜,⑵ 树状数组,⑶ 离散化 补充资料:⑴ qsort,⑵ 二分查找 Description B ...
- 线段树&树状数组与离散化的妙用
牛客2019多校联盟Day7 Fine the median 题意: 每次给数组插入区间[Li,Ri] 内的所有数,每操作一次查询中位数. 遇到这题真的算是巧合,然而就是这种冥冥之中的缘分,给了我线 ...
- HDU 3333 | Codeforces 703D 树状数组、离散化
HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...
- POJ-2299 Ultra-QuickSort (树状数组,离散化,C++)
Problem Description In this problem, you have to analyze a particular sorting algorithm. The algorit ...
- HDU 5877 Weak Pair(树状数组+dfs+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: 给出一棵树,每个顶点都有权值,现在要你找出满足要求的点对(u,v)数,u是v的祖先并且a[u]*a ...
- 【(待重做)树状数组+dp+离散化】Counting Sequences
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定一个数组a,问这个数组有多少个子序列,满足子序列中任意两个相邻数 ...
- D. Nested Segments(树状数组、离散化)
题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对 ...
- 算法笔记求序列A每个元素左边比它小的数的个数(树状数组和离散化)
#include <iostream> #include <algorithm> #include <cstring> using namespace std ; ...
随机推荐
- 在getview方法中有三个参数,起到优化的部分为ViewHolder的使用,主要方法setTag(),getTag()
适配器代码如下: public class Myadapter extends BaseAdapter { List<String> date; Context context; //构造 ...
- 刷leetcode之路
写的不是很好,仅记录自己所写的,仅供参考. 第七题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = ...
- EZOJ #393加倍的飞机
分析 从大到小考虑每个点 记录一个连通块中选了选了几个 如果选的小于siz则直接选否则不选 代码 #include<bits/stdc++.h> using namespace std; ...
- LookupError: "gw_lt" is not among the defined enum values
LookupError: "XXX" is not among the defined enum value 查找错误:“xxx”不在定义的枚举值中 model.py中没有增加对应 ...
- 测开之路六十五:UI测试平台之js
//添加网址的函数,生成一个输入网址的标签,并且把标签append到id为cases下function browser() { var html = '\ <div class="ro ...
- groub by 与 over partition by 的区别
这个逻辑,写的很对.明白了这个意思. over partition by 前面一定要用汇总函数.groub by 就可以不用.本质都是汇总 SELECT a.* ,SUM(a.audit_status ...
- PHP 中 Error 和 Exception 两种异常的特性及日志记录或显示
PHP 文档: Error Exception 参考: 深入理解PHP原理之异常机制 我们什么时候应该使用异常 异常和错误 所有示例基于 PHP7. 应用中,关于错误的最佳实践是: 必须报告错误 开发 ...
- 字符串类——KMP子串查找算法
1, 如何在目标字符串 s 中,查找是否存在子串 p(本文代码已集成到字符串类——字符串类的创建(上)中,这里讲述KMP实现原理) ? 1,朴素算法: 2,朴素解法的问题: 1,问题:有时候右移一位是 ...
- Adam Optimization Algorithm
曾经多次看到别人说起,在选择Optimizer的时候默认就选Adam.这样的建议其实比较尴尬,如果有一点科学精神的人,其实就会想问为什么,并搞懂这一切,这也是我开这个Optimizer系列的原因之一. ...
- eclipse配置,快捷键备忘
1. General --> Workspace --> UTF-82. General --> Editors --> Associations --> JSP --& ...