• [补]2019nowcoder牛客第三场F(暂且)


    红小豆以为自己迈出了历史性的一步,然而并没有_(:з」∠)_

    F  Planting Trees

      参考于:https://www.cnblogs.com/Dillonh/p/11247098.html

      虽然之前说过很多次但是还是要再说一遍:cin不仅跑得慢还跑得螺旋无敌飞天香蕉船慢!!!

      赛中快乐写悬线法,然而wa。。然后快乐ctrl c ctrl v 魔改,加了一堆同名不同用途的数组,还是wa。。

      写完单调队列之后,(糟糕,中间去打比赛打完忘了要说什么了qwq)哦ta是O(n^3)的,感觉像是左右两边的线其实还悬在那里,用队列维护上下边界的时候就不会像悬线法那样受到左右推移的影响。

      我就输入t的时候没改scanf,就快乐地t了。。快读板子是真地快

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    using namespace std;
    typedef long long LL;
    int m, n, t;
    int qi[505], qa[505];
    int mp[505][505], mi[507], ma[507];
     
    inline int rd()
    {
        int s = 0, w = 1; char ch = getchar();
        while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); }
        while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
        return s * w;
    }
     
    int main()
    {
        scanf("%d",&t);
        while (t--) {
            scanf("%d%d", &n, &m);
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                    scanf("%d", &mp[i][j]);
            int ans = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) { mi[j] = 0x3f3f3f3f; ma[j] = -0x3f3f3f3f; }
                for (int j = i; j <= n; j++) {
                    for (int k = 1; k <= n; k++) { mi[k] = min(mi[k], mp[k][j]);ma[k] = max(ma[k], mp[k][j]); }
                    int f1 = 0, f2 = 0, b1 = 0, b2 = 0;
                    int now = 0;
                    for (int k = 1; k <= n; k++) {
                        while (f1 != b1 && mi[k] <= mi[qi[f1]])f1--;
                        while (f2 != b2 && ma[k] >= ma[qa[f2]])f2--;
                        qi[++f1] = k;
                        qa[++f2] = k;
                        while(f1!=b1&&f2!=b2&&ma[qa[b2+1]]-mi[qi[b1+1]]>m)
                            if (qa[b2+1] > qi[b1+1]) {now = qi[b1 + 1];  b1++;}
                            else {now = qa[b2 + 1]; b2++;}
                        ans = max(ans, (j - i + 1) * (k - now));
                    }
                }
            }
            cout << ans << endl;
        }
    
        return 0;
    }
    Planting Trees

       今天依然是没能迈出历史性的一步的我

  • 相关阅读:
    将数组转换为对象
    react常见组件问题Can't perform a React state update on an unmounted component
    React定位到滚动条底部
    React使用定时器interval
    CSS 如何做到隐藏滚动条的同时可以滚动
    css实现字母或数字强制换行
    如何让div的滚动条在上下左右都出现
    js学习
    JavaScript介绍
    前端跨域
  • 原文地址:https://www.cnblogs.com/non-/p/11256276.html
Copyright © 2020-2023  润新知