Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem

实测对比:Gromacs GPU版vsCPU版性能差异到底有多大?2023最新基准测试 本文通过2023年最新基准测试,详细对比了Gromacs GPU版与CPU版的性能差异。测试显示,GPU版本在计算速度上可提升54倍,同时显著降低内存需求和能耗成本。文章还提供了GPU版安装优化实践和硬件选购指南,为计算生物学研究提供关键参考。 阅读详情

题目链接:点击打开链接


题意:给一序列数,定义f(l,r,x)为 l 到 r区间内等于x的数的个数。求对于所有的i,j(1<=i<j<=N),有多少对 f(1, i, ai) > f(j, n, aj)。


实际是一道树状数组的水题,先预处理出 f(1, i, ai) 和 f(j, n, aj),由于数据范围是10^9数组开不下,所以用到map。a数组保存的是f(1, i, ai) ,b数组保存 f(j, n, aj)。

然后树状数组c[i]维护有多少个f(j, n, aj)小于等于i,因为最多有10^6个数,所以只需开这么大的空间,求解的思路和求逆序数一样,从后往前查,每次先查询有多少数小于a[i]  (sum(a[i]-1)),然后把b[i]更新进去,边查询边更新。


数据看成了10^5 wa了n次


代码:

#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
int N;
int c[1000010];
int a[1000010];
int b[1000010];
map <ll,int >Hash;

ll d[1000010];

ll lowbit(ll n){
    return n&(-n);
}

void input(){
    for(ll i=1;i<=N;i++){
        scanf("%I64d",&d[i]);
        a[i]=0;
        c[i]=0;
    }
    Hash.clear();
}

void update(int p,int x){
    while(p<=N){
        c[p]+=x;
        p+=lowbit(p);
    }
}

long long sum(int p){
    long long res=0;
    while(p>0){
        res+=c[p];
        p-=lowbit(p);
    }
    return res;
}

void init(){
    for(int i=1;i<=N;i++){
        Hash[d[i]]++;
        a[i]=Hash[d[i]];
    }
    Hash.clear();
    for(int i=N;i>=1;i--){
        Hash[d[i]]++;
        b[i]=Hash[d[i]];
    }
}

int main(){
    while(cin>>N){
            input();
            init();
            long long res=0;
            for(int i=N;i>=1;i--){
                res+=sum(a[i]-1);
                update(b[i],1);
            }
            cout<<res<<endl;
    }
    return 0;
}




UNet 改进(45):轻松集成Triplet Attention,让分割效果起飞! 本文介绍了一种在U-Net架构中集成CSRA残差注意力模块的方法。该模块通过结合通道注意力和空间注意力机制,在U-Net的瓶颈层对特征进行自适应重标定,使网络聚焦于关键区域。文章详细解析了代码实现,包括基础构建块DoubleConv、核心CSRA模块原理及其在U-Net中的战略位置集成。测试表明该模型能保持标准U-Net的输入输出维度,同时通过注意力机制提升特征选择能力。这种模块化设计便于在不同任务中应用,为图像分割领域提供了有效的注意力增强方案。 阅读详情

相关推荐

Replay音频转换时samplerate缺失的解决方案指南

Replay音频转换时提示"No module named 'samplerate' This error is lazily reported, having originally occured in File"的解决方案

weixin_47445543的博客 2130

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)

2001

Windows 11 上 WSL2 安装 Ubuntu 22.04 保姆级教程(含桌面环境配置)

本文提供在Windows 11上通过WSL2安装Ubuntu 22.04并配置桌面环境的详细教程。涵盖WSL2核心安装、性能调优、Xfce桌面环境部署以及开发环境集成,帮助开发者构建高效、无缝的Windows-Linux混合开发工作站。

Jerry的专栏 633

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组)

D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she w

sxk 726

Appsflyer Web2App实战指南:OneLink与Web SDK深度对比

本文深入对比了Appsflyer实现Web2App的两大核心工具:OneLink智能链接与Web SDK。OneLink提供开箱即用的智能跳转,部署快捷,适合快速推广;Web SDK则支持高度自定义的用户行为追踪,适合深度分析与精细化运营。文章提供了详细的配置指南、场景化选型建议及实战避坑技巧,帮助营销与开发团队根据自身需求选择最佳方案,有效提升从网页到应用的转化率与归因精度。

weixin_29213655的博客 458

不用写代码!3个免费在线工具教你完成Lasso回归分析(含生存资料处理)

本文介绍3款免费在线工具,帮助用户无需编程即可完成临床数据的Lasso回归分析,特别适合处理生存资料。通过详细的操作指南和实战技巧,读者可以轻松掌握变量筛选、模型优化及结果解读,提升临床研究的效率和准确性。

weixin_33738555的博客 349

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem 离散化+树状数组

Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and

Clearlemon 612

