Submission #1224104

#TimeUsernameProblemLanguageResultExecution timeMemory
122410412baaterWall (IOI14_wall)C++20
24 / 100
498 ms43424 KiB
#include "wall.h"
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;


bool comp(const pair<int, pair<int,int>>& a, const pair<int, pair<int,int>>& b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    vector<pair<int, pair<int,int>>> fp;
    multiset<int> big;
    multiset<int> small;
    for (int i = 0; i < k; i++) {
        if (op[i] == 1) {
            fp.push_back({left[i],{height[i],0}});
            fp.push_back({right[i]+1,{height[i],1}});
            continue;
        }
        fp.push_back({left[i],{height[i],2}});
        fp.push_back({right[i]+1,{height[i],3}});
    }
    sort(fp.begin(),fp.end(), comp);
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < fp.size()) {
            if (fp[j].first > i) break;
            auto [val, type] = fp[j].second;
            if (type == 0) big.insert(val);
            else if (type == 1) big.extract(val);
            else if (type == 2) small.insert(val);
            else if (type == 3) small.extract(val);
            j++;
        }
        if (!big.empty())
            finalHeight[i] = *prev(big.end());

        if (!small.empty())
            finalHeight[i] = min(finalHeight[i], *small.begin());
    }
    return;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...