QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404760#190. New HomeMax_s_xaM0 12ms77936kbC++148.7kb2024-05-04 17:30:342024-05-04 17:30:34

Judging History

你现在查看的是最新测评结果

  • [2024-05-04 17:30:34]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:77936kb
  • [2024-05-04 17:30:34]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 3e5 + 10;

int n, m, q;

struct Line
{
    int l, r, x;
    Line(int _l, int _r, int _x) : l(_l), r(_r), x(_x) {}
    bool operator < (const Line u) const {return (l == u.l ? r < u.r : l < u.l);}
};
vector <Line> vec[MAXN];

int d = 1e8;
set <Line> st;
inline auto Split(int x)
{
    auto it = --st.upper_bound(Line(x, 2e9, 0));
    if (it -> l == x) return it;
    int l = it -> l, r = it -> r, v = it -> x;
    st.erase(it), st.insert(Line(l, x - 1, v));
    return st.insert(Line(x, r, v)).first;
}

struct Data
{
    int l, r, x, y;
}g1[MAXN * 3], g2[MAXN * 3];
int t1, t2;
struct Qry
{
    int t, x, ans;
}qt[MAXN];
int b[MAXN << 2], tot, c[MAXN << 1], top;

struct Node
{
    int ls, rs, val;
}tr[MAXN * 200];
int nd, rt[MAXN << 2];
void Update(int &cur, int pre, int l, int r, int x, int y, int k)
{
    cur = ++nd, tr[cur] = tr[pre];
    // cerr << "upd " << cur  << ' ' << pre << ' ' << l << ' ' << r << ' ' << x << ' ' << y << ' ' << k << ' ';
    if (x <= l && r <= y) tr[cur].val = max(tr[cur].val, k);//, cerr << tr[cur].val << '\n';
    else
    {
        // cerr << tr[cur].val << '\n';
        int mid = l + r >> 1;
        if (x <= mid) Update(tr[cur].ls, tr[pre].ls, l, mid, x, y, k);
        if (y > mid) Update(tr[cur].rs, tr[pre].rs, mid + 1, r, x, y, k);
    }
}
int Query(int cur, int l, int r, int x)
{
    // cerr << "qry " << cur << ' ' << l << ' ' << r << ' ' << x << ' ' << tr[cur].val << '\n';
    if (!cur) return -2e9;
    if (l == r) return tr[cur].val;
    int mid = l + r >> 1;
    if (x <= mid) return max(tr[cur].val, Query(tr[cur].ls, l, mid, x));
    return max(tr[cur].val, Query(tr[cur].rs, mid + 1, r, x));
}