QT编程系列1--QT学习前需知

本周学习了一些QT编程方面的知识,学写了几个程序,这里把记录下来。一方面对前面学习的知识做一个总结,便于以后复习、再学习和应用;另一方面也和大家做个交流,有不足的地方请各位看官多指点。   首先是做一些学习之前的交代:一,学习QT需要哪些基础;二,学习QT有哪些用途,QT较其他的开发工具有哪些特点;三,学习QT的思路。

霜月孤鸟&RTEMS&TinyOS 1115

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem(树状数组+逆序数对)

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for

Halo 965

如何在 SAP BTP 上使用 Integration Suite 消费 S/4HANA Cloud API

SAP Integration Suite是一个集成平台即服务(iPaaS),允许开发人员顺利地将内部部署和基于云的应用程序和流程与SAP管理的工具和预构建内容进行集成。登录 SAP Business Technology Platform Cockpit,进入 integration suite:再点击 API management 进入 API Portal:或者直接从收藏夹里打开链接:https://304a49cetrial.integrationsuitetrial-apiportal.cfapp

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1698

【第33话:车辆控制】自动驾驶车辆运动学模型推导及详解

自动驾驶车辆的运动学模型以自行车模型为核心,通过状态方程。

一碗白开水一 831

Codeforces Round #261 (Div. 2)[ABCDE]

Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden 题意: 一个正方形,它的边平行于坐标轴,给出这个正方形的两个点,求出另外两个点。 分析: 推断下是否平行X轴或平行Y轴,各种if。...

weixin_30485291的博客 86

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)

D. Pashmak and Parmida's problem Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has pr

lljjccsskk的专栏 455

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...

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)...

题目链接 题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数。i和j符合f(1,i,a[i])>f(j,n,a[j]),求i和j的种类数。 我们可以用map预处理出f(1, i, a[i])和f(j, n, a[j]),记为s1[n], s2[n]。 这样就变成求满足s1[i] > s[j], i < j情况的数量了,你会发现跟求逆序...

weixin_30553837的博客 113

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【索引】Codeforces Round #261 (Div. 2)

Problem A: Boredom(455A) Problem B: A Lot of Games(455B) Problem C:Civilization(455C) Problem D: Serega and Fun(455D) Problem E: Function(455E)

不慌不忙、不急不躁 701

Codeforces Round261 div2D Pashmak and Parmida's problem 树状数组

题目链接点这儿

御坂美琴o((≧▽≦o) 908

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

weixin_33962923的博客 126

Codeforces Round 459 D. Pashmak and Parmida's problem 树状数组求逆序数 变形

D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl a

01的世界 379

CF459D Pashmak and Parmida's problem (树状数组)

Codeforces Round #261 (Div. 2) 题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数。i和j符合f(1,i,a[i])>f(j,n,a[j]),求i和j的种类数。 题解:使用树状数组统计小于某数的元素数量。 我们可以先把f(1,i,a[i])和f(j,n,a[j])写出来,观察一下,例如样...

weixin_34241036的博客 150

Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组

题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数。i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到左预处理到某个下标为止有多少个数等于该下标,用map维护。 然后树状数组更新每个f(j,n,a[j]),预处理完毕,接下来,从左往右扫过去,每次从树状数组中删去a[i],因为i != j...

weixin_30954265的博客 111

557C - Arthur and Table (前缀和)

如果选择L为最后的最长长度,那么大于L的桌腿必须全去除。然后假如此时剩下M条桌腿,长度L的桌腿有num[L]条,如果tmp=num[L]*2-1-M0,就需要在小于L的腿中选择tmp条花费最小的桌腿。 首先把桌腿按长度排序然后预处理前缀和,这样后可以O(1)得到大于L的桌腿的总代价。 然后因为代价的最大值才200,那么维护小于L的每种代价桌腿的数量,按照计数排序的方法选择桌腿去除,再维

Baoli1008的专栏 1086

UVa 11235 Frequent Values(RMQ,ST算法)

注意到数列是非递减的,这代表相等的数字一定是挨在一起的。 用a[i]表示数字i所在的段的长度。 用left,right数组维护每个数字所在段左右边界位置。 这样对于查询s~t,right[s]+1~left[t]-1这个子区间全都是完整的段,对这个子区间做RMQ,得到最长的段长度。然后再考虑这个子区间两个边界到s,t的距离。这两个距离也可能是答案。这三个答案的最大值就是最终答案。 要特判s

Baoli1008的专栏 1048

csu 1335 高桥和低桥(树状数组+二分)

输入所有桥的高度后先对桥排序,然后先求出

Baoli1008的专栏 952
上一篇: hdu 1875 畅通工程再续
下一篇: Codeforces Round #261 (Div. 2) C. Pashmak and Buses
Baoli1008
博客等级 码龄12年 70粉丝 293原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值