답안 #895956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895956 2023-12-31T08:16:05 Z SalihSahin 벽 (IOI14_wall) C++14
8 / 100
3000 ms 23120 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]);
        }
    }

    int query(int ind, int l, int r, int pos){
        if(l == r) return mx[ind];
        else{
            push(ind);
            int m = (l + r)/2;

            if(pos <= m) return query(ind*2, l, m, pos);
            else return query(ind*2+1, m+1, r, pos);
        }
    }

};

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]);
   }

   for(int i = 0; i < n; i++){
     finalHeight[i] = seg.query(1, 1, n, 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;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 888 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 6 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 103 ms 13916 KB Output is correct
3 Correct 127 ms 8276 KB Output is correct
4 Correct 349 ms 22840 KB Output is correct
5 Execution timed out 3058 ms 23056 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 928 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 115 ms 13948 KB Output is correct
9 Correct 130 ms 8388 KB Output is correct
10 Correct 348 ms 22868 KB Output is correct
11 Execution timed out 3086 ms 23120 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 1124 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 100 ms 14060 KB Output is correct
9 Correct 126 ms 8268 KB Output is correct
10 Correct 367 ms 22836 KB Output is correct
11 Execution timed out 3101 ms 23116 KB Time limit exceeded
12 Halted 0 ms 0 KB -