vector <int> qry[MAXN << 2], upd[MAXN << 2];
void InsertUpdate(int cur, int l, int r, int x, int y, int id)
{
    // cerr << "Inupd " << cur << ' ' << l << ' ' << r << ' ' << x << ' ' << y << ' ' << id << '\n';
    if (x <= l && r <= y) upd[cur].push_back(id);
    else
    {
        int mid = l + r >> 1;
        if (x <= mid) InsertUpdate(cur << 1, l, mid, x, y, id);
        if (y > mid) InsertUpdate(cur << 1 | 1, mid + 1, r, x, y, id);
    }
}
void InsertQuery(int cur, int l, int r, int x, int id)
{
    if (l == r) qry[cur].push_back(id);
    else
    {
        int mid = l + r >> 1;
        if (x <= mid) InsertQuery(cur << 1, l, mid, x, id);
        else InsertQuery(cur << 1 | 1, mid + 1, r, x, id);
    }
}
void Solve(int cur, int fa, int l, int r, bool tp, bool fl)
{
    rt[cur] = rt[fa];
    if (!fl)
    {
        // cerr << "Solve " << cur << ' ' << rt[cur] << ' ' << l << ' ' << r << '\n';
        for (auto id : upd[cur])
            if (!tp)
            {
                if (g1[id].y == 2e9) {fl = 1; break;}
                Update(rt[cur], rt[fa], 1, top, g1[id].x, g1[id].y, g1[id].y);
            }
            else Update(rt[cur], rt[fa], 1, top, g2[id].x, g2[id].y, -g2[id].x);
    }
    if (l == r)
    {
        for (auto id : qry[cur])
            if (fl || qt[id].ans == -1) qt[id].ans = -1;
            else
            {
                int res = Query(rt[cur], 1, top, qt[id].x);
                if (res == -2e9) continue;
                if (tp) res = -res;
                // cerr << res << '\n';
                qt[id].ans = max(qt[id].ans, abs(c[qt[id].x] - c[res]));
            }
        return;
    }
    int mid = l + r >> 1;
    Solve(cur << 1, cur, l, mid, tp, fl), Solve(cur << 1 | 1, cur, mid + 1, r, tp, fl);
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(m), Read(q);
    for (int i = 1, x, t, l, r; i <= n; i++)
    {
        Read(x), Read(t), Read(l), Read(r);
        vec[t].emplace_back(l, r, x);
        b[++tot] = l, b[++tot] = r, c[++top] = x;
    }
    for (int i = 1; i <= m; i++)
    {
        st.clear(), st.insert(Line(1, d, 0));
        sort(vec[i].begin(), vec[i].end(), [&](Line u, Line v) {return u.x < v.x;});
        for (auto t : vec[i])
        {
            int l = t.l, r = t.r, x = t.x, mid;
            // cout << l << ' ' << r << ' ' << x << '\n';
            auto ed = Split(r + 1), bg = Split(l);
            for (auto it = bg; it != ed; it++)
            {
                if (it -> x == 0) g1[++t1] = Data{it -> l, it -> r, 1, x};
                else mid = x + it -> x >> 1, g1[++t1] = Data{it -> l, it -> r, mid + 1, x}, g2[++t2] = Data{it -> l, it -> r, it -> x, mid};
            }
            st.erase(bg, ed);
            st.insert(Line{l, r, x});
            // for (auto x : st) cout << x.l << ' ' << x.r << '\n';
            // cout << '\n';
        }
        for (auto it : st)
            if (it.x == 0) g1[++t1] = Data{it.l, it.r, 1, (int)2e9};
            else g2[++t2] = Data{it.l, it.r, it.x, d};
    }
    // cerr << "ODT\n";
    // for (int i = 1; i <= t2; i++) cerr << g2[i].l << ' ' << g2[i].r << ' ' << g2[i].x << ' ' << g2[i].y << "\n";
    for (int i = 1; i <= q; i++) Read(qt[i].x), Read(qt[i].t), b[++tot] = qt[i].t, c[++top] = qt[i].x;
    b[++tot] = c[++top] = 2e9;
    sort(b + 1, b + tot + 1), tot = unique(b + 1, b + tot + 1) - b - 1;
    sort(c + 1, c + top + 1), top = unique(c + 1, c + top + 1) - c - 1;
    // cerr << "##\n";
    for (int i = 1; i <= q; i++)
    {
        qt[i].t = lower_bound(b + 1, b + tot + 1, qt[i].t) - b;
        qt[i].x = lower_bound(c + 1, c + top + 1, qt[i].x) - c;
        // cerr << qt[i].t << ' ' << qt[i].x << '\n';
        InsertQuery(1, 1, tot, qt[i].t, i);
    }
    // cerr << "insert q\n";
    for (int i = 1; i <= t1; i++)
    {
        g1[i].l = lower_bound(b + 1, b + tot + 1, g1[i].l) - b, g1[i].r = lower_bound(b + 1, b + tot + 1, g1[i].r) - b;
        g1[i].x = lower_bound(c + 1, c + top + 1, g1[i].x) - c;
        if (g1[i].y != 2e9) g1[i].y = upper_bound(c + 1, c + top + 1, g1[i].y) - c - 1;
        if (g1[i].r <= tot) InsertUpdate(1, 1, tot, g1[i].l, g1[i].r, i);
    }
    // cerr << "insert 0\n";
    tr[rt[0] = 0].val = -2e9;
    Solve(1, 0, 1, tot, 0, 0);
    // cerr << "Solve -----------------\n";
    for (int i = 1; i <= tot * 4; i++) upd[i].clear();
    for (int i = 1; i <= t2; i++)
    {
        g2[i].l = lower_bound(b + 1, b + tot + 1, g2[i].l) - b, g2[i].r = lower_bound(b + 1, b + tot + 1, g2[i].r) - b;
        g2[i].x = lower_bound(c + 1, c + top + 1, g2[i].x) - c, g2[i].y = upper_bound(c + 1, c + top + 1, g2[i].y) - c - 1;
        // cerr << g2[i].l << ' ' << g2[i].r << ' ' << g2[i].x << ' ' << g2[i].y << '\n';
        if (g2[i].r <= tot) InsertUpdate(1, 1, tot, g2[i].l, g2[i].r, i);
    }
    for (int i = 0; i <= nd; i++) rt[i] = 0;
    nd = 0, Solve(1, 0, 1, tot, 1, 0);
    for (int i = 1; i <= q; i++) cout << qt[i].ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 8ms
memory: 74280kb

input:

4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10

output:

4
2
-1
-1

result:

ok 4 lines

Test #2:

score: 5
Accepted
time: 11ms
memory: 74732kb

input:

2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7

output:

0
0
-1

result:

ok 3 lines

Test #3:

score: 5
Accepted
time: 3ms
memory: 77936kb

input:

1 1 1
100000000 1 1 1
1 1

output:

99999999

result:

ok single line: '99999999'

Test #4:

score: 5
Accepted
time: 8ms
memory: 74776kb

input:

20 10 20
1 6 1 1
1 9 1 1
1 3 1 1
1 5 1 1
1 2 1 1
1 7 1 1
1 7 1 1
1 8 1 1
1 3 1 1
1 8 1 1
1 5 1 1
1 2 1 1
1 10 1 1
1 7 1 1
1 7 1 1
1 10 1 1
1 1 1 1
1 4 1 1
1 6 1 1
1 8 1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 20 lines

Test #5:

score: 5
Accepted
time: 4ms
memory: 74348kb

input:

20 10 1
45 4 53 54
75 8 56 60
65 3 87 100
56 7 93 97
36 3 64 91
63 4 93 94
71 2 45 97
67 5 57 65
34 6 7 52
96 9 43 95
83 5 63 92
24 3 55 99
7 10 38 52
59 10 59 100
43 5 5 21
38 9 72 82
72 2 1 64
22 7 50 81
74 5 88 89
84 1 25 29
41 48

output:

-1

result:

ok single line: '-1'

Test #6:

score: 5
Accepted
time: 12ms
memory: 77596kb

input:

1 10 20
58 4 59 59
36 88
80 47
56 65
74 45
99 4
17 2
13 46
92 38
82 2
42 47
40 40
30 9
13 41
14 77
61 33
20 73
89 3
89 100
83 100
28 59

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

ok 20 lines

Test #7:

score: 0
Wrong Answer
time: 4ms
memory: 77824kb

input:

20 4 20
61418457 4 33932551 98975124
50805588 3 56616927 66076460
44262243 1 58029464 59272268
34981593 4 10760710 89302332
58741675 3 60670049 77700264
33623668 3 63722438 67824726
62526450 2 43078579 75611393
4274055 2 14095759 73162733
87374777 4 83277088 91743411
94571186 3 89842706 99458411
124...

output:

5876353
42075856
5848467
-1
-1
42932550
-1
24180475
27529716
-1
-1
10879709
16686222
-1
35018819
38405198
41144455
35084106
64627631
6730924

result:

wrong answer 1st lines differ - expected: '10979904', found: '5876353'

Subtask #2:

score: 0
Runtime Error

Test #34:

score: 0
Runtime Error

input:

60000 400 60000
36444793 284 3080519 96564525
76562130 166 22994125 59743695
76399902 168 29694545 59255380
66355790 132 10949454 89347938
40903435 35 29985718 66394219
83300910 368 17240174 54080010
85941830 363 31462093 87304647
73742613 40 29005856 54988711
27852051 29 6132393 88092297
52011498 2...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #55:

score: 0
Runtime Error

input:

300000 60000 300000
52373645 39403 1 100000000
43175904 13875 1 100000000
55098270 40348 1 100000000
69248668 7569 1 100000000
69220659 14654 1 100000000
92585410 38487 1 100000000
41202983 28786 1 100000000
47874378 18728 1 100000000
7254419 14009 1 100000000
94592111 3845 1 100000000
19140558 2773...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%