Advertisement
Guest User

Untitled

a guest
Feb 11th, 2022
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. namespace IO {
  5.     const int BUFSIZE = 1<<14;
  6.     char buf[BUFSIZE + 1], *inp = buf;
  7.  
  8.     bool reacheof;
  9.     char get_char() {
  10.         if (!*inp && !reacheof) {
  11.             memset(buf, 0, sizeof buf);
  12.             int tmp = fread(buf, 1, BUFSIZE, stdin);
  13.             if (tmp != BUFSIZE) reacheof = true;
  14.             inp = buf;
  15.         }
  16.         return *inp++;
  17.     }
  18.     template<typename T>
  19.     T get() {
  20.         int neg = 0;
  21.         T res = 0;
  22.         char c = get_char();
  23.         while (!std::isdigit(c) && c != '-' && c != '+') c = get_char();
  24.         if (c == '+') { neg = 0; }
  25.         else if (c == '-') { neg = 1; }
  26.         else res = c - '0';
  27.  
  28.         c = get_char();
  29.         while (std::isdigit(c)) {
  30.             res = res * 10 + (c - '0');
  31.             c = get_char();
  32.         }
  33.         return neg ? -res : res;
  34.     }
  35. };
  36.  
  37. const int MN = 100111;
  38. const int INF = 1000111000;
  39. int a[MN];
  40.  
  41. int main() {
  42.     int n = IO::get<int>();
  43.     for (int i = 1; i <= n; i++) {
  44.         a[i] = IO::get<int>();
  45.     }
  46.     int q = IO::get<int>();
  47.  
  48.     while (q--) {
  49.         int typ = IO::get<int>();
  50.         int x = IO::get<int>();
  51.         int y = IO::get<int>();
  52.         if (typ == 1) a[x] = y;
  53.         else {
  54.             long long max_val = -INF;
  55.             for (int i = x; i <= y; i++) {
  56.                 max_val = (max_val < a[i]) ? a[i] : max_val;
  57.             }
  58.             cout << max_val << '\n';
  59.         }
  60.     }
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement