首页 > 其他分享 >8.22 lb模拟赛

8.22 lb模拟赛

时间:2023-08-26 22:13:17浏览次数:30  
标签:lb cout int s2 eb inl 8.22 模拟 define

小寄() \(100+0+100+25\) \(rk9\)

\(T4\) 没开 \(long\ long\) 挂 \(25pts\) 实属不该

T1

当时看到字符串差点给跳过了() 结果是呆呆签到题

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mid (l+r>>1)
#define inl inline
#define eb emplace_back
#define ls p<<1
#define rs p<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r 
#define pii pair<int,int>
const int N = 1e5 + 5;
//char buf[1<<24] , *p1 , *p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<24,stdin),p1==p2)?EOF:*p1++)
#define getchar() cin.get();
int read()
{
	int x = 0 , f = 1;
	char ch = getchar();
	while ( !isdigit(ch) ) { if ( ch == '-' ) f = -1; ch = getchar(); }
	while ( isdigit(ch) ) { x = ( x << 1 ) + ( x << 3 ) + ( ch ^ 48 ); ch = getchar(); }
	return x * f ;
}

int n , m , ans[N] , a[N] , b[N];
string s1 , s2;

signed main ()
{
	freopen ( "love.in" , "r" , stdin );
	freopen ( "love.out" , "w" , stdout );
	ios::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	n = read() , m = read();
	cin >> s1; cin >> s2;
	while ( s2.size() < n ) s2 = s2 + s2;
	for ( int i = 1 ; i <= n ; i ++ ) a[i] = s1[i-1] - 'a' + 1 , b[i] = s2[i-1] - '0';
	for ( int i = 1 ; i <= n ; i ++ ) ans[i] = a[i] + b[i];
	for ( int i = 1 ; i <= n ; i ++ )
		cout << (ans[i]>26?(char)(ans[i]-26+'a'-1):(char)(ans[i]+'a'-1));
	cout << endl;
	return 0;
}


T2

博弈论 但是\(skip\)

T3

可以显然发现每一条重链的贡献就是重链的树高+轻链的贡献最大值

\(dp\) 即可

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mid (l+r>>1)
#define inl inline
#define eb emplace_back
#define ls p<<1
#define rs p<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r 
#define pii pair<int,int>
#define print(x) cout << #x << ' ' << x << endl 
const int N = 1e7 + 5;
char buf[1<<24] , *p1 , *p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<24,stdin),p1==p2)?EOF:*p1++)
//#define getchar() cin.get();
int read()
{
	int x = 0 , f = 1;
	char ch = getchar();
	while ( !isdigit(ch) ) { if ( ch == '-' ) f = -1; ch = getchar(); }
	while ( isdigit(ch) ) { x = ( x << 1 ) + ( x << 3 ) + ( ch ^ 48 ); ch = getchar(); }
	return x * f ;
}

int n , t[N] , fa[N] , son[N] , top[N] , len[N] , lg[N];

//vector<int>e[N];
//inl void add ( int u , int v ) { e[u].eb(v); }
int head[N] , cnt;
struct node { int to , nxt; } e[N];
inl void add ( int u , int v ) { e[++cnt] = { v , head[u] } , head[u] = cnt; }

void dfs2 ( int u , int tp , int &sz )
{
//	cout << u << ' ' << tp << ' ' << sz << endl;
//	cout << son[u] << endl;
	top[u] = tp , sz ++;
	if ( son[u] ) dfs2 ( son[u] , tp , sz );
	for ( int i = head[u] ; i ; i = e[i].nxt ) { int v = e[i].to; if ( v != fa[u] && v != son[u] ) dfs2 ( v , v , len[v] ); }
}

void dfs ( int u , int f )
{
	for ( int i = head[u] ; i ; i = e[i].nxt )
	{
		int v = e[i].to;
		if ( v ^ f )
		{
			dfs ( v , u );
			t[u] = max ( t[u] , t[v] );
		}
	} 
	if ( top[u] == u ) t[u] += lg[len[u]];
}

signed main ()
{
	freopen ( "aqua.in" , "r" , stdin );
	freopen ( "aqua.out" , "w" , stdout );
	ios::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	n = read();
	lg[0] = -1;
	for ( int i = 1 ; i <= n ; i ++ ) lg[i] = lg[(int)ceil((double)i/2)] + 1;
//	for ( int i = 1 ; i <= 16 ; i ++ ) cout << (int)ceil(log2(i))+1 << endl;
//	for ( int i = 1 ; i <= 16 ; i ++ ) cout << lg[i] << endl;
	for ( int i = 1 ; i <= n ; i ++ ) fa[i] = read() , add ( fa[i] , i );
	for ( int i = 1 ; i <= n ; i ++ ) son[i] = read();
	dfs2 ( 1 , 1 , len[1] );
//	for ( int i = 1 ; i <= n ; i ++ ) print(len[i]) , print((top[i]==i));
	dfs ( 1 , 0 );
	cout << t[1] << endl;
	return 0;
}


T4

\(50pts\) 就是维护差分数组和正常数组 区间修改区间(单点)查询即可

正解是 我们将第一个点(也就是 \((0,1)\) 这个点)赋值为 \(1\) 先递推出来整个矩阵

考虑在第 \(i\) 个位置上的修改 值为 \(val\) 的影响 最后的影响就是矩阵向右移动一个定长再乘上 \(val\)

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mid (l+r>>1)
#define inl inline
#define eb emplace_back
#define ls p<<1
#define rs p<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r 
#define pii pair<int,int>
#define print(x) cout<<#x<<' '<<x<<endl 
#define int long long
const int K = 100 + 5;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
//char buf[1<<24] , *p1 , *p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<24,stdin),p1==p2)?EOF:*p1++)
#define getchar() cin.get();
int read()
{
	int x = 0 , f = 1;
	char ch = getchar();
	while ( !isdigit(ch) ) { if ( ch == '-' ) f = -1; ch = getchar(); }
	while ( isdigit(ch) ) { x = ( x << 1 ) + ( x << 3 ) + ( ch ^ 48 ); ch = getchar(); }
	return x * f ;
}

