| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 649759 | boris_mihov | Santa Claus (RMI19_santa) | C++17 | 1094 ms | 262144 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <tgmath.h>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <set>
typedef long long llong; 
const int MAXN = 100000 + 10;
const int MOD  = 1e9 + 7;
const int INF  = 1e9;
struct House
{
    int x, h, v;
    inline friend bool operator < (const House &a, const House &b)
    {
        return a.x < b.x || (a.x == b.x && a.h < b.h) || (a.x == b.x && a.h == b.h && a.v < b.v);
    }
} houses[MAXN];
int n, t;
int x[MAXN];
int h[MAXN];
int v[MAXN];
bool gotPresent[MAXN];
std::multiset <int> s;
std::multiset <int> toGive[MAXN];
std::vector <std::pair <int,bool>> left;
bool check(int idx, int allowed)
{
    left.clear();
    for (const int &i : toGive[allowed-1]) 
    {
        left.emplace_back(i, 0);
    }
    for (int i = allowed ; i <= idx ; ++i)
    {
        left.emplace_back(v[i], h[i]);
    }
    std::sort(left.begin(), left.end(), [&](auto x, auto y)
    {
        return x.first > y.first || (x.first == y.first && x.second < y.second);
    });
    int cnt = 0;
    for (int i = 0 ; i < left.size() ; ++i)
    {
        if (left[i].second == 0) cnt++;
        else if (cnt >= 1) cnt--;
    }
    
    return cnt == 0;
}
int maxElvePos = 0;
void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        toGive[i] = toGive[i - 1];
        if (h[i] == 0) toGive[i].insert(v[i]);
        else
        {
            auto it = toGive[i].lower_bound(v[i]);
            if (it != toGive[i].end()) toGive[i].erase(it);
        }
    }
    for (int i = 1 ; i <= n ; ++i)
    {
        if (x[i] < maxElvePos)
        {
            std::cout << -1 << ' ';
            continue;
        }
        int l = 0, r = i + 1, mid;
        while (l < r - 1)
        {
            mid = (l + r) / 2;
            if (check(i, mid)) l = mid;
            else r = mid;
        }
        if (l == 0) std::cout << -1 << ' ';
        else std::cout << 2*x[i] - x[l] << ' ';
    }
    std::cout << '\n';
}
void read()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i) std::cin >> houses[i].x;
    for (int i = 1 ; i <= n ; ++i) std::cin >> houses[i].h;
    for (int i = 1 ; i <= n ; ++i) std::cin >> houses[i].v;
    std::sort(houses + 1, houses + 1 + n);
    for (int i = 1 ; i <= n ; ++i)
    {
        x[i] = houses[i].x;
        h[i] = houses[i].h;
        v[i] = houses[i].v;
        if (h[i] == 0) maxElvePos = x[i];
    }
}
void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}
int main()
{
    fastIO();
    std::cin >> t;
    while (t--)
    {
        read();
        solve();
    }
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
