题目传送门//res tp nowcoder 分析 定理:B1~B2当且仅当B1与B2有同构的笛卡尔树. (B₁~B₂ iff B₁ and B₂ have isomorphic Cartesian trees.) 对A与B同时构建小根堆性笛卡尔树,每次同时插入结点时,判断是否同构即可. #include<iostream> #include<cstdio> using namespace std; const int L = 100010; int a[L],b[L],u[L],…
传送门 J-Counting Triangles_2021牛客暑期多校训练营3 (nowcoder.com) 题目 Goodeat finds an undirected complete graph with n vertices. Each edge of the graph is painted black or white. He wants you to help him find the number of triangles (a, b, c) (a < b < c), such…
E Find the median 题意:每次往序列中增加连续的[l,r]的数,每加入一次就询问当前序列的中位数. 解法:此题没有要求在线,那么直接离线+线段树+二分就可以了.求出每个端点之后排序得到数组b,线段树每个叶子结点i存储的是区间[ b[i-1]+1,b[i] ]的系数(即当前序列有多少个[ b[i-1]+1,b[i] ]).修改时顺便维护当前总的数个数sum,然后处理询问就是直接在线段树上二分就可以了. #include<bits/stdc++.h> #define lc o*2…
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1≤l≤r≤mwhere RMQ(w,l,r)RMQ(w,l,r) denotes the inde…
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them into either red team or white team such that each team consists of exactly N people and the total competitive value is maximized. Total competitive va…
链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Amy asks Mr. B problem D. Please help Mr. B to solve the following problem. Amy wants to crack Merkle–Hellman knapsack…
链接:https://ac.nowcoder.com/acm/contest/886/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Rowlet is playing a very popular game in the pokemon world. Recently, he has encountered a problem and wants to ask for…
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if R M Q ( u ,…
链接:https://ac.nowcoder.com/acm/contest/888/E来源:牛客网 Gromah and LZR have entered the fifth level. Unlike the first four levels, they should do some moves in this level. There are nn_{}n vertices and mm_{}m bidirectional roads in this level, each road…
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1≤l≤r≤m where RMQ(w,l,r)RMQ(w,l,r) denotes the index of…
题意 给一个\(n*m\)的01矩阵,找有多少个全1子矩阵不被其他全1子矩阵包括. 分析 用单调栈找到的全1子矩阵是不能向上扩展和向右扩展的,只需判断该子矩阵能否向左和向下扩展,若四个方向都不能扩展,则该矩阵合法.是否能向左扩展可用预处理出的左边一列的高度是否大于等于该子矩阵的高度判断,是否能向下扩展可用前缀和判断下面一段是否全1. Code #include<bits/stdc++.h> #define fi first #define se second #define pb push_b…
F.Partition problem 传送门 题意:有2n个人,分两组,每组n个,要求sum(vij)最大值. 题解:n并不大我们可以枚举每个人是在1组还是2组爆搜. 代码: #include <bits/stdc++.h> #define ll long long using namespace std; + ; int n,a[N],b[N]; ll v[N][N],ans = ,cnt1=,cnt2=; void dfs(int x,ll sum) { if (cnt1>n||c…