int n , m , k , a[K][N] , pos[N] , val[N] , cnt;

int solve ( int x )
{
	int res = 0;
	for ( int i = 1 ; i <= cnt ; i ++ )
		if ( pos[i] <= x ) ( res += a[k][x-pos[i]+1] * val[i] ) %= mod;
	return res;
}

signed main ()
{
//	freopen ( "ruby.in" , "r" , stdin );
//	freopen ( "ruby.out" , "w" , stdout );
	ios::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	n = read() , m = read() , k = read();
	a[0][1] = 1;
	for ( int i = 1 ; i <= k ; i ++ )
		for ( int j = 1 ; j <= n ; j ++ )
			a[i][j] = ( a[i-1][j] + a[i][j-1] ) % mod;
	for ( int i = 1 , x , y ; i <= m ; i ++ )
	{
		int op = read();
		if ( op == 0 ) x = read() , y = read() , pos[++cnt] = x , val[cnt] = y;
		else x = read() , cout << solve(x) << endl;		
	}
	return 0;
}

标签:lb,cout,int,s2,eb,inl,8.22,模拟,define
From: https://www.cnblogs.com/Echo-Long/p/17659545.html

相关文章

  • m基于FPGA的多径信道模拟verilog实现,包含testbench,可配置SNR,频偏,多径增益和多径延
    1.算法仿真效果其中Vivado2019.2仿真结果如下:  2.算法涉及理论知识概要       瑞利分布是一个均值为0,方差为σ²的平稳窄带高斯过程,其包络的一维分布是瑞利分布。其表达式及概率密度如图所示。瑞利分布是最常见的用于描述平坦衰落信号接收包络或独立多径分量接受......
  • OpenSBI 中的 coolboot & warmboot
    coolboot&warmboot这里的coolboot和warmboot并不是传统意义上的热启动和冷启动,所以经常会造成误解。在OpenSBI的issue中,找到了以下对话:从这里的对话中我们可以清楚地得知,OpenSBI中的coolboot和warmboot不代表传统意义上的热启动和冷启动。而是“完全初始化”......
  • 学会Python Requests库+Cookies模拟自动登录!
    importrequestsurl="https://my.cheshi.com/user/"headers={"User-Agent":"Mozilla/5.0(Macintosh;IntelMacOSX10_15_7)AppleWebKit/537.36(KHTML,likeGecko)Chrome/116.0.0.0Safari/537.36"}res=requests.get(......
  • CSP模拟-30D
    [AGC019F]YesorNo我们可以试着把所有"最优策略的答题历程"放在一张网状图里。就像这样。(声明:我们默认\(n\geqm\))我们认为\((x,y)\)表示还剩\(x\)道答案为\(Yes\)的题,\(y\)同理.认为向左走为回答\(Yes\),向下为\(No\).然后你就会发现你啥也发现不了,答题的过程就......
  • [Lua] 实现所有类的基类Object、模拟单继承OO、实现抽象工厂
    所有类的基类ObjectLua没有严格的oo(Object-Oriented)定义,可以利用元表特性来实现先定义所有类的基类,即Object类。代码顺序从上到下,自成一体。完整代码定义一个空表Object,__index指向其自身(继承将直接使用该表作为对象的元表)Object={}Object.__index=Objectnew定......
  • 【MySQL 8.0】通过mysqlbinlog实现binlog文件的远程同步
    mysqlbinlog会伪装成一个slave,连接master请求指定的binlogfile,master接收到这个请求之后创建一个binlogdump线程推送binlog给伪装的slave。[mysql@node01~]$mysql-uroot-pabcd.1234-hnode01(root@node01)>createuserrepl@'%'identifiedby'repl';QueryOK,0ro......
  • VisionPro 工具调用和工具组(ToolBlock)调用
    VisionPro是Cognex的机器视觉算法软件,通常的做法是使用VS做二次开发。这里主要分享VisionPro中通过ToolBlock实现一个视觉检测,以及通过调用单个Tool实现一个视觉检测。最终实现一个硬币数量检测以及坐标位置输出的应用:使用ToolBlock的方式:声明CogToolBlock类型的实例,并且序列化......
  • 暑假集训D24 2023.8.22 contest I
    C.CityFolding题意:有一个由\(2^n\)条等长线段组成的线,你可以进行\(n\)次对折,可以从左向右对折或从右向左对折,给出初始时线段的编号\(P\),问如何对折\(n\)次才能使对折后该线段恰好在从下往上数第\(H\)层?\(\operatorname{Solution}\)构造可以倒过来考虑这个......
  • 系统内存管理:虚拟内存、内存分段与分页、页表缓存TLB以及Linux内存管理
    虚拟内存虚拟内存是一种操作系统提供的机制,用于将每个进程分配的独立的虚拟地址空间映射到实际的物理内存地址空间上。通过使用虚拟内存,操作系统可以有效地解决多个应用程序直接操作物理内存可能引发的冲突问题。在使用虚拟内存的情况下,每个进程都有自己的独立的虚拟地址空间,它......
  • 2019年牛客普及模拟赛5
    字符统计:给出一个只包含空格和小写字母的字符串,问出现次数最多的字符(多个字符按照字典序输出)签到题。#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;intsum[250];charans[250];signedmain(){ //freopen("T1.in","r",stdin); //freopen("T1.out"......