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:花儿朵朵(树状数组+坐标离散化)的更多相关文章

  1. nyoj 600:花儿朵朵(树状数组+坐标离散化)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...

  2. WUSTOJ 1337: Car race game(C)树状数组,离散化

    题目链接:1337: Car race game 参考资料:⑴ Car race game 树状数组 棋煜,⑵ 树状数组,⑶ 离散化 补充资料:⑴ qsort,⑵ 二分查找 Description B ...

  3. 线段树&树状数组与离散化的妙用

    牛客2019多校联盟Day7 Fine the median 题意:  每次给数组插入区间[Li,Ri] 内的所有数,每操作一次查询中位数. 遇到这题真的算是巧合,然而就是这种冥冥之中的缘分,给了我线 ...

  4. HDU 3333 | Codeforces 703D 树状数组、离散化

    HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...

  5. POJ-2299 Ultra-QuickSort (树状数组,离散化,C++)

    Problem Description In this problem, you have to analyze a particular sorting algorithm. The algorit ...

  6. HDU 5877 Weak Pair(树状数组+dfs+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: 给出一棵树,每个顶点都有权值,现在要你找出满足要求的点对(u,v)数,u是v的祖先并且a[u]*a ...

  7. 【(待重做)树状数组+dp+离散化】Counting Sequences

    https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定一个数组a,问这个数组有多少个子序列,满足子序列中任意两个相邻数 ...

  8. D. Nested Segments(树状数组、离散化)

    题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对 ...

  9. 算法笔记求序列A每个元素左边比它小的数的个数(树状数组和离散化)

    #include <iostream> #include <algorithm> #include <cstring> using namespace std ; ...

随机推荐

  1. 织梦dedecms后台发布文章提示“标题不能为空”

    问题症状:V5.7登录后台后,发布英文标题没问题,发布中文会提示“标题不能为空”. 问题根源:htmlspecialchars在php5.4默认为utf8编码,gbk编码字符串经 htmlspecia ...

  2. bootstrap中的下拉菜单

    下拉菜单必要的代码: <div  class="container"> <div  class="dropdown"> <butt ...

  3. 利用angular控制元素的显示和隐藏

    <!DOCTYPE html> <html lang="en" ng-app="myapp"> <head> <met ...

  4. JavaScript数组基础及实例

    js数组 和var i=1;这样的简单存储一样是js中的一种数据结构,是专门用来存储多个数据的一种数据结构. 摘:数组是一组数据的集合,其表现形式就是内存中的一段连续的内存地址,数组名称其实就是连续内 ...

  5. shell脚本调用C语言之字符串切分之strtok函数

    今天上午在写一个需求,要求的比较急,要求当天完成,我大致分析了一下,可以采用从shell脚本中插入一连串的日期,通过调用proc生成的可执行文件,将日期传入后台数据库,在数据库中进行计算.需要切分日期 ...

  6. vue-router单页应用简单示例(二)

    我们先来理一下思路. 图1:main.js 引入vue,App.vue,router/index.js文件 声明要渲染的Id为app,将App.vue中的模版渲染到入口界面(就是打开localhost ...

  7. Nginx+Keepalived 主备高可用 安装与配置

    环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10. ...

  8. oracle学习笔记(2)-基本术语

    oracle基本术语 先上图. 相当粗糙的一个图,可能有些地方不够精细,大致结构基本是对的. 逻辑结构上从大到小的依次为文件(file)->表空间(tablespace)->段(segme ...

  9. win7系统中使用DOS命令是出现乱码的解决方法

    方法一:设置cmd显示字体1.win+R打开运行窗口->输入cmd->回车,打开命令行提示符窗口 win7系统运行窗口win7系统DOS命令行提示窗口 2.在命令行标题栏上点击右键,选择” ...

  10. C#注册表操作类--完整优化版

    using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; namespace ...