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 ; ...
随机推荐
- Eclipse中安装和使用FindBugs
FindBugs在Eclipse的离线安装: 1 到http://findbugs.sourceforge.net/downloads.html下载20131115123549_nlpir_ict ...
- [CSP-S模拟测试]:走格子(模拟+BFS+Dijkstra)
题目描述 $CYJ$想找到他的小伙伴$FPJ$,$CYJ$和$FPJ$现在位于一个房间里,这个房间的布置可以看成一个$N$行$M$列的矩阵,矩阵内的每一个元素会是下列情况中的一种:$1.$障碍区域—这 ...
- 表单修饰符 number、trim、lazy
number修饰符 <input type="number" v-model.number="age"> 结论:age 类型则为number,非字符 ...
- 如何正确安装Mysql
1.官网去下载 2.针对操作系统的不同下载不同的版本 安装步骤: 第一步解压文件:位置为你想要安装的盘符第二步加载环境变量加载的是bin目录第三步初始化:在cmd终端中输入 mysqld --ini ...
- php json_encode的问题
问题:跨域调用信息,返回json格式数据,返回的json数据中会多出空格,导致再用json_decode()编码的时候,页面显示空白,编码失败.解决方法:在页面中加入ob_end_clean();解决 ...
- Python判断端口连通性
#!/usr/bin/env python # -*- coding: utf-8 -*- import socket,sys def MySQL_Connet(MySQL_ip): MySQL_so ...
- CentOS 安装开发工具包
这里使用组安装包,一次性安装所有开发者工具. 1.查看有那些组安装包可用. [root@bogon ~]# yum grouplist | more 2.搜索一下有哪些和 Development 有关 ...
- 批量调整word 图片大小
打开文档后,按Alt+F11,在左边Porject下找到ThisDocument,右键插入模块,贴上下面的 Sub Macro()For Each iShape In ActiveDocument.I ...
- js实现方块弹珠游戏
下载地址:https://files.cnblogs.com/files/liumaowu/%E5%BC%B9%E4%B8%80%E5%BC%B9%E6%89%93%E6%96%B9%E5%9D%97 ...
- Android关于Activity生命周期详解
子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思想精 ...