Advertisement
Guest User

Untitled

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