当前位置:网站首页>Codeforces 1637 B. mex and array - reading, violence
Codeforces 1637 B. mex and array - reading, violence
2022-06-12 13:32:00 【Tianyi City*】
The question :
Give you a length of n Array of a. Ask you the value and maximum of all its sub segments .
value :
Divide an array into sections , The value of each interval is the length of the interval + In this range MEX. The value of an array is the sum of the values of all intervals .
Answer key :
this tnd I read the topic for half a day .
Since we need to find the maximum , Let's see if it's better to divide into multiple intervals , Let's let the MEX Bigger and better . for instance :
0 1 2 3 4
Does this look like an interval MEX The largest is probably the best ? The answer is interval numbers 1+ Section MEX5=6
What if an interval has only one number ? That is interval number 5+ Section MEX{1,0,0,0,0}=6
It looks the same .
Let's think about this problem : Suppose the current interval length is x, If you move one space to the right , Is it better to become a new section or let MEX May be +1 good .
We can find out ,MEX once +1, That means interval numbers don't +1, If the interval number +1,MEX Won't +1.
however MEX We have to verify it , Very tired, . So it's better to direct a number to an interval .
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int z=0;
for(int j=i;j;j--){
z+=a[j]==0;
ans+=i-j+1+z;
}
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
- list和dict的应用
- Encryptor and client authenticate with each other
- Cocoapods的相关知识点
- It is enough to read this article. Web Chinese development
- Implementing pytorch style deep learning framework similartorch with numpy
- Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- 一种快速创建测试窗口的方法
- import torch_ Geometric loads some common datasets
- 1003: align output
猜你喜欢

leetcode 47. Permutations II full permutations II (medium)

简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链

torch_ geometric message passing network

一种快速创建测试窗口的方法

Semantic segmentation with pytorch

xcode 调试openGLES

The goods are full. You must take this knowledge
![[embedded] serial communication and its case](/img/5c/2e691e5ef03c7d65fd514e8b940e7b.jpg)
[embedded] serial communication and its case

Pytorch to onnx, onnxruntime reasoning in mmclas

Qualcomm platform development series (Protocol) QMI brief introduction and usage
随机推荐
imagemagick:a gentle introduction to magick++
开发中使用的语言技巧
Successfully rated Tencent t3-2, 10000 word parsing
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
C language [23] classic interview questions [2]
torch_geometric message passing network
jupyternotebook有汉字数据库吗。在深度学习中可以识别手写中文吗
Redis消息队列重复消费问题
2063: [example 1.4] cattle eat grass
[brush title] probability of winning a draw
安装MySQL时出错,照着下面这个链接,做到cmd就不行了
Application of list and Dict
5V升压到12.6V的锂电池充电IC芯片方案FS4062B
手把手教你IDEA创建SSM项目结构
Pre research of image scanning tool
m1 pod install pod lint 失败解决方案
软件构造 03 正则表达式
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
import torch_ Geometric loads some common datasets
创新实训(十一)开发过程中的一些bug汇总