zoukankan      html  css  js  c++  java
  • 楼房重建

    https://www.lydsy.com/JudgeOnline/problem.php?id=2957

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 inline int read()
     5 {
     6     int x=0,f=1;char ch=getchar();
     7     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
     8     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
     9     return x*f;
    10 }
    11 
    12 /********************************************************************/
    13 
    14 const int maxn = 1e6+7;
    15 int n,m,sum,sz;
    16 //sum: kuai(s),  sz:   ge(s)/kuai
    17 int num[maxn];
    18 double k[maxn];
    19 double maxv[maxn];
    20 vector<double> see[500];
    21 int l[500],r[500];
    22 
    23 void makeblock()
    24 {
    25     memset(maxv,0,sizeof(maxv));
    26     sz=sqrt((double)n*1.05);
    27     for(sum=1;sum*sz<n;sum++)
    28     {
    29         l[sum]=(sum-1)*sz+1;
    30         r[sum]=sum*sz;
    31         for(int i=l[sum];i<=r[sum];i++) num[i]=sum;
    32     }
    33     l[sum]=sz*(sum-1)+1;
    34     r[sum]=n;
    35     for(int i=l[sum];i<=r[sum];i++) num[i]=sum;
    36 }
    37 
    38 void update(int a, int b)
    39 {
    40     double aa=a,bb=b;
    41     k[a]=bb/aa;
    42     maxv[num[a]]=0;
    43     see[num[a]].clear();
    44     double tmp=0;
    45     for(int i=l[num[a]];i<=r[num[a]];i++)
    46     {
    47         if(k[i]>maxv[num[a]])
    48         {
    49             maxv[num[a]]=k[i];
    50             see[num[a]].push_back(k[i]);
    51         }
    52     }
    53 }
    54 
    55 void query()
    56 {
    57     int ans=0;
    58     double tmp=0;
    59     for(int i=1;i<=sum;i++)
    60     {
    61         if(!see[i].empty())
    62         {
    63             ans+=see[i].end()-upper_bound(see[i].begin(),see[i].end(),tmp);
    64             tmp=max(tmp,maxv[i]);
    65         }
    66     }
    67     printf("%d
    ", ans);
    68 }
    69 
    70 int main(){
    71     n=read(),m=read();
    72     makeblock();
    73     while(m--)
    74     {
    75         int a, b;
    76         scanf("%d%d",&a,&b);
    77         update(a, b);
    78         query();
    79     }
    80 }
  • 相关阅读:
    2019年10月31日 万能异常
    2019年10月29日 异常处理
    2019年10月26日 复习
    爬虫时如何使用代理服务器
    爬虫时url中http和https的区别
    博客园如何自定义博客皮肤和主题
    Python发送QQ邮件
    Python中的XML
    持久化-pickle和shelve
    open()函数提示找不到file的解决办法
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9608072.html
Copyright © 2011-2022 走看看