zoukankan      html  css  js  c++  java
  • hdu 6047

    题解:先对b排序,用一个数组预处理a,记录当前位置之后到n的最大值,然后在用一个变量维护新增变量的最大值,用的时候和前面的数组的最大值做一个比较就ok。

    AC代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    const int mod=1e9+7;
    int maxx[250001];
    int a[250001];
    int b[250001];
    int main()
    {
        cin.sync_with_stdio(false);
        int n;
        while(cin>>n)
        {
            for(int i=1;i<=n;i++) cin>>a[i];
            for(int j=1;j<=n;j++) cin>>b[j];
            int nmax=0;
            for(int i=n;i>=1;i--)
            {
                nmax=max(nmax,a[i]-i);
                maxx[i]=nmax;
            }
            sort(b+1,b+1+n);
            nmax=0;
            int sum=0;
            for(int i=1;i<=n;i++)
            {
                int temp=maxx[b[i]];
                temp=max(temp,nmax);
                nmax=max(nmax,temp-(i+n));
                sum=(sum+temp)%mod;
            }
            cout<<sum<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Web 呼起 APP
    移动端监测离开页面
    input 呼起数字键盘
    建站工具Hexo
    linux 查找并kill进程
    linux php --ini
    Git + BeyondCompare
    Linux连续执行多条命令
    chrome start.js报错
    emoji和utf8mb4字符集
  • 原文地址:https://www.cnblogs.com/z1141000271/p/7250347.html
Copyright © 2011-2022 走看看