• hdu 4747 Mex


    思路:分析知道sum(1,i) (1<=i<=n) 具有单调性。每次求出1-i之间的所有可能值,

    注意每次增加一个数时对结果的影响,用mp数组维护下就可以!!

    代码如下:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 #include<iomanip>
     5 #include<cmath>
     6 #include<cstring>
     7 #include<vector>
     8 #define ll __int64
     9 using namespace std;
    10 int a[200002],p[200002],mp[200002];
    11 int main()
    12 {
    13     int n,cnt;
    14     while(scanf("%d",&n)&&n){
    15             for(int i=1;i<=n;i++)
    16                   scanf("%d",&a[i]);
    17             ll now=0,pre;
    18             ll ans=0;
    19             memset(p,0,sizeof(p));
    20             memset(mp,0,sizeof(mp));
    21             for(int i=1;i<=n;i++){
    22                   if(a[i]<=n){
    23                         pre=p[a[i]];
    24                         p[a[i]]=i;
    25                         for(int j=a[i];j<=n;j++){
    26                               if(j) mp[j]=min(mp[j-1],p[j]);
    27                               else mp[j]=p[j];
    28                               if(mp[j]>pre){
    29                                     now+=mp[j]-pre;
    30                               }else break;
    31                         }
    32                   }
    33                   ans+=now;
    34             }
    35             printf("%I64d
    ",ans);
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    nuget
    C#枚举中使用Flags特性
    情感分析
    docker
    core部署
    脱壳系列_2_IAT加密壳_详细分析(含脚本)
    安全公司-* * * *-面试题:_ 安卓逆向分析分享
    18_ShadowWalker
    17_页面异常接管
    16_TLB与流水线
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3325154.html
Copyright © 2020-2023  润新知