AlexNeagu11

Untitled

Mar 19th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream in("arbint.in");
  4. ofstream out("arbint.out");
  5.  
  6. int main() {
  7. int N, M;
  8. in >> N >> M;
  9. vector<int> a(N);
  10. for(int i = 0; i < N; ++i) {
  11. in >> a[i];
  12. }
  13. vector<int> block(N);
  14. int blockSize = (int) sqrt(N);
  15. for(int i = 0; i < N; ++i) {
  16. block[i] = i / blockSize;
  17. }
  18. vector<int> maxByBlock(N / blockSize + 6);
  19. for(int i = 0; i < N; ++i) {
  20. int whatBlock = block[i];
  21. maxByBlock[whatBlock] = max(maxByBlock[whatBlock], a[i]);
  22. }
  23. for(int i = 0; i < M; ++i) {
  24. int op;
  25. in >> op;
  26. if(op == 0) {
  27. int L, R;
  28. in >> L >> R;
  29. L--, R--;
  30. int ans = -2e9;
  31. while(L < R && block[L] == block[L + 1]) {
  32. ans = max(ans, a[L]);
  33. L++;
  34. }
  35. while(R > L && block[R] == block[R - 1]) {
  36. ans = max(ans, a[R]);
  37. R--;
  38. }
  39. if(L == R) {
  40. ans = max(ans, a[L]);
  41. L++;
  42. } else {
  43. ans = max(ans, a[L]);
  44. ans = max(ans, a[R]);
  45. L++;
  46. R--;
  47. }
  48. } else {
  49. int pos, x;
  50. in >> pos >> x;
  51. pos--;
  52. int L = block[pos] * blockSize;
  53. int R = min( (block[pos] + 1) * blockSize - 1, N - 1);
  54. a[pos] = x;
  55. maxByBlock[ block[pos] ] = -2e9;
  56. for(int j = L; j <= R; ++j) {
  57. maxByBlock[ block[j] ] = max(maxByBlock[ block[j] ], a[j]);
  58. }
  59. }
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment