제출 #559109

#제출 시각아이디문제언어결과실행 시간메모리
559109aryan12벽 (IOI14_wall)C++17
0 / 100
274 ms139172 KiB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;

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

void UpdateLazy(int l, int r, int pos)
{
    // cout << "UpdateLazy(" << l << ", " << r << ", " << pos << ")\n";
    // if(l == 4 && r == 4)
    // {
    //     cout << "in update lazy\n";
    //     cout << "seg[pos] = " << seg[pos] << "\n";
    //     cout << "lazy[pos] = {" << lazy[pos][0] << ", " << lazy[pos][1] << ", " << lazy[pos][2] << ", " << lazy[pos][3] << "}\n";
    // }
    if(lazy[pos][0] > lazy[pos][1])
    {
        if(lazy[pos][2] > lazy[pos][3])
        {
            lazy[pos][1] = lazy[pos][0];
        }
        else
        {
            lazy[pos][0] = lazy[pos][1];
        }
    }
    if(l == r)
    {
        if(lazy[pos][3] > lazy[pos][2])
        {
            seg[pos] = max(seg[pos], lazy[pos][0]);
            seg[pos] = min(seg[pos], lazy[pos][1]);
        }
        else
        {
            seg[pos] = min(seg[pos], lazy[pos][1]);
            seg[pos] = max(seg[pos], lazy[pos][0]);
        }
        // if(l == 4 && r == 4)
        // {
        //     cout << "in update lazy\n";
        //     cout << "seg[pos] = " << seg[pos] << "\n";
        //     cout << "lazy[pos] = {" << lazy[pos][0] << ", " << lazy[pos][1] << ", " << lazy[pos][2] << ", " << lazy[pos][3] << "}\n";
        // }
        return;
    }
    // if(l == 5 && r == 6)
    // {
    //     cout << "lazy[pos * 2] = {" << lazy[pos * 2][0] << ", " << lazy[pos * 2][1] << ", " << lazy[pos * 2][2] << ", " << lazy[pos * 2][3] << "}\n";
    // }
    if(lazy[pos * 2][2] < lazy[pos][2])
    {
        lazy[pos * 2][0] = lazy[pos][0];
        lazy[pos * 2][2] = lazy[pos][2];
    }
    if(lazy[pos * 2 + 1][2] < lazy[pos][2])
    {
        lazy[pos * 2 + 1][0] = lazy[pos][0];
        lazy[pos * 2 + 1][2] = lazy[pos][2];
    }
    if(lazy[pos * 2][3] < lazy[pos][3])
    {
        lazy[pos * 2][1] = lazy[pos][1];
        lazy[pos * 2][3] = lazy[pos][3];
    }
    if(lazy[pos * 2 + 1][3] < lazy[pos][3])
    {
        lazy[pos * 2 + 1][1] = lazy[pos][1];
        lazy[pos * 2 + 1][3] = lazy[pos][3];
    }

}

void Update(int l, int r, int pos, int qop, int ql, int qr, int qval)
{
    UpdateLazy(l, r, pos);
    if(ql > r || l > qr)
    {
        // cout << "Update(" << l << ", " << r << "), q range: (" << ql << ", " << qr << "), q values: " << qop << ", " << qval << "\n";
        // cout << "No intersection\n";
        return;
    }
    if(l == r)
    {
        // cout << "Update(" << l << ", " << r << "), q range: (" << ql << ", " << qr << "), q values: " << qop << ", " << qval << "\n";
        // cout << "Full intersection (point)\n";
        if(qop == 1)
        {
            lazy[pos][2] = cnt;
            lazy[pos][0] = max(qval, lazy[pos][0]);
            lazy[pos][1] = max(lazy[pos][0], lazy[pos][1]);
            seg[pos] = max(seg[pos], qval);
        }
        else
        {
            lazy[pos][3] = cnt;
            lazy[pos][1] = min(lazy[pos][1], qval);
            lazy[pos][0] = min(lazy[pos][1], lazy[pos][0]);
            seg[pos] = min(seg[pos], qval);
        }
        return;
    }
    if(ql <= l && r <= qr)
    {
        // cout << "Update(" << l << ", " << r << "), q range: (" << ql << ", " << qr << "), q values: " << qop << ", " << qval << "\n";
        // cout << "Full intersection (range)\n";
        int mid = (l + r) >> 1;
        if(qop == 1) // adding phase
        {
            lazy[pos][2] = cnt;
            lazy[pos][0] = max(qval, lazy[pos][0]);
            lazy[pos][1] = max(lazy[pos][0], lazy[pos][1]);
        }
        else
        {
            lazy[pos][3] = cnt;
            lazy[pos][1] = min(lazy[pos][1], qval);
            lazy[pos][0] = min(lazy[pos][1], lazy[pos][0]);
        }
        return;
    }
    int mid = (l + r) >> 1;
    Update(l, mid, pos * 2, qop, ql, qr, qval);
    Update(mid + 1, r, pos * 2 + 1, qop, ql, qr, qval);
    // cout << "Update(" << l << ", " << r << "), q range: (" << ql << ", " << qr << "), q values: " << qop << ", " << qval << "\n";
    // cout << "Partial intersection\n";
}

int Query(int l, int r, int pos, int qpos)
{
    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 buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    for(int i = 0; i < k; i++)
    {
        cnt++;
        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);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

wall.cpp: In function 'void Update(int, int, int, int, int, int, int)':
wall.cpp:110:13: warning: unused variable 'mid' [-Wunused-variable]
  110 |         int mid = (l + r) >> 1;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...