NEERC 17 G The Great Wall (treap)

超菜鸟级ctf5 超菜鸟级ctf5 前言 这次的题整体也比较简单,感觉密码题可能多了点 题目 门太低了 这道题前面也做过类似,考查xss,查看源码也能看到提示xss,这里script必须小写,大写还不行…没什么意思的题啊 New Swan Stone Castle 这中sql注入已经做了很多了,sqlmap都是可以直接跑出来的 这里手工注入的话要闭合括号和双引号。能用sqlmap直接不调参就跑出来,意义... 阅读详情

题意:

        给你一个数列,每个点有abc三个值,现在让你画两个区间x,y,区间大小为r,区间不可以完全重合,当一个点没有被区间覆盖时值为a,被一个区间覆盖时值为b,两个区间为c,问第k小的数列数值总和为多少

思路:

       我们二分答案val,寻找小于val的有多少对x,y
       首先思考当x,y没有重合的时候,我们枚举后面的区间y的起点i,设区间权值和为v,我们每次询问小于val-v的有多少个,询问完后将,[i-r+1,i]这个区间的值加入到一个数据结构里面,支持插入和查询排名,treap就能满足
       然后我们思考当两个区间有重合的时候,区间可化为gi+figi+fi,其中
                            gi=∑i−10(ci−2∗bi)+∑i+r−1i(ci−bi)gi=∑0i−1(ci−2∗bi)+∑ii+r−1(ci−bi)

                            fi=∑i−10(2∗bi−ci)+∑i+r−1i(bi)fi=∑0i−1(2∗bi−ci)+∑ii+r−1(bi)
       这个式子是什么意思呢,可以画一下图,就发现这两个式子和会使得区间相互抵消,最后就是我们希望的结果,那么我们和之前一样,不停查询,插入即可,但是这里记得及时删除无法和后面区间产生重合的区间,支持插入,查询排名和删除,treap依旧能满足
       在开始之前将bi−aibi−ai,ci−aici−ai,写的时候会更加清晰,在输出答案之前加上∑n1ai∑1nai就行
       发现好多大佬都是用树状数组线段树写的,不是很懂是什么原理,我这样的渣渣只能用treap莽了QAQ

错误及反思:

        NEERC虽然有的题目很麻烦,但是意外的数据都没坑,有点爽

代码:

#include<bits/stdc++.h>
using namespace std;
const int N = 31000;

int n,k,r;
int a[N],b[N],c[N];
long long preb[N],pre2bc[N],precb[N];
struct Treap{
    int l,r,dat;
    long long val;
    int cnt,size;
}t[N];
int tot,root;
long long INF = 1000000000000000;

int New(long long val){
    t[++tot].val=val;
    t[tot].dat=rand();
    t[tot].l=t[tot].r=0;
    t[tot].cnt = t[tot].size =1;
    return tot;
}

void Update(int p){ t[p].size=t[t[p].l].size+t[t[p].r].size+t[p].cnt; }
void Build(){ New(-INF); New(INF); root=1,t[1].r=2; Update(root); }
void zig(int &p){ int q=t[p].l; t[p].l=t[q].r,t[q].r=p,p=q; Update(t[p].r),Update(p);}
void zag(int &p){ int q=t[p].r; t[p].r=t[q].l,t[q].l=p,p=q; Update(t[p].l),Update(p); }

int GetRankByVal(int p,long long val){
    if(p==0) return 0;
    if(val==t[p].val) return t[t[p].l].size+t[p].cnt;
    if(val<t[p].val) return GetRankByVal(t[p].l,val);
    return GetRankByVal(t[p].r,val)+t[t[p].l].size+t[p].cnt;
}

void Insert(int &p,long long val){
    if(p==0){
        p=New(val);
        return ;
    }
    if(val==t[p].val){
        t[p].cnt++,Update(p);
        return ;
    }
    if(val<t[p].val){
        Insert(t[p].l,val);
        if(t[p].dat<t[t[p].l].dat) zig(p);
    }
    else{
        Insert(t[p].r,val);
        if(t[p].dat<t[t[p].r].dat) zag(p);
    }
    Update(p);
}

