ZOJ 3872 Beauty of Array(数学)

systermverilog中for循环中的fork join执行情况分析 仅为本人学习记录,如有错误感谢指正! 阅读详情

Beauty of Array

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer is no larger than 1000000.

Output

For each case, print the answer in one line.

Sample Input
3
5
1 2 3 4 5
3
2 3 3
4
2 3 3 2
Sample Output
105
21
38

题意:定义一个序列的美丽值为序列中不同数的和,求一个序列的所有子序列的美丽值的和


思路:在代码中,关键是理解我C(x,2)代表取得区间是左开右闭的



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef long long ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 1000005

int ha[N],hato[N];
int a[N],b[N];
vector<int>g[N];
int n;
int k;

void solve()
{
	int i,j;
	ll ans=0;
	ll temp;
	fre(i,0,k)
	{

		ans+=(long long)(n)*(n+1)/2*hato[i]; //根据德保大神点拨,
		temp=0;                           //例如一个区间有3的位置为(这里用真实位置,不是从0开始)
										  //    3 ..  5... 8    假设在0位置有一个3
										  //那么有3的位置  0    3    5     8
										  //因为加了0,所以序列一共n+1个数,假设n+1个数都是3
										  //,现在任取两个数s,e作为
										  //有效区间为[s+1,e]时,那么就会加一个3,此时是上面那一步
										  //现在因为两个3之间并不都是3
										  //所以要去重,假设两个3之间的数的数目,设为x,那么应该x++,
										  //因为下面的C(x,2)代表取得区间的有效值是做开右闭的
										  //去掉的个数应该是C(x,2),当然减去的东西应该 再  * 3(这里的3代表原序列相同的数)
		fre(j,0,g[i].size())
		{
			ll tt=g[i][j]+1-temp;
			ans-=(tt)*(tt-1)/2*hato[i];
			temp=g[i][j]+1;
		}
		ll tt=n+1-temp;
		ans-=(tt)*(tt-1)/2*hato[i];
	}

  pf("%lld\n",ans);
}

int main()
{
   int i,j,t;
   sf(t);
   while(t--)
   {
   	  sf(n);
   	  fre(i,0,n)
   	  {
   	  	sf(a[i]);
   	  	b[i]=a[i];
   	  }

      sort(b,b+n);
      k=unique(b,b+n)-b; //担心数据太大,哈希预处理

      for(i=0;i<k;i++)
		{
			ha[b[i]]=i;   //哈希
		    hato[i]=b[i];
		}

	  fre(i,0,k+1)
	    g[i].clear();

	  fre(i,0,n)
	    g[ha[a[i]]].push_back(i); //保存相同数的下标,注意这里比实际的小1
	  solve();
   }
   	  return 0;
}

/*

3
5
1 2 3 4 5
3
2 3 3
4
2 3 3 2

*/













23、电生理与CSD分析:探索大脑活动的前沿技术 本文介绍了电生理与电流源密度(CSD)分析在探索大脑活动中的前沿应用。从电生理技术的发展现状,到局部场电位(LFPs)的起源与解释,重点阐述了CSD分析的原理、实验方法及其在绘制皮层兴奋流、解析突触输入和研究自发振荡中的广泛应用。文章还总结了该领域的优势与挑战,并展望了技术改进、多模态融合、数据分析创新及临床拓展的未来方向,展示了这些技术在揭示大脑功能机制中的关键作用。 阅读详情

相关推荐

SNN目标识别MNIST

总体来说这篇论文提出的方法用了多种更精密的细节,如LIF膜电位公式,三种STDP方法,但我觉得还可以有很大的改进,比如输入层全连接到兴奋层,兴奋层通过抑制层实现的侧向抑制,抑制层不参与学习等等。尤其是兴奋层通过抑制层实现侧向抑制这里,当神经元兴奋时,通过抑制层再倒回兴奋层,所抑制的已经经过一了一段时间的延迟。如有错误,请不吝赐教。

m0_74982304的博客 1262

ZOJ-3872-Beauty of Array【数学】【12th浙江省赛】

ZOJ-3872-Beauty of Array

Linoy 1120

SQLite学习——Dapper初识

dapper下载:https://www.nuget.org/packages/Dapper/1.40.0

jiDxiaohuo的博客 1295

ZOJ 3872 Beauty of Array (技巧)

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous s

小坏蛋_千千 797

TI DSP TMS320F280025 Note1:工程模板Template创建

该方法新建的工程支持寄存器开发,同时也支持库函数开发,新建后移动该工程也不需要重新修改路径,路径使用变量定义,使用方便、移植性能高

weixin_52849254的博客 2302

芯片Tapeout前GDS Review | Calibre中如何切出gds中指定区域版图?

芯片Tapeout GDS Review 之Calibre中如何切出指定区域版图GDS

weixin_37584728的博客 1786

