• NOIP 模拟 $38; m a$


    题解 (by;zjvarphi)

    压行。

    枚举两行,将中间的行压成一行,然后直接前缀和加二分。

    注意边界细节问题。

    Code
    #include<bits/stdc++.h>
    #define Re register
    #define ri Re signed
    #define p(i) ++i
    namespace IO{
        char buf[1<<21],*p1=buf,*p2=buf;
        #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++
        struct nanfeng_stream{
            template<typename T>inline nanfeng_stream &operator>>(T &x) {
                Re bool f=0;x=0;Re char ch=getchar();
                while(!isdigit(ch)) f|=ch=='-',ch=getchar();
                while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
                return x=f?-x:x,*this;
            }
        }cin;
    }
    using IO::cin;
    namespace nanfeng{
        #define FI FILE *IN
        #define FO FILE *OUT
        template<typename T>inline T cmax(T x, T y) {return x>y?x:y;}
        template<typename T>inline T cmin(T x, T y) {return x>y?y:x;}
        typedef long long ll;
        static const int N=5e4+7;
        int mat[33][N],sum[33][N],pre[N],n,m,l,r;
        char s[N];
        ll ans;
        inline int main() {
            //FI=freopen("nanfeng.in","r",stdin);
            //FO=freopen("nanfeng.out","w",stdout);
            cin >> n >> m;
            for (ri i(1);i<=n;p(i)) {
                scanf("%s",s+1);
                for (ri j(1);j<=m;p(j)) mat[i][j]=s[j]=='1',sum[i][j]=sum[i-1][j]+mat[i][j];
            }
            cin >> l >> r;
            for (ri i(1);i<=n;p(i)) 
                for (ri j(1);j<=i;p(j)) 
                    for (ri k(1);k<=m;p(k)) {
                        pre[k]=pre[k-1]+sum[i][k]-sum[j-1][k];
                        if (pre[k]<l) continue;
                        int le=pre[k]-l;
                        int nm=std::upper_bound(pre,pre+k,le)-pre;
                        --nm;
                        ans+=nm+1;
                        if (pre[k]<=r) continue;
                        int re=pre[k]-r;
                        nm=std::lower_bound(pre,pre+k,re)-pre;
                        ans-=nm;
                    }
            printf("%lld
    ",ans);
            return 0;
        }
    }
    int main() {return nanfeng::main();}
    
  • 相关阅读:
    JQ_浏览器窗口改变触发
    5. 通过PHP反序列化进行远程代码执行
    2. 文件包含(150)
    1. md5 collision(50)
    4.xpath注入详解
    2.HTTP头注入
    1.5 xss漏洞修复
    1.4 DVWA亲测XSS漏洞
    1.如何绕过WAF(Web应用防火墙)
    1.3 xss原理分析与剖析(4)
  • 原文地址:https://www.cnblogs.com/nanfeng-blog/p/15139141.html
Copyright © 2020-2023  润新知