zoukankan      html  css  js  c++  java
  • 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司

    1568: [JSOI2008]Blue Mary开公司

    Time Limit: 15 Sec  Memory Limit: 162 MB
    Submit: 602  Solved: 214
    [Submit][Status][Discuss]

    Description

    Input

    第 一行 :一个整数N ,表示方案和询问的总数。 接下来N行,每行开头一个单词“Query”或“Project”。 若单词为Query,则后接一个整数T,表示Blue Mary询问第T天的最大收益。 若单词为Project,则后接两个实数S,P,表示该种设计方案第一天的收益S,以及以后每天比上一天多出的收益P。

    Output

    对于每一个Query,输出一个整数,表示询问的答案,并精确到整百元(以百元为单位,例如:该天最大收益为210或290时,均应该输出2)。

    Sample Input

    10
    Project 5.10200 0.65000
    Project 2.76200 1.43000
    Query 4
    Query 2
    Project 3.80200 1.17000
    Query 2
    Query 3
    Query 1
    Project 4.58200 0.91000
    Project 5.36200 0.39000

    Sample Output

    0
    0
    0
    0
    0

    HINT

    约定: 1 <= N <= 100000 1 <= T <=50000 0 < P < 100,| S | <= 10^6 提示:本题读写数据量可能相当巨大,请选手注意选择高效的文件读写方式。

      

      一种特殊的线段树……

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 using namespace std;
     5 const int maxn=50010;
     6 struct Node{
     7     double a,b;
     8     Node(double a_=0.0,double b_=0.0){
     9         a=a_;b=b_;
    10     }
    11     double Val(int p){
    12         return a*p+b; 
    13     }
    14     int CmP(int l,int r,Node x){
    15         if(Val(l)>=x.Val(l)&&Val(r)>=x.Val(r))return 1;
    16         if(Val(l)<=x.Val(l)&&Val(r)<=x.Val(r))return -1;
    17         return 0;
    18     }
    19 }T[maxn<<2];
    20 
    21 double Query(int x,int l,int r,int g){
    22     if(l==r)return T[x].Val(l);
    23     int mid=(l+r)>>1;
    24     double ret=T[x].Val(g);
    25     if(mid>=g)return max(ret,Query(x<<1,l,mid,g));
    26     else return max(ret,Query(x<<1|1,mid+1,r,g));
    27 }
    28 
    29 void Modify(int x,int l,int r,Node p){
    30     int tmp=p.CmP(l,r,T[x]);
    31     if(tmp==1)T[x]=p;
    32     if(tmp!=0)return;
    33     int mid=(l+r)>>1;
    34     
    35     tmp=p.CmP(l,mid,T[x]);
    36     if(tmp!=1&&l!=r)Modify(x<<1,l,mid,T[x]);
    37     if(tmp!=-1&&l!=r)Modify(x<<1,l,mid,p);
    38     tmp=p.CmP(mid+1,r,T[x]);
    39     if(tmp!=1&&l!=r)Modify(x<<1|1,mid+1,r,T[x]);
    40     if(tmp!=-1&&l!=r)Modify(x<<1|1,mid+1,r,p);
    41 }
    42 
    43 char op[10];
    44 int main(){
    45     int Q,p,n=50000;
    46     double s,t;
    47     scanf("%d",&Q);
    48     while(Q--){
    49         scanf("%s",op);
    50         if(!strcmp(op,"Project")){
    51             scanf("%lf%lf",&s,&t);
    52             Modify(1,1,n,Node(t,s-t));
    53         }
    54         else{
    55             scanf("%d",&p);
    56             printf("%d
    ",(int)(Query(1,1,n,p)/100));
    57         }
    58     }
    59 }
    尽最大的努力,做最好的自己!
  • 相关阅读:
    Discovery Scanning
    Openvas
    Common Vulnerability Scoring System CVSS
    NIagara Workbench ( 温度控制)
    Nikto and whatweb
    Jace Config
    Active information gathering-services enumeration
    Intsall The Nessus in you kali linux
    Source Code Review
    Niagara workbench (Basic )
  • 原文地址:https://www.cnblogs.com/TenderRun/p/5580070.html
Copyright © 2011-2022 走看看