コード例 #1
0
 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         int n = fs.NextInt(), k = fs.NextInt(), a = fs.NextInt(), b = fs.NextInt(), q = fs.NextInt();
         SqrtDecomposer<long> adec = new SqrtDecomposer<long>(Enumerable.Repeat<long>(0, n).ToArray(), new SqrtBoundedSum(a), new SqrtSum());
         SqrtDecomposer<long> bdec = new SqrtDecomposer<long>(Enumerable.Repeat<long>(0, n).ToArray(), new SqrtBoundedSum(b), new SqrtSum());
         while (q-- > 0)
         {
             int cmd = fs.NextInt();
             if (cmd == 1)
             {
                 int d = fs.NextInt() - 1, val = fs.NextInt();
                 adec.Update(d, adec.Get(d) + val);
                 bdec.Update(d, bdec.Get(d) + val);
             }
             else
             {
                 int p = fs.NextInt() - 1;
                 writer.WriteLine(bdec.Eval(0, p - 1) + adec.Eval(p + k, n - 1));
             }
         }
     }
 }
コード例 #2
0
 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
         using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
         {
             int n = fs.NextInt(), k = fs.NextInt(), a = fs.NextInt(), b = fs.NextInt(), q = fs.NextInt();
             SqrtDecomposer <long> adec = new SqrtDecomposer <long>(Enumerable.Repeat <long>(0, n).ToArray(), new SqrtBoundedSum(a), new SqrtSum());
             SqrtDecomposer <long> bdec = new SqrtDecomposer <long>(Enumerable.Repeat <long>(0, n).ToArray(), new SqrtBoundedSum(b), new SqrtSum());
             while (q-- > 0)
             {
                 int cmd = fs.NextInt();
                 if (cmd == 1)
                 {
                     int d = fs.NextInt() - 1, val = fs.NextInt();
                     adec.Update(d, adec.Get(d) + val);
                     bdec.Update(d, bdec.Get(d) + val);
                 }
                 else
                 {
                     int p = fs.NextInt() - 1;
                     writer.WriteLine(bdec.Eval(0, p - 1) + adec.Eval(p + k, n - 1));
                 }
             }
         }
 }