Submission #892896

# Submission time Handle Problem Language Result Execution time Memory
892896 2023-12-26T06:40:35 Z Mr_Husanboy Wall (IOI14_wall) C++17
100 / 100
555 ms 97108 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;
const int inf = 1e9;



struct Segtree{
  struct Node{
    int mn = inf, mx = 0;
    void apply(int x, int type){
      if(type == 1){
        mn = max(mn, x);
        mx = max(mx, x);
      }else{
        mn = min(mn, x);
        mx = min(mx, x);
      }
    }
    void calibrate(){
      mn = inf, mx = 0;
    }
  };
  vector<Node> t;
  int n;

  void init(int _n){
    n = _n;
    t.resize(4 * n);
  }

  void push(int x){
    t[x * 2].apply(t[x].mx, 1);
    t[x * 2].apply(t[x].mn, 2);
    t[x * 2 + 1].apply(t[x].mx, 1);
    t[x * 2 + 1].apply(t[x].mn, 2);
    t[x].calibrate();
  }

  void upd(int x, int l, int r, int ql, int qr, int val, int type){
    if(l > qr || ql > r) return;
    if(ql <= l && r <= qr){
      //cout << l << ' ' << r << ' ' << val << ' ' << type << endl;

      t[x].apply(val, type);
     // cout << t[x].mx << endl;
      return;
    } 
    push(x);
    int m = (l + r) / 2;
    upd(x * 2, l, m, ql, qr, val, type);
    upd(x * 2 + 1, m + 1, r, ql, qr, val, type);
  }

  void finish(vector<int> &ans, int x, int l, int r){
    if(l == r){
      //t[x].apply(t[x].mn, 2);
      ans[l] = t[x].mx;
      return;
    }
    push(x);
    int m = (l + r) / 2;
    finish(ans, x * 2, l, m); finish(ans, x * 2 + 1, m + 1, r);
  }

  //interface

  void upd(int l, int r, int val, int type){
    upd(1, 0, n - 1, l, r, val, type);
  }

  void finish(vector<int> &ans){
    finish(ans, 1, 0, n - 1);
  }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int ans[]){
    Segtree t;
    t.init(n);
    vector<int> an(n);
    for(int i = 0; i < k; i ++){
      t.upd(left[i], right[i], height[i], op[i]);
      // t.finish(an);
      // for(int j = 0; j < n; j ++)cout << an[j] << ' ';
      // cout << endl;
    }
    t.finish(an);
    for(int i = 0; i < n; i ++){
      ans[i] = an[i];
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 4 ms 860 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 109 ms 13956 KB Output is correct
3 Correct 131 ms 7968 KB Output is correct
4 Correct 354 ms 21676 KB Output is correct
5 Correct 235 ms 22224 KB Output is correct
6 Correct 224 ms 20564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 119 ms 13868 KB Output is correct
9 Correct 124 ms 8092 KB Output is correct
10 Correct 360 ms 21840 KB Output is correct
11 Correct 223 ms 22220 KB Output is correct
12 Correct 231 ms 20652 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 117 ms 13900 KB Output is correct
15 Correct 20 ms 2140 KB Output is correct
16 Correct 353 ms 21728 KB Output is correct
17 Correct 225 ms 21100 KB Output is correct
18 Correct 223 ms 21092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 122 ms 13996 KB Output is correct
9 Correct 125 ms 8012 KB Output is correct
10 Correct 349 ms 21672 KB Output is correct
11 Correct 223 ms 22356 KB Output is correct
12 Correct 231 ms 20684 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 119 ms 13936 KB Output is correct
15 Correct 21 ms 2128 KB Output is correct
16 Correct 352 ms 21584 KB Output is correct
17 Correct 230 ms 21148 KB Output is correct
18 Correct 231 ms 21096 KB Output is correct
19 Correct 518 ms 96856 KB Output is correct
20 Correct 521 ms 96852 KB Output is correct
21 Correct 517 ms 96852 KB Output is correct
22 Correct 512 ms 97108 KB Output is correct
23 Correct 506 ms 97104 KB Output is correct
24 Correct 525 ms 96860 KB Output is correct
25 Correct 530 ms 96852 KB Output is correct
26 Correct 512 ms 96856 KB Output is correct
27 Correct 507 ms 96848 KB Output is correct
28 Correct 555 ms 96860 KB Output is correct
29 Correct 516 ms 96848 KB Output is correct
30 Correct 515 ms 97092 KB Output is correct