Advertisement
Artem_Chepurov

Ex5 Tink Back

Jun 29th, 2022
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Matr
  7.     {
  8.         List<List<long>> d;
  9.         private int n, m;
  10.  
  11.         public Matr(int n, int m)
  12.         {
  13.             this.n = n;
  14.             this.m = m;
  15.             d = new List<List<long>>(n);
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 d.Add(new List<long>(m));
  19.                 for (int j = 0; j < m; j++)
  20.                 {
  21.                     d[i].Add(0);
  22.                 }
  23.             }
  24.  
  25.         }
  26.  
  27.         public void Add(long l, long r, long x)
  28.         {
  29.             for (int i = Convert.ToInt32(l); i <= r; i++)
  30.             {
  31.                 for (int j = 0; j < m; j++)
  32.                 {
  33.                     d[j][i] += x;
  34.                 }
  35.             }
  36.         }
  37.  
  38.         public void Change(int i, long x)
  39.         {
  40.             List<long> changeList = new List<long>(n);
  41.             for (int j = 0; j < m; j++)
  42.                 changeList.Add(x);
  43.             d[i] = changeList;
  44.         }
  45.  
  46.         public long Get(int i, int j)
  47.         {
  48.             return d[i][j];
  49.         }
  50.     }
  51.  
  52.     class Program
  53.     {
  54.         public static void Main(string[] args)
  55.         {
  56.             string? input = Console.ReadLine();
  57.             if (input == null) return;
  58.             int n, m, countQ, q;
  59.             n = Convert.ToInt32(input.Split(' ')[0]);
  60.             m = Convert.ToInt32(input.Split(' ')[1]);
  61.             countQ = Convert.ToInt32(input.Split(' ')[2]);
  62.             Matr matr = new Matr(n, m);
  63.             for (int it = 0; it < countQ; it++)
  64.             {
  65.                 input = Console.ReadLine();
  66.                 if (input == null) return;
  67.                 q = Convert.ToInt32(input.Split(' ')[0]);
  68.                 switch (q)
  69.                 {
  70.                     case 1:
  71.                         long l = Convert.ToInt64(input.Split(' ')[1]);
  72.                         long r = Convert.ToInt64(input.Split(' ')[2]);
  73.                         long x = Convert.ToInt64(input.Split(' ')[3]);
  74.                         l--;
  75.                         r--;
  76.                         matr.Add(l, r, x);
  77.                         break;
  78.                     case 2:
  79.                         int i = Convert.ToInt32(input.Split(' ')[1]);
  80.                         long xx = Convert.ToInt64(input.Split(' ')[2]);
  81.                         i--;
  82.                         matr.Change(i, xx);
  83.                         break;
  84.                     case 3:
  85.                         int ii = Convert.ToInt32(input.Split(' ')[1]);
  86.                         int j = Convert.ToInt32(input.Split(' ')[2]);
  87.                         ii--;
  88.                         j--;
  89.                         Console.WriteLine(matr.Get(ii, j));
  90.                         break;
  91.                 }
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement