题目传送门//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],…
题目传送门//res tp nowcoder 目的 给定n*m 01矩阵,求矩阵内第二大矩形 分析 O(nm)预处理01矩阵为n个直方图,问题转换为求n个直方图中的第二大矩形.单调栈计算,同时维护前二大的面积即可. 对于XY的矩阵,我们只需考虑X Y,X * (Y-1),(X-1) * Y即可 #include<iostream> #include<algorithm> #include<stack> using namespace std; typedef long…
题目传送门//res tp nowcoder dfs 先将所有人都归于一队,之后从一队中取出人放置到另一个队. #include<iostream> #include<cstdio> #include<vector> using namespace std; typedef long long ll; int n; const int L = 30; ll a[L][L]; ll sum[L]; ll ans; vector<int>v; void dfs(…
layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" catalog: true tags: mathjax: true - ACM-ICPC 题意 给你两个由数字组成的字符串\(S\),\(T\) 长度为\(1e3\),问你S中有多少个子序列的值大于字符串T: 思路 首先在比赛的时候一眼确定是\(N^2\) 复杂度的DP,但是想了两三个小时却没想到怎么转移,各种…
传送门 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…
题意 给定两个$n$个元素的数组$a,b$,它们的前$p$个元素构成的数组是"等价"的,求$p$的最大值."等价"的意思是在其任意一个子区间内的最小值相同. $[link]$ 分析 这题有两种做法,笛卡尔树和单调栈,这里暂且只介绍单调栈的做法. 我们先假设$p=i$成立,考虑新加进来的$i+1$,如果以$i+1$为右端点构成的所有区间最小值相同,那么$p$就可以更新为$i+1$(这样的话就可以通过小区间的最小值位置相同依次证明大区间的最小值位置相同).或者换句话说,…
题意 给出n个数组(每组数个数不定),m个询问 l, r, x 序号在区间\([l,r]\)的每个数组是否都可以取出任意个数异或出x 题解 判断一个数组能否异或出x,是简单的线性基问题 判断多个线性基能否异或出x只需求出这些线性基的交,在交线性基上判断能否异或出x,多个线性基的交一定能被每个线性基分别表示,利用线段树维护区间线性基交就行,线性基求交模板是牛客上扒的咖啡鸡的 代码 #include <bits/stdc++.h> using namespace std; const int mx…
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才mod下没有二次剩余,所以不能这么做了.可以分解mod,然后利用循环节搞. zoj: #include <bits/stdc++.h> using namespace std; typedef long long LL; ; ; LL fac[N],A[N],B[N]; void Init() {…
链接: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/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 Bobo knows that ∫ ∞ 0 1 1 x 2 d x = π 2 . ∫0∞11+x2 dx=π2. Given n distinct positive integers a 1 , a 2 , -…