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

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn=1e5+5;
     4 struct A
     5 {
     6     int x;
     7     double w;
     8 }maxx[maxn];
     9 int n,m;
    10 bool mark[maxn];
    11 template<class t>void red(t &x)
    12 {
    13     int w=1;
    14     x=0;
    15     char ch=getchar();
    16     while(ch>'9'||ch<'0')
    17     {
    18         if(ch=='-')
    19             w=-1;
    20         ch=getchar(); 
    21     }
    22     while(ch>='0'&&ch<='9')
    23     {
    24         x=(x<<3)+(x<<1)+ch-'0';
    25         ch=getchar();
    26     } 
    27     x*=w;
    28 } 
    29 void input()
    30 {
    31     freopen("input.txt","r",stdin);
    32 }
    33 void update(int l,int r,int z,int x,int y)
    34 {
    35     if(l==r&&l==x)
    36     {
    37         maxx[z].w=y/x;
    38         maxx[z].x=x;
    39         return;
    40     }
    41     int j=(l+r)>>1;
    42     if(x<=j)
    43         update(l,j,z<<1,x,y);
    44     else    
    45         update(j+1,r,z<<1|1,x,y);
    46     if(maxx[z<<1].w<maxx[z<<1|1].w) 
    47         maxx[z]=maxx[z<<1|1];
    48     else
    49         maxx[z]=maxx[z<<1];
    50 }
    51 int f(int x) 
    52 {
    53     int ans=0;
    54     for(int i=1;i<x;++i)
    55         ans+=mark[i]?0:1;
    56     return ans;
    57 }
    58 int main()
    59 {
    60     //input();
    61     red(n);
    62     red(m);
    63     int x,y;
    64     for(int i=1;i<=m;++i)
    65     {
    66         red(x);
    67         red(y);
    68         if(y)
    69             mark[x]=1;
    70         if(!y&&mark[x])
    71             mark[x]=0;
    72         update(1,n,1,x,y);
    73         printf("%d
    ",maxx[1].x-f(maxx[1].x));
    74     }
    75     return 0;
    76 }
    没动脑子瞎打10分
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn=4e5+5;
     4 struct A
     5 {
     6     int s;
     7     double h;
     8 }maxx[maxn];
     9 int n,m;
    10 template<class t>void red(t &x)
    11 {
    12     int w=1;
    13     x=0;
    14     char ch=getchar();
    15     while(ch>'9'||ch<'0')
    16     {
    17         if(ch=='-')
    18             w=-1;
    19         ch=getchar(); 
    20     }
    21     while(ch>='0'&&ch<='9')
    22     {
    23         x=(x<<3)+(x<<1)+ch-'0';
    24         ch=getchar();
    25     } 
    26     x*=w;
    27 } 
    28 void input()
    29 {
    30     freopen("input.txt","r",stdin);
    31 }
    32 int query(int l,int r,int z,int h)
    33 {
    34     if(maxx[z].h<=h)
    35         return 0;
    36     if(l==r)
    37         return maxx[z].h>h;
    38     int j=(l+r)>>1;
    39     if(maxx[z<<1].h<=h)
    40         return query(j+1,r,z<<1|1,h);
    41     return query(l,j,z<<1,h)+maxx[z].s-maxx[z<<1].s;
    42 }
    43 void update(int l,int r,int z,int x,int y)
    44 {
    45     if(l==r&&l==x)
    46     {
    47         maxx[z].h=(double)y/x;
    48         maxx[z].s=1;
    49         return;
    50     }
    51     int j=(l+r)>>1;
    52     if(x<=j)
    53         update(l,j,z<<1,x,y);
    54     else    
    55         update(j+1,r,z<<1|1,x,y);
    56     maxx[z].h=max(maxx[z<<1].h,maxx[z<<1|1].h);
    57     maxx[z].s=maxx[z<<1].s+query(j+1,r,z<<1|1,maxx[z<<1].h);
    58 }
    59 int main()
    60 {
    61     input();
    62     red(n);
    63     red(m);
    64     int x,y;
    65     for(int i=1;i<=m;++i)
    66     {
    67         red(x);
    68         red(y);
    69         update(1,n,1,x,y);
    70         printf("%d
    ",maxx[1].s);
    71     }
    72     return 0;
    73 }
    蜜汁打挂70分

    query里忘记改double了

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn=4e5+5;
     4 struct A
     5 {
     6     int s;
     7     double h;
     8 }maxx[maxn];
     9 int n,m;
    10 template<class t>void red(t &x)
    11 {
    12     int w=1;
    13     x=0;
    14     char ch=getchar();
    15     while(ch>'9'||ch<'0')
    16     {
    17         if(ch=='-')
    18             w=-1;
    19         ch=getchar(); 
    20     }
    21     while(ch>='0'&&ch<='9')
    22     {
    23         x=(x<<3)+(x<<1)+ch-'0';
    24         ch=getchar();
    25     } 
    26     x*=w;
    27 } 
    28 void input()
    29 {
    30     freopen("input.txt","r",stdin);
    31 }
    32 int query(int l,int r,int z,double h)
    33 {
    34     if(l==r)
    35         return maxx[z].h>h;
    36     int j=(l+r)>>1;
    37     if(maxx[z<<1].h<=h)
    38         return query(j+1,r,z<<1|1,h);
    39     return query(l,j,z<<1,h)+maxx[z].s-maxx[z<<1].s;
    40 }
    41 void update(int l,int r,int z,int x,int y)
    42 {
    43     if(l==r&&l==x)
    44     {
    45         maxx[z].h=(double)y/x;
    46         maxx[z].s=1;
    47         return;
    48     }
    49     int j=(l+r)>>1;
    50     if(x<=j)
    51         update(l,j,z<<1,x,y);
    52     else    
    53         update(j+1,r,z<<1|1,x,y);
    54     maxx[z].h=max(maxx[z<<1].h,maxx[z<<1|1].h);
    55     maxx[z].s=maxx[z<<1].s+query(j+1,r,z<<1|1,maxx[z<<1].h);
    56 }
    57 int main()
    58 {
    59     input();
    60     red(n);
    61     red(m);
    62     int x,y;
    63     for(int i=1;i<=m;++i)
    64     {
    65         red(x);
    66         red(y);
    67         update(1,n,1,x,y);
    68         printf("%d
    ",maxx[1].s);
    69     }
    70     return 0;
    71 }
    100分
  • 相关阅读:
    Ubantu 安装Redis
    传说中的WCF(5):数据协定(a)
    传说中的WCF(4):发送和接收SOAP头
    传说中的WCF(3):多个协定
    传说中的WCF(2):服务协定的那些事儿
    传说中的WCF(1):这东西难学吗?
    Linq教程
    Installutil.exe的位置和路径
    uni-app中对输入框的判断与提示(密码格式为6-12位,必须有大小写字母和数字组成)
    uni-app系列回顾总结----项目国际化
  • 原文地址:https://www.cnblogs.com/Achensy/p/11008231.html
Copyright © 2011-2022 走看看