void Remove(int &p,long long val){
    if(p==0) return ;
    if(val==t[p].val){
        if(t[p].cnt>1){
            t[p].cnt--,Update(p);
            return ;
        }
        if(t[p].l||t[p].r){
            if(t[p].r==0||t[t[p].l].dat>t[t[p].r].dat)
                zig(p),Remove(t[p].r,val);
            else zag(p),Remove(t[p].l,val);
            Update(p);
        }
        else p=0;
        return ;
    }
    val<t[p].val?Remove(t[p].l,val):Remove(t[p].r,val);
    Update(p);
}


int cal1(long long x){
    tot=0; Build();
    int ans=0;
    for(int i=r;i+r-1<=n;i++){
        ans+=GetRankByVal(root,x-preb[i+r-1]+preb[i-1])-1;
        Insert(root,preb[i]-preb[i-r]);
    }
    return ans;
}

int cal2(long long x){
    tot=0; Build();
    int ans=0;
    for(int i=1;i+r-1<=n;i++){
        ans+=GetRankByVal(root,x-(pre2bc[i-1]+preb[i+r-1]-preb[i-1]))-1;
        Insert(root,-pre2bc[i-1]+precb[i+r-1]-precb[i-1]);
        if(i>=r) Remove(root,-pre2bc[i-r]+precb[i]-precb[i-r]);
    }
    return ans;
}


int judge(long long x){
    int ans=0;
    ans+=cal1(x);
    ans+=cal2(x);
    return ans;
}

int main(){
    scanf("%d%d%d",&n,&r,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]),b[i]-=a[i];
    for(int i=1;i<=n;i++) scanf("%d",&c[i]),c[i]-=a[i];

    for(int i=1;i<=n;i++) preb[i]=1ll*preb[i-1]+1ll*b[i];
    for(int i=1;i<=n;i++) pre2bc[i]=1ll*pre2bc[i-1]+2ll*b[i]-1ll*c[i];
    for(int i=1;i<=n;i++) precb[i]=1ll*precb[i-1]+1ll*c[i]-1ll*b[i];

    long long l=0,r=3e10;
    while(l+1<r)
    {
        long long m=(l+r)/2;
        if(judge(m)>=k) r=m;
        else l=m;
    }
    for(int i=1;i<=n;i++) r+=1ll*a[i];
    printf("%lld\n",r);

}
“蔚来杯“2022牛客暑期多校训练营9 I题: The Great Wall II Tag: 动态规划,单调栈 阅读详情

相关推荐

网络流题目合集

属实狠活 HDU 2883 kebab还是区间k重覆盖的变形,然而每想到 就这? HDU 3315 My Brute HDU 3947 River Problem 区间k重覆盖的变形 拉了

Roll_Keyboard的博客 848

2020-2021 ICPC银川站B题 The Great Wall 题解(dp)

题意: 给出一个长度为nnn的数组 aaa ,将数组分成 kkk 段,每段的价值为最大值减去最小值。数组的价值为每段价值之和。 求k=1.2.3.4..nk=1.2.3.4..nk=1.2.3.4..n 时,数组的最大价值。 题解: 可以将每段价值转换成选择两个数相减,使得最后总和最大,那么最优必是最大值减去最小值,其实也可以看成选一个数乘上1,再选一个数乘上-1 那么设dp[i][j][0]dp[i][j][0]dp[i][j][0] 表示前 iii 个数分成 jjj 段,且第jjj 段还未选择两个数,d

the best 的博客 3905

codesys【modbusRTU】主站

【代码】modbusRTU【codesys】

cfqq1989的博客 4370

The Great Wall, a thousand year long watchman

