soj上一个fuckable的题目

求逆序数的三种数据结构比较 本文比较树状数组,线段树,还有一种unnamed的树状结构,在求逆序数中的运行效率。 阅读详情

题目链接:http://cs.scu.edu.cn/soj/problem.action?id=3098

题目概述:

Description



Once again, James Bond is on his way to saving the world. Bond's latest mission requires
him to travel between several pairs of cities in a certain country.

The country has N cities (numbered by 1, 2, . . ., N), connected by M bidirectional roads.
Bond is going to steal a vehicle, and drive along the roads from city s to city t.
The country's police will be patrolling the roads, looking for Bond, however, not all
roads get the same degree of attention from the police.

More formally, for each road MI6 has estimated its dangerousness, the higher it is,
the more likely Bond is going to be caught while driving on this road. Dangerousness
of a path from s to t is defined as the maximum dangerousness of any road on this path.

Now, it's your job to help Bond succeed in saving the world by finding the least dangerous
paths for his mission.

Input



There will be at most 5 cases in the input file.

The first line of each case contains two integers N, M (2 ≤ N≤ 50000, 1≤ M ≤ 100000) –
number of cities and roads. The next M lines describe the roads. The i-th of these lines
contains three integers: xi, yi, di (1 ≤ xi, yi ≤ N, 0 ≤ di ≤ 10^9) - the numbers of the
cities connected by the ith road and its dangerousness.

Description of the roads is followed by a line containing an integer Q (1 ≤ Q ≤ 50000), followed
by Q lines, the i-th of which contains two integers si and ti (1 ≤ si, ti  ≤ N, si != ti).

Consecutive input sets are separated by a blank line.

Output



For each case, output Q lines, the i-th of which contains the minimum dangerousness of a path
between cities si and ti. Consecutive output blocks are separated by a blank line.

The input file will be such that there will always be at least one valid path.

Sample Input



4 5
1 2 10
1 3 20
1 4 100
2 4 30
3 4 10
2
1 4
4 1

2 1
1 2 100
1
1 2

Sample Output



20
20

100

Source



Ivan Krasilnikov @ Next generation contest – 4 @ UVA

 

 

解决方案:最小生成树+lca(可以用tarjan,正是因为我想用rmq结果搞得fuckable了)

 

 

 

 

代码:

 

 

 

 

 

 

SOJ编程题目集锦 SOJ题目 立即下载

相关推荐

GNSS数据处理新手避坑:手把手教你用GAMP_GOOD下载IGS/MGEX数据(附.cfg文件详解)

本文详细介绍了如何使用GAMP_GOOD进行GNSS数据处理,从基础配置到高级参数调优,帮助新手避开常见错误。内容包括软件安装、配置文件详解、数据源选择、测站文件配置以及性能优化技巧,特别适合GNSS数据处理初学者快速上手。

weixin_30338481的博客 390

【深度之眼】Pytorch框架班第五期-Pytorch中常见的报错信息与课程总结

报错: ValueError: num_samples should be a positive integer value, but got num_samples=0 可能的原因:传入的Dataset中的len(self.data_info)==0,即传入该dataloader的dataset里没有数据 解决方法: 检查dataset中的路径,路径不对,读取不到数据。 检查Dataset的__len__()函数为何输出为零 2 报错:TypeError: pic should be PIL I...

Zero_run的博客 785

Ubuntu系统下STM32开发环境搭建:从零配置CubeMX、VSCode与OpenOCD调试实战

本文详细介绍了在Ubuntu系统下搭建STM32开发环境的完整流程,包括CubeMX、VSCode和OpenOCD的安装配置。通过实战教程指导开发者从基础环境准备到工程创建与调试,提供高效的嵌入式开发解决方案,并分享常见问题解决方法。

potato的博客 941

C++基础(一) C++对C语言的增强

文章目录1 Hello World2 命名空间 namespace2.1 命名空间的使用1 直接用std::cout 方式2 使用using namesapce std 方式3 使用std::cout2.2 自定义命名空间(1) 定义一个命名空间(2) 命名空间嵌套3 C++语言的增强(1) 实用性增强1 对于变量定义的位置可以随用随定义2 对全局变量的检测能力加强3 使用struct时 不需要再...

simple_a的博客 971

免费获取船舶轨迹数据?手把手教你用Python处理中国海洋卫星AIS数据

本文详细介绍了如何免费获取中国海洋卫星AIS数据,并使用Python进行船舶轨迹数据的处理与分析。从数据源评估到自动化处理流水线,再到高级分析与可视化技巧,手把手教你避开常见问题,实现高效数据处理。特别适合航运数据分析、物流优化和海上安全研究等领域的研究者和开发者。

weixin_42616115的博客 320

YOLOv11改进 | 注意力篇 | YOLOv11引入24年ECCV的自调制特征聚合注意力模块(SMFA),并构建C2PSA_SMFA

1.SMFA介绍1.1 摘要:基于Transformer的图像复原方法由于Transformer的自注意(self-attention,SA)特性能够更好地挖掘非局部信息,从而获得更好的高分辨率图像重建效果,因此具有重要的应用价值。然而,关键点积SA需要大量的计算资源,这限制了其在低功耗器件中的应用。此外,模拟退火机制的低通特性限制了其捕获局部细节的能力,从而导致平滑的重建结果。

tsg6698的博客 952

成功解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题

成功解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题 目录 解决问题 解决思路 解决方法 解决问题 解决Python中出现的ValueError: not enough values to unpack (expected 2, got 1)的问题 解...

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 17万+

