QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#257924#7582. Snowy Smileddl_VS_pigeon#WA 42ms3868kbC++173.1kb2023-11-19 13:49:452023-11-19 13:49:47

Judging History

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

  • [2023-11-19 13:49:47]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:3868kb
  • [2023-11-19 13:49:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll lnf = 1e18;

struct Segt {
    struct T {
        ll tag, mx, mn;
        T() : tag(0), mx(0), mn(0) {}
        void add(int val) { tag += val, mx += val, mn += val; }
    };
    int n;
    vector<T> t;
    Segt(int _n) : n(_n), t(n << 2 | 1) {}
    void add(int al, int ar, int val) { add(al, ar, val, 1, 0, n - 1); }
    ll getmx(int ql, int qr) { return getmx(ql, qr, 1, 0, n - 1); }
    ll getmn(int ql, int qr) { return getmn(ql, qr, 1, 0, n - 1); }
#define mid ((l + r) >> 1)
#define ls (v << 1)
#define rs (v << 1 | 1)
    void add(int al, int ar, int val, int v, int l, int r) {
        if (ar < l || al > r) {
            return;
        }
        if (al <= l && ar >= r) {
            t[v].add(val);
        } else {
            add(al, ar, val, ls, l, mid);
            add(al, ar, val, rs, mid + 1, r);
            t[v].mx = max(t[ls].mx, t[rs].mx) + t[v].tag;
            t[v].mn = min(t[ls].mn, t[rs].mn) + t[v].tag;
        }
    }
    ll getmx(int ql, int qr, int v, int l, int r) {
        if (qr < l || ql > r) {
            return -lnf;
        }
        if (ql <= l && qr >= r) {
            return t[v].mx;
        } else {
            return max(getmx(ql, qr, ls, l, mid),
                       getmx(ql, qr, rs, mid + 1, r)) +
                   t[v].tag;
        }
    }
    ll getmn(int ql, int qr, int v, int l, int r) {
        if (qr < l || ql > r) {
            return lnf;
        }
        if (ql <= l && qr >= r) {
            return t[v].mn;
        } else {
            return min(getmn(ql, qr, ls, l, mid),
                       getmn(ql, qr, rs, mid + 1, r)) +
                   t[v].tag;
        }
    }
#undef rs
#undef ls
#undef mid
};

void solve() {
    int n;
    cin >> n;
    struct P {
        int x, y, w;
    };
    vector<P> p(n);
    vector<int> vx, vy;
    for (auto& [x, y, w] : p) {
        cin >> x >> y >> w;
        vx.emplace_back(x);
        vy.emplace_back(y);
    }
    sort(vx.begin(), vx.end());
    vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());
    for (auto& [x, y, w] : p) {
        x = lower_bound(vx.begin(), vx.end(), x) - vx.begin() + 1;
        y = lower_bound(vy.begin(), vy.end(), y) - vy.begin() + 1;
    }
	sort(p.begin(), p.end(), [](const P &a, const P &b) {
		return a.x < b.x;
	});
    ll ans = 0;
    for (int i = 0; i < n;) {
        Segt tr(vy.size() + 1);
        int j = i;
        while (j < n && p[j].x == p[i].x) {
            ++j;
        }
        for (int k = i; k < j; k++) {
            tr.add(p[k].y, vy.size(), p[k].w);
        }
        for (int k = i; k < j; k++) {
            ans =
                max(ans, tr.getmx(p[k].y, vy.size()) - tr.getmn(0, p[k].y - 1));
        }
        i = j;
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3792kb

input:

2
4
1 1 50
2 1 50
1 2 50
2 2 -500
2
-1 1 5
-1 1 1

output:

100
6

result:

ok 2 number(s): "100 6"

Test #2:

score: -100
Wrong Answer
time: 42ms
memory: 3868kb

input:

52
10
30 -1 -40065867
-15 -74 -695603735
-14 3 -847010045
33 -92 -458180374
-88 -86 -488393753
50 -91 -949931576
39 -99 -168684248
-29 64 783067879
14 -5 -104144786
-67 90 492127865
10
-29 -70 151800541
54 41 -677722362
-85 -72 766300892
-47 -90 -74384884
-12 -56 679506148
0 -41 -30038154
-4 -6 -254...

output:

783067879
766300892
994100068
901275923
872354235
730596027
893315423
867947203
950808787
867301747
794597342
639275654
735787644
799956609
849013201
892854273
735821201
959675440
519863348
897729398
972395417
985683136
939454734
879598697
683339575
755884904
610229288
826179841
896229946
885086038
...

result:

wrong answer 1st numbers differ - expected: '1275195744', found: '783067879'