The Great Wall, like a giant dragon winding across the land of China, is not only a pile of bricks, stones, and soil, but also a symbol of the resilient and indomitable spirit of the Chinese nation. Every brick, every handful of soil, tells the story of th

m0_38012434的博客 107

江科大51单片机笔记【1】单片机及开发板介绍

单片机,Micro Controller Unit,简称MCU,内部集成了CPU、RAM、ROM、定时器、中断系统、通讯接口等一系列电脑的常用硬件功能单片机的任务是信息采集(传感器)、处理(CPU)和硬件设备(电机、LED)的控制单片机算是一个袖珍版计算机,是一个完整的计算机系统,成本低体积小结构简单单片机的使用领域:智能仪表、实时工控、通讯设备、导航系统、家用电器等。

2301_80195807的博客 831

AI Agent开发实战:100个真实场景题库解析

AI Agent开发涉及复杂的需求理解、架构设计及安全防护等关键技术环节。在工程实践中,开发者常面临需求偏差、系统崩溃等挑战,特别是在金融、医疗等高要求场景下。通过真实案例题库,开发者能系统性地掌握需求分析、架构决策树建模(如向量数据库选型)、安全攻防策略(如提示词注入防御)等核心技能。这些实战经验不仅能提升Agent的可用性和安全性,还能优化其在电商客服、智能家居等场景中的表现。题库采用动态难度系统,覆盖从基础到高级的开发挑战,是AI工程化落地的重要参考。

weixin_29057695的博客 342

P6955 [NEERC2017] Designing the Toy 题解

spj 提供者写的题解。

luogu_553625的博客 182

python等级考试——一级知识点汇总(不包含turtle画图)

本篇文章是针对中国电子学会青少年编程等级考试的,适合初学者以及青少年编程学习者

weixin_65350557的博客 9025

2017 NEERC