SCSA,scCATCH,SciBet,SingleR 四种注释方法比较

以下是和四种细胞类型注释方法的详细对比,从。

qq_40256654的博客 1215

Jackson异常问题和解决方案总结

转自:http://www.baeldung.com/jackson-exception 1. 前言 在本教程中, 我们会回顾最常见的Jackson异常 – the JsonMappingException and UnrecognizedPropertyException. 最后,我们将会简要讨论Jackson 中的no such method错误。 2. “Json

蚁人的博客 6万+

亿图机床采集数据

这个数控系统的英文名是HUST,在台湾知名度还可以,但大陆这边我做这么多年项目也只接触过屈指可数的几次,可见市场占有率并不大,联网采集不复杂。

若云流风的专栏 2495

Qt实现思维导图功能5『纵向分布模式』

思维导图纵向分布模式:模式一

浮生流年的博客 1060

Expected value at 1:0 Expected value at 2:0 Expected value at xx:xx错误的解决,实测解决

json文件出现以下问题: 解决方案: 1.原文件目录下右击->new file,新建config.json(随便起个名字,后缀是.json就可以); 2.把原来的.json文件内容copy到新建的config.json即可 3.把原文件删除,新建的config.json名字改回来 ps: 如果没有设置配置文件编码的,别忘了右击文件->properties->编码改成u...

Ange1Beats的博客 4495

6-Halcon-- var_threshold 函数功能(用于基于局部统计特性的动态阈值分割的算子)

var_threshold 是 HALCON 中用于基于局部统计特性的动态阈值分割的算子,特别适用于处理低对比度图像或纹理均匀但包含细微差异的场景。与 dyn_threshold 不同,它不依赖预处理生成的参考图像,而是直接在局部区域内计算灰度值的统计特性(均值和标准差),从而自适应调整阈值。

weixin_45590420的博客 1328

使用tensorflow训练数据时遇到的问题总结

1、OP_REQUIRES failed at assign_op.h models 这个问题的根源在于GPU不够用,解决方法也是各不相同,这里写一下几个共性方法。 在eval文件中加入os.environ['CUDA_VISIBLE_DEVICES']='2' 强制使用CPU验证 降低batch_size 修改tensorflow-gpu的版本,可能有效果 更换网络 2、Argument must be a dense tensor: range(0, 3) - got shape [3], bu

好好学java 1万+

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

深度学习工具包 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")

pytorch遇到的问题1

问题一 RuntimeError:Given groups=1,weight of size[16,3,3,3],expected input[1,384,384,3] to have 3 channels,but got 384 channels instead. 我写的网络的nn.Conv2d(3,16,3,1,padding=1),要求输入通道为3,输出是16,网络对于四个参数的认识是第一...

weixin_43989326的博客 5437

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

KMP算法C++代码

//by baihacker  #include    #include    #include    #include    using namespace std;templatetypename FType, typename SType>struct equal_cmp{  bool operator ()(const FType& _F, const SType& _S)cons

baihacker的专栏 1万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

金山招聘题目:编程计算从1到2008080808之间的整数有多少个含有数字7

我的代码(如果要加一个模板参数来判断n和last是否相等,会有意想不到的效果):#include     using namespace std;const int MAX = 2008080808;const int IT = 7;templateint n, int curr, int last, int base, int weight>class A{    enum{it = n/b

baihacker的专栏 7751

关于PE458(project euler 458 Permutations of Project)的思考

本文回顾了PE458的解题过程中遇到的问题,介绍了trie,AC自动机,自动机化简算法.

baihacker的专栏 7117

windows10下编译clang流水帐

windows10上编译clang的流水账。

baihacker的专栏 4619

AVL(平衡树)C++代码(非递归)

代码被移动到二叉查找树代码中。需要资源分为0。 资源描述 1.里面有一份较老的avl树代码。 2.主要构成是基于C++的模板技术的二叉查找树代码,其中包含 avl树,bst树(二叉查找树),rbt(红黑树),sbt(size平衡树),splay(伸展树),treap树。 3.代码以一个bst_base为基础,实现通用算法。将对象特征和存储结构通过模板参数向上传递,实现特化算法。最终各个不

baihacker的专栏 3971

生日悖论

今天http://weibo.com/2887339314/BcqXD9OKz 发了个问题:300个人,至少5个人同一天生 日的概率,博主用蒙特卡罗方法算出来了结果,一时兴起,写了个算精确结果的代码。

baihacker的专栏 3378

用递归写的大数运算

//by baihacker 用递归写的大数运算 #include      typedef struct BigNum_{    int data[256];    int n;} BigNum;BigNum* carry(BigNum* bn, int curr, int valid, int inc){    return curr>=valid && inc ? (++bn->n,

baihacker的专栏 3321

在GitHub上挖了两个坑

在Github上挖了两个关于project euler的坑.

baihacker的专栏 3091

二分原理

作者:baihacker 来源:http://hi.baidu.com/feixue http://hi.youkuaiyun.com/baihacker 二分原理: 设f是定义在[a, b]上的bool函数,且满足性质若f(i) = true则f(i+1) = true. 那么算法: int l = a, r = b; while (l {  int mid = (l + r)/2;

baihacker的专栏 2687

DacningLinks实现

本文简单分析DancingLinks实现中的数据结构设计,给出了精确覆盖问题及其扩展问题的代码,并应用于数独问题。

baihacker的专栏 2586
上一篇: 没事晒晒代码
下一篇: google code jam 2009 解题报告
baihacker
博客等级 码龄21年 1703粉丝 57原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值