QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226699#7582. Snowy Smile8BQube#AC ✓391ms3792kbC++202.1kb2023-10-26 14:06:052023-10-26 14:06:05

Judging History

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

  • [2023-10-26 14:06:05]
  • 评测
  • 测评结果:AC
  • 用时:391ms
  • 内存:3792kb
  • [2023-10-26 14:06:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()

const int N = 2005;

struct node {
    ll mx, sum, mxl, mxr;
} seg[N << 2];

int pos[N];

void build(int l, int r, int rt) {
    seg[rt].mx = seg[rt].sum = seg[rt].mxl = seg[rt].mxr = 0;
    if (l == r) {
        pos[l] = rt;
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, rt << 1), build(mid + 1, r, rt << 1 | 1);
}

void up(int rt) {
    seg[rt].mx = max({seg[rt << 1].mx, seg[rt << 1 | 1].mx, seg[rt << 1].mxr + seg[rt << 1 | 1].mxl});
    seg[rt].sum = seg[rt << 1].sum + seg[rt << 1 | 1].sum;
    seg[rt].mxl = max(seg[rt << 1].mxl, seg[rt << 1].sum + seg[rt << 1 | 1].mxl);
    seg[rt].mxr = max(seg[rt << 1].mxr + seg[rt << 1 | 1].sum, seg[rt << 1 | 1].mxr);
}

void modify(int x, ll v) {
    x = pos[x];
    seg[x].sum += v, seg[x].mx += v, seg[x].mxl += v, seg[x].mxr += v;
    while (x > 1) {
        x >>= 1;
        up(x);
    }
}

vector<int> val;

pii arr[2005];
int wei[2005], ycoord[2005];

void solve() {
    int n;
    cin >> n;
    vector<int> idx(n);
    iota(ALL(idx), 1);
    val.clear();
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].X >> arr[i].Y >> wei[i];
        val.pb(arr[i].Y);
    }
    sort(ALL(val)), val.resize(unique(ALL(val)) - val.begin());
    sort(ALL(idx), [&](int x, int y) {
        return arr[x].X < arr[y].X; 
    });
    for (int i = 1; i <= n; ++i)
        ycoord[i] = upper_bound(ALL(val), arr[i].Y) - val.begin();
    ll ans = 0;
    for (int i = 0, j = 0; i < n; i = j) {
        while (j < SZ(idx) && arr[idx[i]].X == arr[idx[j]].X) ++j;
        build(1, SZ(val), 1);
        for (int a = i, b = i; a < n; a = b) {
            while (b < SZ(idx) && arr[idx[a]].X == arr[idx[b]].X) { 
                modify(ycoord[idx[b]], wei[idx[b]]);
                ++b;
            }
            ans = max(ans, seg[1].mx);
        }
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 391ms
memory: 3792kb

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:

1275195744
2084179225
1734353870
1018976777
2591083202
1309403622
2358891488
2143566532
1602649268
2112317422
1470851645
2423431804
2209082718
1571719735
1313345276
2039708041
1526772930
1368470878
866267413
1826546180
1878414495
1706604892
1822460963
1942258759
2943744963
2090539403
666502909
14660...

result:

ok 52 numbers