比赛 不平凡的世界 评测结果 AAAAAAAAAA
题目名称 不平凡的boss 最终得分 100
用户昵称 ---- 运行时间 2.328 s
代码语言 C++ 内存使用 8.61 MiB
提交时间 2015-11-05 10:14:25
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102333;
struct D { int x, y, z; } in[maxn];
inline bool operator<(const D&a, const D&b) { return a.x < b.x; }
typedef long long int i64;
template<class T> inline void mint(T& a, T b) { if (a > b) a = b; }
template<class T> inline void maxt(T& a, T b) { if (a < b) a = b; }
const int maxsgt = 262144;
struct MM 
{

    int disc[maxn * 3], cd;
    int SGT[maxsgt << 1];
    inline int query(int l, int r)
    {
        l += maxsgt - 1, r += maxsgt + 1;
        int ans = 0;
        while (l ^ r ^ 1)
        {
            if (~l & 1) maxt(ans, SGT[l ^ 1]); 
            if (r & 1) maxt(ans, SGT[r ^ 1]);
            l >>= 1; r >>= 1;
        }
        return ans;
    }
    inline void alt(int p, int v) 
    { 
        for (maxt(SGT[p += maxsgt], v); p >>= 1 ;)
            SGT[p] = max(SGT[p << 1], SGT[p << 1 | 1]);
    }
    int cur; i64  cans;
    inline void add(int a, int b)
    {
        int ra = lower_bound(disc, disc + cd, a) - disc;
        alt(ra, b); 
        cans = disc[cur] + query(cur + 1, cd);
        if (ra <= cur) return;
        for (; ra < cd; ++ra)
        {
            i64 ss = disc[ra] + query(ra + 1, cd);
            if (ss <= cans ) cur = ra, cans = ss;
            else break;
        }
    }


} QA, QB;
pair<int, int> tt[maxn]; int ct;
inline i64 baoli()
{
    sort(tt, tt + ct);
    i64 ans = tt[ct - 1].first, cmt = 0;;

    for (int i = ct - 1; i > 0; --i)
    {
        maxt(cmt, (i64)tt[i].second);
        mint(ans, tt[i - 1].first + cmt);
    }
    maxt(cmt, (i64)tt[0].second); mint(ans, cmt);
    return ans;
}
int main()
{
    freopen("playwithboss.in", "r", stdin);
    freopen("playwithboss.out", "w", stdout);

    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d%d%d", &in[i].x, &in[i].y, &in[i].z);
    sort(in + 1, in + n + 1); 
    QA.disc[QA.cd++] = 0; QB.disc[QB.cd++] = 0;
    for (int i = 1; i <= n; ++i)  QA.disc[QA.cd++] = in[i].y;
    sort(QA.disc, QA.disc + QA.cd); QA.cd = unique(QA.disc, QA.disc + QA.cd) - QA.disc;
    for (int i = 1; i <= n; ++i)  QB.disc[QB.cd++] = in[i].z;
    sort(QB.disc, QB.disc + QB.cd); QB.cd = unique(QB.disc, QB.disc + QB.cd) - QB.disc;

    i64 ans = in[n].x;
    for (int i = n; i > 0; --i)
    {
        QA.add(in[i].y, in[i].z);
        QB.add(in[i].z, in[i].y);
        //tt[ct++] = make_pair(in[i].y, in[i].z);
        //assert(baoli() == min(QA.cans, QB.cans));
        mint(ans, min(QA.cans, QB.cans) + in[i - 1].x);
    }
    printf("%lld\n", ans);
}