Nested Segments CodeForces - 652D 树状数组

清理异常值(MAD:绝对中位差) 清理异常数据: 中位数绝对偏差(MAD):用来描述单变量样本在定量数据中可变的一种标准 在统计学中,绝对中位差是刻画一元数据样本变化的一个鲁棒度量。由公式可以看出,其求解还算简单,给定一个数据样本集,首先求其中位数,然后求原始数据减去中位数的绝对值从而形成一个新的数据样本,再求新的数据样本的中位数即为绝对中位差。比如说有一个数据样本集X={2 3 8 7 9 6 4},这时候数据的中位数是6,原... 阅读详情

D. Nested Segments
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line.

Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide.

Output

Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment.

Examples
input
4
1 8
2 3
4 7
5 6
output
3
0
1
0
input
3
3 4
1 5
2 6
output
0
1
1

给定n条线段,问每条线段包含了几条线段,先根据左端点值从大到小排序,相等按照右端点值从小到大,这样排序后前面的区间相对与后面的区间左端点可以满足条件,只需求前面的线段里有几个右端点也满足的即可,这一步可以用树状数组维护,不过这个题的右端点值范围较大,所以要先将右端点值离散化处理,在用树状数组维护

#include<bits/stdc++.h>
using namespace std;
struct node
{
	int l,r;
	int index;
}num[200005];
int f[200005],ans[200005],n;
int sum(int x)
{
	int sum=0;
	while(x>0)
	{	
		sum+=f[x];
		x-=x&-x;
	}
	return sum;
}
int add(int t,int x)
{
	while(t<=n)
	{
		f[t]+=x;
		t+=t&-t;
	}
}
int cmp1(node u,node v)
{
	if(u.l==v.l)
	{
		return u.r<v.r;
	}
	return u.l>v.l;
}
int cmp(node u,node v)
{
	return u.r<v.r;
}
map<int,int>p;
int main()
{
	int i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&num[i].l,&num[i].r);
		num[i].index=i;
	}
	int cnt=1;
	sort(num,num+n,cmp);
	for(i=0;i<n;i++)
	{
		if(!p.count(num[i].r))
		{
			p[num[i].r]=cnt++;
		}
	}
	sort(num,num+n,cmp1);
	for(i=0;i<n;i++)
	{
		ans[num[i].index]=sum(p[num[i].r]);
		add(p[num[i].r],1);
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}




基于Xilinx XDMA 的PCIE通信 基于Xilinx XDMA 的PCIE通信 概述:   想实现基于FPGA的PCIe通信,查阅互联网各种转载…基本都是对PCIe的描述,所以想写一下基于XDMA的PCIe通信的实现(PCIe结构仅做简单的描述(笔记),了解详细结构移至互联网)。实践实践!!! 说明: 参考文档: PCI Express Base Specification Revision 3.0 PCI Express Base Specification Revision 5.0 pg195-pcie-dma PCI Express体系 阅读详情

相关推荐

用STM32定时器PWM高级功能驱动步进电机:F103C8T6+TB6600实战教程

本文详细介绍了如何利用STM32F103C8T6微控制器的定时器PWM高级功能驱动TB6600步进电机驱动器,实现高效、灵活的运动控制方案。通过硬件配置、PWM参数计算、运动控制算法及TB6600高级功能应用的全面解析,为工业自动化和精密控制领域提供了实用的技术参考。

game4的博客 186

Nested Segments(离散+树状数组)

You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ...

fang_kuai的博客 532

单细胞数据导入实战:Read10X函数常见报错与解决方案

本文针对单细胞转录组分析中Read10X函数数据导入的常见问题,提供了详细的实战解决方案。重点解析了因文件路径错误、压缩文件未解压、版本命名不符及内存不足导致的报错,并给出了检查路径、正确解压、重命名文件、调整参数及优化内存等具体操作步骤,帮助用户高效完成单细胞数据导入,为后续分析奠定坚实基础。

weixin_28235513的博客 238

Nested Segments

