• Codeforces Round #576 (Div. 2) D. Welfare State


    http://codeforces.com/contest/1199/problem/D

    Examples

    input1

    4
    1 2 3 4
    3
    2 3
    1 2 2
    2 1

    output1

    3 2 3 4 

    input2

    5
    3 50 2 1 10
    3
    1 2 0
    2 8
    1 3 20

    output2

    8 8 20 8 10 

    Note

    In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4

    In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10

    这题很简单 ,可以用线段树做,蒟蒻的我表示不会,只好再另找方法

    有两种操作:

    操作1(单点修改操作):将x位置处的值变为y

    操作2(更新修改操作):输入一个z值,将数组中所有小于z的都改为z

    如果没进行单点修改操作,后面更新修改操作的大值会覆盖掉前面更新修改操作的小值

    如果该数进行过单点修改操作,那么在该操作之前的操作对该数均无效,只有后面的更新修改操作会生效

    如果有10个操作数

    c数组形式可能为

    c1 c2 c3 c4 c5 c6 c7 c8 c9 c10

    9  9  9  7  7  3   2  2  0  0 

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <queue>
     8 #include <set>
     9 #include <math.h>
    10 const int INF=0x3f3f3f3f;
    11 using namespace std;
    12 #define maxn 200010
    13 
    14 int a[maxn];//存放数据
    15 int b[maxn];//存放单点修改操作的最后一次操作标号 
    16 int c[maxn];//存放更新修改操作,存要修改的值,下标为操作标号 
    17 
    18 int main()
    19 {
    20     int n;
    21     scanf("%d",&n);
    22     for(int i=1;i<=n;i++)
    23     {
    24         scanf("%d",&a[i]);
    25     }
    26     int q;
    27     scanf("%d",&q);
    28     for(int i=1;i<=q;i++)
    29     {
    30         int t;
    31         scanf("%d",&t);
    32         if(t==1) //单点修改操作 
    33         {
    34             int x,y;
    35             scanf("%d %d",&x,&y);
    36             a[x]=y;//直接改值
    37             b[x]=i;//记录该位置最后一次单点操作标号
    38         }
    39         else if(t==2)//更新修改操作 
    40         {
    41             scanf("%d",&c[i]);//记录该操作标号下的更新处理的值 
    42         }
    43     }
    44     for(int i=q-1;i>=1;i--)//后面大值会覆盖之前的小值,c[1]为最大值 
    45     {
    46         c[i]=max(c[i],c[i+1]);
    47     }
    48     for(int i=1;i<=n;i++)
    49     {
    50         printf("%d ",max(a[i],c[b[i]+1]));
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    JVM参数默认值列表
    垃圾回收G1日志解析
    《深入理解JAVA虚拟机》垃圾回收时为什么会停顿
    《深入理解JAVA虚拟机》JDK的垃圾收集算法
    什么才是技术?
    Lodash使用示例(比较全)
    MSCL超级工具类(C#),开发人员必备,开发利器
    刷新SqlServer数据库中所有的视图
    Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法
    C#中执行批处理文件(.bat),执行数据库相关操作
  • 原文地址:https://www.cnblogs.com/jiamian/p/11275464.html
Copyright © 2020-2023  润新知