Submission #895957

# Submission time Handle Problem Language Result Execution time Memory
895957 2023-12-31T08:20:37 Z SalihSahin Wall (IOI14_wall) C++14
100 / 100
622 ms 128440 KB
#include<bits/stdc++.h>
#include "wall.h"
#define pb push_back
#define mp make_pair
using namespace std;

const int mod = 1e9 + 7;
const int N = 3e5 + 5;

struct SEGT{
    vector<int> mx, mn, lazy;

    void init(int n){
        lazy.assign(4*n, -1);
        mx.assign(4*n, 0);
        mn.assign(4*n, 0);
    }

    void push(int ind){
        if(lazy[ind] == -1) return;
        mx[ind*2] = lazy[ind];
        mx[ind*2+1] = lazy[ind];
        mn[ind*2] = lazy[ind];
        mn[ind*2+1] = lazy[ind];
        lazy[ind*2] = lazy[ind];
        lazy[ind*2+1] = lazy[ind];

        lazy[ind] = -1;
    }

    void update1(int ind, int l, int r, int ql, int qr, int val){
        if(l > r || l > qr || r < ql) return;
        if(l >= ql && r <= qr && mx[ind] <= val){
            lazy[ind] = val;
            mx[ind] = val;
            mn[ind] = val;
        }
        else if(l >= ql && r <= qr && mn[ind] >= val) return;
        else if(l == r){
            mx[ind] = max(mx[ind], val);
            mn[ind] = mx[ind];
        }
        else{
            push(ind);
            int m = (l + r)/2;

            update1(ind*2, l, m, ql, qr, val);
            update1(ind*2+1, m+1, r, ql, qr, val);

            mx[ind] = max(mx[ind*2], mx[ind*2+1]);
            mn[ind] = min(mn[ind*2], mn[ind*2+1]);
        }
    }

    void update2(int ind, int l, int r, int ql, int qr, int val){
        if(l > r || l > qr || r < ql) return;
        if(l >= ql && r <= qr && mn[ind] >= val){
            lazy[ind] = val;
            mx[ind] = val;
            mn[ind] = val;
        }
        else if(l >= ql && r <= qr && mx[ind] <= val) return;
        else if(l == r){
            mx[ind] = max(mx[ind], val);
            mn[ind] = mx[ind];
        }
        else{
            push(ind);
            int m = (l + r)/2;

            update2(ind*2, l, m, ql, qr, val);
            update2(ind*2+1, m+1, r, ql, qr, val);

            mx[ind] = max(mx[ind*2], mx[ind*2+1]);
            mn[ind] = min(mn[ind*2], mn[ind*2+1]);
        }
    }

    void query(int ind, int l, int r, vector<int> &a){
        if(l == r) a[l] = mx[ind];
        else{
            push(ind);
            int m = (l + r)/2;

            query(ind*2, l, m, a);
            query(ind*2+1, m+1, r, a);
        }
    }

};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
   SEGT seg;
   seg.init(n);
   for(int i = 0; i < k; i++){
     if(op[i] == 1) seg.update1(1, 1, n, left[i] + 1, right[i] + 1, height[i]);
     else seg.update2(1, 1, n, left[i] + 1, right[i] + 1, height[i]);
   }
   vector<int> a(n+1);
   seg.query(1, 1, n, a);

   for(int i = 0; i < n; i++){
     finalHeight[i] = a[i+1];
   }
}

/*
int main()
{
  int n;
  int k;

  int i, j;  
  int status = 0;

  status = scanf("%d%d", &n, &k);
  assert(status == 2);

  int* op = (int*)calloc(sizeof(int), k);
  int* left = (int*)calloc(sizeof(int), k);
  int* right = (int*)calloc(sizeof(int), k);
  int* height = (int*)calloc(sizeof(int), k);
  int* finalHeight = (int*)calloc(sizeof(int), n);

  for (i = 0; i < k; i++){
    status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
    assert(status == 4);
  }

  buildWall(n, k, op, left, right, height, finalHeight);

  for (j = 0; j < n; j++)
    printf("%d\n", finalHeight[j]);
  
  return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 2 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 1 ms 344 KB Output is correct
2 Correct 103 ms 8068 KB Output is correct
3 Correct 135 ms 4436 KB Output is correct
4 Correct 343 ms 13736 KB Output is correct
5 Correct 229 ms 13728 KB Output is correct
6 Correct 241 ms 22408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 5 ms 856 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 102 ms 8016 KB Output is correct
9 Correct 120 ms 4604 KB Output is correct
10 Correct 351 ms 13648 KB Output is correct
11 Correct 224 ms 13732 KB Output is correct
12 Correct 239 ms 22224 KB Output is correct
13 Correct 1 ms 500 KB Output is correct
14 Correct 118 ms 13856 KB Output is correct
15 Correct 27 ms 2384 KB Output is correct
16 Correct 455 ms 23116 KB Output is correct
17 Correct 245 ms 22772 KB Output is correct
18 Correct 245 ms 22772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 5 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 126 ms 8256 KB Output is correct
9 Correct 126 ms 4436 KB Output is correct
10 Correct 338 ms 13648 KB Output is correct
11 Correct 223 ms 13740 KB Output is correct
12 Correct 231 ms 22096 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 110 ms 14316 KB Output is correct
15 Correct 26 ms 2384 KB Output is correct
16 Correct 456 ms 23340 KB Output is correct
17 Correct 242 ms 22612 KB Output is correct
18 Correct 242 ms 22612 KB Output is correct
19 Correct 592 ms 128312 KB Output is correct
20 Correct 608 ms 128256 KB Output is correct
21 Correct 592 ms 128440 KB Output is correct
22 Correct 622 ms 128080 KB Output is correct
23 Correct 561 ms 128148 KB Output is correct
24 Correct 573 ms 128248 KB Output is correct
25 Correct 600 ms 128068 KB Output is correct
26 Correct 575 ms 128356 KB Output is correct
27 Correct 563 ms 128080 KB Output is correct
28 Correct 610 ms 128248 KB Output is correct
29 Correct 580 ms 128244 KB Output is correct
30 Correct 578 ms 128244 KB Output is correct