zoukankan      html  css  js  c++  java
  • 4056 hdu4866 Shooting

    题目描述

    In the shooting game, the player can choose to stand in the position of [1, X] to shoot, you can shoot all the nearest K targets. The value of K may be different on different shootings. There are N targets to shoot, each target occupy the position of [Li, Ri] , the distance from the starting line is Di(1<=i<=N). Shooting a target can get the bonus points equal to the distance to the starting line. After each shooting targets still exist. Additional, if the previous bonus points is more than P, then as a reward for the shooting present bonus points doubled(and then check the next one). Player wants to know the bonus points he got in each shot.

    输入

    The input consists several test cases.
    The first line has two integers, N, M, X, P(1<=N, M ,X<=100000, P<=1000000000), N represents the total number of target shooting, M represents the number of shooting.
    The next N lines of three integers L, R, D (1<=L<=R<=X, 1<=D<=10000000), occupy the position of [L, R] and the distance from the starting line is D.
    The next M lines, each line contains four integers x, a, b, c (1<=x<=X, 0<=a,b<=N, 1<=c<=10000000), and K = ( a * Pre + b ) % c. Pre is the bonus point of previous shooting , and for the first shooting Pre=1. It denotes standing in the position x and the player can shoot the nearest K targets.

    输出

    Output M lines each corresponds to one integer.

    样例输入

    4 3 5 8
    1 2 6
    2 3 3
    2 4 7
    1 5 2
    2 2 1 5
    3 1 1 10
    4 2 3 7

    样例输出

    11
    10
    18


    呼呼呼临走前终于弄出来了,又一道主席树
    总之就是维护X棵线段树的感觉,每条线段拆成添加和修改两个操作
    如果同一个位置有多个操作的话rt数组就记录做完最后那一次的
    不过这题还有别的做法
    用两颗主席树去做,一颗负责在加入时加入,一颗负责在删除时加入
    这样的话利用可减性,用第一颗减去第二颗就是实际的树了
    我比较懒啊,写的第一种算法,不过总感觉有点鬼。。。
    为什么跟我的同学比我校平台上我比较快,而hdu上我就被卡成TLE他就A了???
    இ௰இ
     1 #include<cstdio>
     2 #include<algorithm>
     3 #define ll long long
     4 using namespace std;
     5 int N,M,X,P,tot,siz,st;
     6 int rt[100005];
     7 struct node{
     8     int l,r,s;
     9     ll sum;
    10 }t[2000005];
    11 struct mmove{
    12     int x,opt;
    13     ll sum;
    14 }g[200005];
    15 bool cmp(mmove A,mmove B){return A.x<B.x;}
    16 ll ds[100005],pre;
    17 int insert(int k,int x,int o,int l,int r){
    18     t[++tot]=t[k];k=tot;
    19     if(l==r){
    20         t[k].s+=o;
    21         t[k].sum+=ds[l]*o;
    22         return k;
    23     }
    24     int mid=(l+r)/2;
    25     if(x<=mid) t[k].l=insert(t[k].l,x,o,l,mid);
    26     else t[k].r=insert(t[k].r,x,o,mid+1,r);
    27     t[k].s=t[t[k].l].s+t[t[k].r].s;
    28     t[k].sum=t[t[k].l].sum+t[t[k].r].sum;
    29     return k;
    30 }
    31 ll query(int k,int x,int l,int r){
    32     if(l==r)return (t[k].s==0?0:(t[k].sum/t[k].s)*min(t[k].s,x));
    33     int mid=(l+r)/2;
    34     if(t[t[k].l].s>=x)return query(t[k].l,x,l,mid);
    35     else return t[t[k].l].sum+query(t[k].r,x-t[t[k].l].s,mid+1,r);
    36 }
    37 int main(){
    38     while(scanf("%d%d%d%d",&N,&M,&X,&P)!=EOF){
    39         pre=1;tot=0;
    40         t[0]=(node){0,0,0,0};
    41         for(int i=1;i<=N;i++){
    42             scanf("%d%d%lld",&g[i].x,&g[i+N].x,&ds[i]);
    43             g[i+N].x++;
    44             g[i].opt=1;g[i+N].opt=-1;
    45             g[i+N].sum=g[i].sum=ds[i];
    46         }
    47         sort(ds+1,ds+1+N);
    48         siz=unique(ds+1,ds+1+N)-ds-1;
    49         for(int i=1;i<=2*N;i++)
    50             g[i].sum=lower_bound(ds+1,ds+1+siz,g[i].sum)-ds;
    51         sort(g+1,g+2*N+1,cmp);
    52         st=1;
    53         for(int i=1;i<=X;i++){
    54             rt[i]=rt[i-1];
    55             while(st<=2*N&&g[st].x==i){
    56                 rt[i]=insert(rt[i],g[st].sum,g[st].opt,1,N);
    57                 st++;
    58             }
    59         }
    60         for(int i=1,x,a,b,c,K;i<=M;i++){
    61             scanf("%d%d%d%d",&x,&a,&b,&c);
    62             K=(1ll*a*pre+b)%c;
    63             pre=query(rt[x],K,1,N)*(pre>P?2:1);
    64             printf("%lld
    ",pre);
    65         }
    66     }
    67 }
    View Code
  • 相关阅读:
    用 HTML 格式导出 Excel 时,如何保留显示网格线
    [转载] 让SciTE能够和IDE一样进行成员提示
    RedHat 上安装多个 mysql 实例并配置 django 连接的操作记录
    我的 SciTEGlobal.properties 配置文件
    FrameSet 不能支持透明
    RedHat 上安装 lighttpd 并配置 fastcgi + django 的记录
    系统设计与开发 辅助工具大集成终结版
    SQL Server Management Object(SMO)大大简化数据库工具的开发 几行代码开发功能强大的SQL工具
    Enterprise Solution 解决方案与源代码下载
    LLBL Gen 实体映射工具技术原理剖析
  • 原文地址:https://www.cnblogs.com/2017SSY/p/10182064.html
Copyright © 2011-2022 走看看