Gym - 101102D Rectangles (单调栈)】的更多相关文章

Given an R×C grid with each cell containing an integer, find the number of subrectangles in this grid that contain only one distinct integer; this means every cell in a subrectangle contains the same integer. A subrectangle is defined by two cells: t…
题目链接:https://cn.vjudge.net/problem/Gym-100971D 题目大意:给你n个城市的信息,每一个城市的信息包括坐标和人数,然后让你找每一个城市的父亲,作为一个城市的父亲具体满足的条件是:作为父亲的城市的坐标和当前城市的人数最多,,如果有多个满足的城市,则和原来的点相隔最近的作为父亲. 具体思路:首先,题目中说坐标和人数是不会有相同的值,所以我们对于每一个点,按照x轴进行排序之后,找出当前点的左边的第一个人数大于当前点的,然后再找出当前点的右边的第一个人数大于当前…
[Agc081F/At2699] 给出一个拥有 \(H\times W\) 个格子的棋盘,每个格子的颜色为黑色或白色. Snuke 可以进行任意次下列操作: 选择棋盘中的一行或一列,将这一行或一列的颜色翻转(黑变成白,白变成黑) Snuke 想知道,在他进行操作后,棋盘中最大的全黑矩形最大能为多少. 考虑 \(2\times 2\) 方格,当且仅当偶数个黑时,可以做成全黑 大矩形能做成全黑,当且仅当所有 \(2\times 2\) 子格都是偶数个黑 然后就是一个很朴素的单调栈求最大矩形了 注意到…
题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cell containing an integer, find the number of subrectangles in this grid that contain only one distinct integer; this means every cell in a subrectangle…
题目链接:http://codeforces.com/gym/101102/problem/D 题目大意:给你一个n*m的矩阵,矩阵里面的数值范围为[1,1e9].这个矩阵有一个值,如果相邻的多个数字是一样的,那么val += 他们的组合数,例如 1 1 1,那么就是val就是6. 问最后这个矩阵是val是多少? 思路: 我们固定右端点,先统计出上方有几个和他数值相同的数字,并把这个定义成这个位置的高,然后每次往统计以这个点为右下角的端点数即可.然后暴力右下角就是O(n*n) 我们发现,如果要每…
D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100971D Description standard input/output Announcement   Statements One-dimensional country has n cities, the i-th of which is…
Description One-dimensional country has n cities, the i-th of which is located at the point xi and has population pi, and all xi, as well as all pi, are distinct. When one-dimensional country got the Internet, it was decided to place the main server…
D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u One-dimensional country has n cities, the i-th of which is located at the point xi and has population pi, and all xi, as well as all pi, are distinct. Whe…
当时我的第一想法也是用单调栈,但是被我写炸了:我也不知道错在哪里: 看了大神的写法,用数组模拟的: 记录下单调递增栈的下标,以及每个数字作为最小值的最左边的位置. 当有数据要出栈的时候,说明栈里的数据已经不是最小了,右端点就是当前位置-1,那么就可以计算栈顶的元素所作的贡献:出栈完后,当前这个数字,他的最左边就是栈顶所能到达的位置:入栈: #include <bits/stdc++.h> using namespace std; + ; int a[maxn]; int stacks[maxn…
要求找出每个a[i],找到离他最近而且权值比它大的点,若距离相同,输出权利最大的那个 我的做法有点复杂,时间也要500+ms,因为只要时间花在了map上. 具体思路是模拟一颗树的建立过程,对于权值最大的那个,必须是-1,次大的那个,必须是pos_peo[mx]:就是最大人口的节点id. 然后维护一个单调的序列,记录当前有多少个位置加入了树.用个set保证单调性.小到大 把结构体按人口排序大到小,枚举没个城市,这样保证加入后,后面加入的直接找位置最短即可,人口最对的bigger than now的…