Nested Segments 题面 题目描述 给你n个闭区间,让你判断是否有两个区间之间存在包含关系(解释:如果有两个区间A[a,b] B[c,d],当a&amp;lt;=c且b&amp;gt;=d时,我们认定A与B存在包含关系)。如果对题意还是不理解的可以看样例与note。 题目分析 这道题一出来,最朴素的解法就是暴力枚举所有可能的情况 即:for(i=1;i&amp;lt;n;i++){ for(j=i+1;j...

weixin_44412226的博客 703

雷电模拟器安装面具环境并过软件检测系列(看这一篇就够了!)

雷电模拟器安装面具环境并过基本软件的环境检测

qq_45059975的博客 6万+

游戏开发实战:如何用旋转矩阵实现2D角色平滑转向(附Unity代码)

本文深入探讨了在Unity游戏开发中,如何运用旋转矩阵原理实现2D角色的平滑转向。文章从核心理论出发,提供了计算目标旋转、实现平滑插值(Lerp与SmoothDamp)的完整C#代码,并解决了与动画系统、物理引擎协同的常见难题,帮助开发者提升游戏操作手感与视觉流畅度。

weixin_29057237的博客 287

D. Nested Segments(树状数组,排序)

先对右端点小到大来排序,维护左端点先对右端点小到大来排序,维护左端点先对右端点小到大来排序,维护左端点 由于排序后第iii条线段的右端点小于之后的右端点’ 所以右边的线段不可能对自己有贡献 考虑左边的线段对自己的贡献 由于自己的右端点大于前面的线段,想包含他们,还需要左端点小于他们由于自己的右端点大于前面的线段,想包含他们,还需要左端点小于他们由于自己的右端点大于前面的线段,想包含他们,还需要左端点小于他们 所以树状数组统计前面左端点大于自己左端点的个数即可所以树状数组统计前面左端点大于自己左端点的个数即可

jziwjxjd的博客 620

人工智能训练师三级考试备考全攻略|报名条件+真题+补贴申领一站式通关(2026版)

本专栏是人工智能训练师三级考证最完整的备考指南,共77篇文章,覆盖从职业认知、报名实操、AI基础知识、数据标注、模型训练测试部署、考前冲刺到考后进阶的全链路。本导读按模块整理了全部文章链接,帮你快速定位所需内容。人工智能训练师是国家认定的正式职业,证书可在osta.mohrss.gov.cn查询,三级证书可申领最高3120元技能补贴。

白话机器学习 1800

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

题目链接 参考博客 题意:   给n个线段,对于每个线段问它覆盖了多少个线段。 思路:   由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对右端点升序排序:   例如 2 3     5 6     4 7     1 8   这样的话,如果对i<j,a[ i...

ampg66396的博客 315

订餐平台餐厅信息抓取:使用Python爬虫获取商家信息和用户评价

在这篇博客中,我们展示了如何使用Python爬虫抓取订餐平台上的餐厅信息和用户评价数据。通过使用requests和Selenium,我们能够有效地从静态和动态网页中提取数据,并使用pandas和matplotlib对数据进行存储和分析。未来,您可以根据需求进一步扩展功能,例如增加错误处理、增加抓取多个页面的能力,或者使用高级技术如分布式爬虫来抓取更大规模的数据。

2201_76125261的博客 1651

YOLOv11改进目录一览 | 涉及卷积层、轻量化、注意力、损失函数、Backbone、SPPF、Neck、检测头等全方位改进

如今各种网络模型更新迭代越来越快,计算机视觉相关的文章也越来越多,多到一些普通,通用的改进点无法达到发表的要求。本专栏正是解决这个问题!如何寻找创新点?为什么要使用这个模块?如何才能提升模型的精度?这是贯穿我们研究始终的问题。创新点在这个专栏中我已经整理好了,这已经省去了大部分时间,但是当我们使用这些新的模块去优化已有的模型,如何才能提升模型的精度,才是我们要达到的最终目标。当然我们可以使用传统的A+B+C的方法去堆积模块,然后是进行大量的实验去排列组合以实现最终的精度提升,这无可厚非。

Limiiiing的博客 6万+

Weight of the System of Nested Segments

【代码】Weight of the System of Nested Segments。

m0_73915139的博客 146

Qt:一个强大而灵活的跨平台应用程序开发框架

代码示例中的源代码是简单的示例,用于演示Qt框架的一些基本特性。实际应用中,开发人员可以根据自己的需求和项目要求,使用Qt框架提供的丰富功能和组件进行开发。在Qt的官方文档和示例代码中,您可以找到更多详细的教程和示例,以帮助您更好地理解和使用Qt框架。它提供了丰富的工具和功能,支持跨多个平台进行开发,并具有高度的可定制性和灵活性。它提供了丰富的工具和功能,使得开发人员能够创建高性能、可扩展和易于维护的应用程序。下面将详细介绍Qt框架的优点,并提供一些相关的源代码示例。

CodeVorter的博客 858

Codeforces 652D Nested Segments 【树状数组 + 离散化】

题目链接:Codeforces 652D Nested Segments D. Nested Segments time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given n segments on a li

世界很大 1069

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

CodeForces - 652D Nested Segments(树状数组)

题目链接:https://codeforces.com/problemset/problem/652/D 题意:给你n条线段,每条线段的右端点一定不一样,问每一条线段包含几条线段。 思路:首先,我们可以把这n条线段按照左端点从小到大排序,如果左端点相同,就按照右端点从大到小排序。 如果拿第一个样例来举例的话,排序之后应该是这样的 这样,问题就转化成了对每一个直线的右端点,查找这条直线后面有多少个...

qq_43423395的博客 214

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Nested Segments CodeForces 652D 树状数组+离散化

传送门:CodeForces  652D 题意:给出n个区间,问每个区间包含多少区间。 思路:同时维护两个端点不好维护,我们可以按其中一个端点排序然后维护另一个端点,用树状数组维护一下就好了。 代码:#include #define ll long long #define pi acos(-1) #define MAXN 100010 #define inf 0x3f3f3f3f usin

WA是一笔财富 401

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CodeForces 652D Nested Segments (树状数组)

题意:给你n个区间,问每个区间包含了多少个区间 思路:先离散化一波,然后就是显然的树状数组瞎搞了...和POJ2458差不多 #include #include #include #include #include #include #include #include #include #include #include #include #include u

围巾的ACM博客 1108

CodeForces 652D Nested Segments 树状数组

题意: 给你n个区间,问第i个区间有多少个子区间? 分析: 跟poj2481那题差不多,把区间看成是一个点,那么一个区间的子区间一定在它的右下方,即x比他的大,y比他的小的点。然后用树状数组搞下就好,因为题目范围是( - 1e9≤ li < ri ≤ 1e9) ,所以要离散化,因为每个区间的右端点都不一样,所以直接对y排序后离散化就可以。 #includ...

196

CodeForces 652D Nested Segments(离散化,树状数组)

题目链接:http://codeforces.com/problemset/problem/652/D D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa

Shyazhut 463

Codeforces 652D Nested Segments 树状数组离线处理

You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.Input The first line contains a single integer n (1 ≤ n ≤

青铜时代 479

【Codeforces 652 D Nested Segments】+ 树状数组 + 离散化

D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputYou are given n segments on a line. There are no ends of some seg

楚江枫 596

CodeForces 652D :Nested Segments 思维 + 树状数组

传送门 题意 给你nnn条闭区间的线段,求每条能够包含的线段的数量 分析 考虑固定一维,将线段的左端点从大到小排序,那么被包含的线段一定是访问过的,右端点小于当前访问线段右端点的线段,离散化之后用树状数组维护即可 代码 #pragma GCC optimize(3) #include <bits/stdc++.h> #define debug(x) cout<<#x<<":"<<x<<endl; #define dl(x) printf("%lld

tlyzxc的博客 264

[离散化+树状数组]CodeForces - 652D Nested Segments

Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are givennsegments on a line. Th...

dixiangee374493的博客 147

codeforces_652D. Nested Segments(树状数组、二分)

D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given n segments on a line. Ther

凳子 538

Nested Segments CodeForces - 652D (树状数组,离散化)

You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.Input The first line contains a single integer n (1 ≤ n ≤

Hanylch 370

CodeForces 652D Nested Segments(树状数组 离散化)

题意:给你N条线段,保证线段终点没有重复,求每条线段他包含多少条线段。 思路:将线段按左端点排序,那么问题就变成了求这条线段之后的右端点比当前右端点小的线段有几条。这样就可以拿树状数组来做,先把每条边的右 端点+1,每处理一个边,就把该边的右端点-1,那么树状数组中维护的就是该边之后的。query(r-1)就是查询当前边之后的边中右端点比当前右端点 小的边数量。因为坐标比较大,所以需

CillyB的博客 616
上一篇: D - Longest Subsequence CodeForces - 632D
下一篇: Number of Parallelograms CodeForces - 660D 思维
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值