2017 NEERC Problem A. Archery Tournament 题目描述:在二维平面上,会陆续出现一些圆,以及一些询问,询问点是否在圆内,如果是,则输出那个圆,并把那个圆删掉,否则输出\(-1\)。注意:这些圆均与\(x\)轴相切,并且这些圆不会相交。 solution 因为这些圆都与\(x\)轴相切,所以经过直线\(x=x'\)的圆不会超过\(log\)个。所以只要找...

diebenger6280的博客 326

VFH避障/局部路径规划算法

VFH避障/局部路径规划算法 本文章是我看《The Vector Field Histogram-Fast Obstacle Avoidance for Mobile Robots》论文时候的笔记,感兴趣的欢迎去看原论文。 VFH中有一些概念是从其他算法中借鉴过来的,并且VFH算法本身就是对VFF(Virtural Force Field)的一种改进,其中有很多的相似之处。所以按照原论文的思路,先介绍由CMU提出的Certainty Grid算法中的一些概念,再介绍一下势场法中的一些概念,接着介绍一下VFF

qq_41845878的博客 8116

用 Message Monitoring Overview 打造接口健康驾驶舱:SAP AIF 消息监控实战解析

究竟解决了什么痛点?概括起来,这个应用把SAP AIF的接口监控,从传统的事务码和技术视角,带到了一个更加直观、业务友好的层次:(通过卡片式总览,让你在一个页面上看到所有自己负责的接口及其健康状况。通过和的联动,实现了从接口态势到具体消息的快速钻取。通过Recipient模型和应用,实现了监控职责的灵活分配。借助拖拽排序、搜索过滤等特性,让每个运维人员都可以打造属于自己的接口健康 cockpit。如果你正在做S/4HANA或项目,无论是公有云还是本地部署,只要系统启用了SAP AIF。

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

CTF题目记录7

Questionnaire 叮您有一份调查问卷请查收~ https://forms.gle/Vmzt99LazrtXsRLM9 这题要翻墙= =所以我瞟一下源码好了 没见过的f12题 拼成flag null,null,null,null,[["1vV5T8FOS13NOQDji-xYIynLwsUMXcV8aatxUWP6ljvfz-w",null,[740,416,0] ] ] ] ,[603160739,"What is the name of the store?",null,0,[[53905431

kkzzjx 1503

WOFOST作物模型(3):敏感性分析

使用TAGP(Total Above Ground Production),地上总产量TSUM1,temperature sum from emergence to anthesis,萌发至开花所需温度TSUM2,temperature sum from anthesis to maturity,开花至成熟所需温度SPAN,life span of leaves growing at 35 Celsius,生长温度为35度时的叶龄。

所有专家都曾始于新手 1145

Gym 101630G The Great Wall

题意: 三个有n个正整数的数组满足a[i]&lt;b[i]&lt;c[i],固定一个r,根据不同的x,y生成不同的数列,每对合法的x,y(x&lt;y)生成两个区间[x,x+r-1],[y,y+r-1],合法指生成的区间不会越界,如果一个点i被两个区间覆盖,他的值就是c[i],如果被一个覆盖就是b[i],否则a[i],一个数列的价值等于所有点的值之和,问在所有x,y生成的序列中价值第k大的是多少...

lych4o的博客 651

一文讲透 SAP VDM 命名里的前缀与后缀:看懂 I_、C_、A_,把 CDS 视图栈搭得又稳又好用

SAP S/4HANA 的 CDS 视图命名规范解析 摘要:本文详细解析 SAP S/4HANA 中 CDS 视图的 VDM 命名规范。通过前缀(如 I_、C_、R_)区分视图层级,后缀标记附加角色,结合 @VDM.viewType 注解形成完整语义体系。I_作为稳定接口层,C_面向特定场景裁剪,R_限定应用域内复用,A_提供远程 API 接口。命名规范使团队能快速识别视图用途、依赖关系和扩展边界,确保模型长期可维护性。文章结合制造业物料主数据、Fiori 应用等实际案例,说明如何通过规范命名构建清晰的视图

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

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

The Great Wall II[dp/单调栈优化]

那么接下来就是正题。,然后对于每一个j来说,dp【p】【j】都是可以提前计算出来的,而对于i,i增大时,后面那个值是不递减的,只会变得更大或者不变,而对于决策p来说,后面的值是不递增的,这样我们就可以大大缩小我们的决策范围,如果dp【p】【j-1】比前一个小,那么势必比前一个决策更优,反之比它大,由于maxx的对p不递增性,是无法保证哪一个更优的,而每一个i+1实际上只是比i多了dp【i】【j-1】项,因此我们就可以据此优化我们的dp。)个数,求分成k段的最小代价,每一段的代价等于这一段数组的最大值。

weixin_62887323的博客 496

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

2018鹏程杯 初赛 Writeup

1.签到 公众号回复 2.Traffic Light misc stegsolve打开看可以发现1000多帧 网上找了个脚本分离所有帧(python3+PIL) 根据红黄绿信号猜测0 1 空格 可以图像识别 但细心点可以发现文件大小并不相同 于是根据图像大小得到一串数字 相应的图片做一个映射即可 3.Quotes misc 脑洞题 My+mission+in+life+is+not+mer ely...

CODER的博客 2378

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

NEERC 17 G.The Great Wall

NEERC 17 G.The Great Wall Solution 这题的第一步tricktricktrick是:我们注意到取a,b,ca,b,ca,b,c的集合两两不交且并集为UUU,因此确定了b,cb,cb,c之后可以简单地唯一确定aaa,于是我们通过让bi−=ai,ci−=ai,Ans+=∑aib_i-=a_i,c_i-=a_i,Ans+=\sum a_ibi​−=ai​,ci​−=ai​,Ans+=∑ai​来削减一维。 然后令bi′=∑j=1ibib'_i=\sum_{j=1}^ib_ibi′​=

xmr_pursue_dreams的博客 321

The Great Wall I (zoj 3475 最小割最大流)

题意:n*m的地图,现在上面有X国家和一些联盟国要共同抵御E国,X国要建长城,有一些国家联盟进来并出一定费用,每条边都有一个建造费用,告诉每个国家的坐标和参加联盟的国家出的费用,问X国怎样建可以使费用最小,输出最小费用。 思路:这一类题目在图中把点分成两部分可以用最小割求解,图中的一条边就表示以改变为公共边的两个点之间有弧,添加源点和汇点,枚举哪些国家在长城内,将源点与这些国家连边,E和边界与汇点连边。这样求一遍最大流,选择了某条边为割边就表示方格中两个格子间的那条围墙被选择了。

@you! 1091

Gym - 101630G The Great Wall (二分+线段树) (2017–2018, NEERC – Northern Eurasia Finals)

  解题思路:首先求第k小的答案,通常套路都是二分答案,然后判断有多少个答案比他小即可。 关键在于如何高效的判断有多少个答案比他小,如果我们把所有答案预处理出来,复杂度是N^2级别的,但是我们不必把所有答案都预处理出来,我们只需要知道有多少个比他小即可。因此我们可以通过各种数据结构,高效的查询有多少个比他小即可。这样复杂度就可以去到NLogN了。这里需要巧妙地转化,使得可以在O(NlogN...

LP_Cong 669

NEERC 17 I Interactive Sort (交互题)

题意: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;给出1到n这n个数的任意一个排列,然后奇数按顺序分到o数组,偶数按顺序分到e数组,你每次可以询问e数组中第i个和o数组中第j个的大小情况,查询结束后输出结果,查询次数最多30 000次,n≥1000n≥1000n\ge1000 思路: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;我...

Roll_Keyboard的博客 705

Codeforces 85D. Sum of Medians (线段树)

题意: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 三种操作,1.加入一个数,2,删除一个数,3,询问经过排序以后,所有下标mod5mod5mod5余3的数的和 思路: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 注意到,当我们加入一个数以后,会让所有后面的数后移一位,删除会使得后面全部前移一位,每次移动都使得下标变化1,所以我...

Roll_Keyboard的博客 652

Codeforces Round #437 (Div. 2) B. Save the problem!

题意:给你一个数字A,要你给出一个价格和一堆硬币种类,要让这些硬币组成这个价格的方案数为A思路:想了很久没想出来,答案是除了A是1的时候,价格都是2*(A-1),硬币只有1和2,因为,你用(A-1)个2元0个1元,然后是(A-2)个2个1元,这样方案数就相当于A-1减到0,共A种,真的有点巧妙。。。错误及反思:其实自己写个完全背包打表也许能看出规律吧,可惜完全没往这个方向想代码:#include<b

Roll_Keyboard的博客 634

Codeforces Round #104 (Div. 1) E. Lucky Queries (线段树)

题意: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 长度为n的47串,两种操作,一种是区间变换,即4变7,7变4,一种是询问,问最长的非严格递增子序列长度 思路: &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 线段树维护即可,47可以抽象成01串,变换就是异或,存储全0串最长长度,全1串最长长度,000..111串长度,111…0...

Roll_Keyboard的博客 564

NEERC 17 L Laminar Family (树链剖分)

题意: &nbsp;&nbsp;&nbsp;&nbsp; 给你一颗树,每次选取一个路径,把路径上的所有点加入到一个集合里面,问最后的集合是否两两之间满足 A∈BA∈B A\in B 或者B∈AB∈AB\in A或者A∪B=∅A∪B=∅A\cup B = \emptyset 思路: &nbsp;&nbsp;&nbsp;&nbsp;我们发现,如果最后是符合条件的,那么必定是一个集合被另一个集合...

Roll_Keyboard的博客 549
上一篇: NEERC 17 I Interactive Sort (交互题)
下一篇: treap入门题目集合(附模板)
Roll_Keyboard
博客等级 码龄9年 10粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值