ZOJ3872:Beauty of Array(浙江省赛2015)

The 12th Zhejiang Provincial Collegiate Programming Contest  Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now

ACM!荣耀之路! 3646

IMU卡尔曼滤波方法详细介绍

本文介绍了基于IMU和卡尔曼滤波的状态估计方法。系统采用9维状态向量(位置、速度、加速度计零偏),通过牛顿运动学建立状态方程,并利用外部位置观测进行校正。详细推导了状态转移矩阵和控制输入矩阵的形式,阐述了预测和更新的计算步骤。同时说明了过程噪声Q和观测噪声R的设置原则,其中Q反映模型不确定性,R取决于传感器精度。该方法可有效融合IMU测量与外部观测数据,实现位置、速度和偏置的联合估计。

haing2019的博客 756

ZOJ 3872 — Beauty of Array

原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3872 题意:求n个数的所有相邻的子数组的和,但重复的数字不加;     譬如:2 3 3 — 相邻子数组:2;3;3;23;33;233;     sum = (2)+(3)+(3)+(2+3)+(3)+(2+3)=  21; 思路:a[i]表示到第i

吧唧吧唧 576

利用大规模生物活性挖掘,计算识别针对癌基因驱动蛋白 EGFR、BRAF 与 CDK4 的高亲和力抑制剂

背景:精准癌症治疗需要小分子抑制剂与致瘤蛋白靶点之间的精确匹配。方法:我们使用 Python 及 ChEMBL 数据库 API 开发了一套计算流程,系统性地筛选针对 EGFR、BRAF 与 CDK4 的高亲和力配体。对 IC50 < 1000 nM 的生物活性进行过滤,并检索候选化合物的分子结构(SMILES)以供后续优化。结果:本研究共识别出 [插入总数] 种独特化合物。其中,对 BRAF 激酶而言,我们挑选了一批 IC50 低至 6.0 nM 的高效实验性化合物。

u012133341的博客 95

[实践篇]13.13 再来梳理一下HAB的设计原理

HAB全称为Hypervisor Abstraction,即硬件抽象,主要用于提供对HOST OS硬件资源的访问。

从0到1,突破自己 7258

ZOJ - 3872 Beauty of Array(子串的乘积的和)

Beauty of ArrayTime Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array a...

柳予欣的三味书屋~ 275

【QNX+Android虚拟化方案】01 - 芯片介绍

【QNX+Android虚拟化方案】01 - 芯片介绍

|~~~热爱生活、努力学习的小伙汁~~~| 2945

ZOJ 3872 Beauty of Array【数学】

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous ...

PinkAir的博客 248

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

pscad IEEE标准系统搭建说明

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

zoj3872——Beauty of Array(数学)

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguou

Beyond the Sora 532

IMSL CNL 7.0.0 (x86-64)Crack

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

zoj 3872 Beauty of Array (数学题)

题意: 给出一个序列,然后问这个序所有子序列对应数值的和是多少,注意这个和是序列中不同的数的和。 题解: 这题我们可以这样分析,对于某个数,考虑这个数对总的结果的贡献是多少,于是根据这个方向去思考,加上一些实例的判断,发现可以用递推去求解。 #include #include #include #include #include #include #include #include

ACM之梦 640

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

ZOJ 3872 Beauty of Array 第12届浙江省省赛D题 [思维] 【数学】

题目链接 : http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3872Beauty of ArrayTime Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of

Tabris的博客 752

ZOJ 3872 Beauty of Array(DP)

ZOJ 3872 Beauty of Array( DP思想 )

1033

zoj3872Beauty of Array

Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the arra

走一步再走一步 528

ZOJ 3872 Beauty of Array

Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the arra

LZK1997的博客 403

ZOJ - 3872 Beauty of Array

题意:给定一个含有N个数的序列S,定义序列的魅力值为序列中不同数字之和,求出该序列所有子序列的魅力值之和。 分析:每个数乘以它出现的次数,求和即可。 如何求每个数出现的次数? 1、对于一个各数字完全不同的序列, eg:3 5 2 6 8 对于5来说,确定其存在于的子序列 (1)其右面,可选0个数字---5        可选1个数字---3 5 (2)其右面,可选0个数...

Cherrychan2014的博客 139

ZOJ 3872:Beauty of Array【数列】

Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array.

所谓梦想,就是永不停息的疯狂。。。。。 438

ZOJ 3872: Beauty of Array(思维)

Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. He defines the beauty of a...

weixin_30954607的博客 70

【ZOJ - 3872】Beauty of Array(思维,计算贡献,枚举)

题干: Edward has an arrayAwithNintegers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contig...

xuanweiace的博客 413

ZOJ - 3872 Beauty of Array (dp)

Edward has an arrayAwithNintegers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguo...

本该如此 230
上一篇: HDU 4035 Maze (概率dp)
下一篇: ZOJ 3870 Team Formation(数学)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值