답안 #558875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558875 2022-05-08T22:34:37 Z aryan12 벽 (IOI14_wall) C++17
24 / 100
464 ms 82764 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 2e6 + 5;
int seg[N * 4];
vector<pair<int, int> > lazy(N * 4, {-1, 100001});


void UpdateLazy(int l, int r, int pos)
{
    // if(l == 0 && r == 0 && lazy[pos].size() != 0)
    // {
    //     cout << "\n\n\n\n\n\n\n\n\n\n\n";
    //     cout << "lazy[pos].size() = " << lazy[pos].size() << "\n";
    //     cout << "\n\n\n\n\n\n\n\n\n\n\n";
    // }
    if(l != r)
    {
        lazy[pos * 2].first = max(lazy[pos * 2].first, lazy[pos].first);
        lazy[pos * 2].second = min(lazy[pos * 2].second, lazy[pos].second);

        lazy[pos * 2 + 1].first = max(lazy[pos * 2 + 1].first, lazy[pos].first);
        lazy[pos * 2 + 1].second = min(lazy[pos * 2 + 1].second, lazy[pos].second);
        lazy[pos] = {-1, 100001};
    }
    else
    {
        if(seg[pos] < lazy[pos].first) seg[pos] = lazy[pos].first;
        if(seg[pos] > lazy[pos].second) seg[pos] = lazy[pos].second;
        lazy[pos] = {-1, 100001};
    }
}


int Query(int l, int r, int pos, int qpos)
{
    // cout << "l = " << l << ", r = " << r << ", pos = " << pos << ", qpos = " << qpos << "\n";
    UpdateLazy(l, r, pos);
    if(l == r)
    {
        return seg[pos];
    }
    int mid = (l + r) >> 1;
    if(qpos <= mid)
    {
        return Query(l, mid, pos * 2, qpos);
    }
    return Query(mid + 1, r, pos * 2 + 1, qpos);
}


void Update(int l, int r, int pos, int qoperation, int qleft, int qright, int qvalue)
{
    UpdateLazy(l, r, pos);
    if(qleft > r || l > qright)
    {
        // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; 
        // cout << "no intersection\n";
        return;
    }
    if(l == r)
    {
        // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; 
        // cout << "full intersection (point)\n";
        if(qoperation == 1) //adding phase
        {
            seg[pos] = max(seg[pos], qvalue);
        }
        else //removing phase
        {
            seg[pos] = min(seg[pos], qvalue);
        }
        return;
    }
    if(qleft <= l && r <= qright)
    {
        // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; 
        // cout << "full intersection (range)\n";
        if(qoperation == 1) // adding phase
        {
            lazy[pos * 2].first = max(lazy[pos * 2].first, qvalue);
            lazy[pos * 2 + 1].first = max(lazy[pos * 2 + 1].first, qvalue);
        }
        else
        {
            lazy[pos * 2].second = min(lazy[pos * 2].second, qvalue);
            lazy[pos * 2 + 1].second = min(lazy[pos * 2 + 1].second, qvalue);
        }
        return;
    }
    int mid = (l + r) >> 1;
    Update(l, mid, pos * 2, qoperation, qleft, qright, qvalue);
    Update(mid + 1, r, pos * 2 + 1, qoperation, qleft, qright, qvalue);
    // cout << "Update: (" << l << ", " << r << "), query range(" << qleft << ", " << qright << ", query operation and value: (" << qoperation << ", " << qvalue << ")\n"; 
    // cout << "partial intersection\n";
}


void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    for(int i = 0; i < k; i++)
    {
        Update(0, n - 1, 1, op[i], left[i], right[i], height[i]);
        // cout << "QUERYING\n";
        // for(int j = 0; j < n; j++)
        // {
        //     cout << Query(0, n - 1, 1, j) << "\n";
        // }
        // cout << "\n\n\n\n\n";
    }
    for(int i = 0; i < n; i++)
    {
        finalHeight[i] = Query(0, n - 1, 1, i);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 62828 KB Output is correct
2 Correct 29 ms 62912 KB Output is correct
3 Incorrect 29 ms 62932 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 62888 KB Output is correct
2 Correct 157 ms 70776 KB Output is correct
3 Correct 185 ms 66460 KB Output is correct
4 Correct 464 ms 81764 KB Output is correct
5 Correct 333 ms 82764 KB Output is correct
6 Correct 326 ms 81388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 62920 KB Output is correct
2 Correct 30 ms 62972 KB Output is correct
3 Incorrect 30 ms 62936 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 62796 KB Output is correct
2 Correct 33 ms 62924 KB Output is correct
3 Incorrect 31 ms 62896 KB Output isn't correct
4 Halted 0 ms 0 KB -