QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304860#8006. Dinosaur Bones Diggingucup-team992#WA 1ms3588kbC++173.2kb2024-01-14 04:34:232024-01-14 04:34:23

Judging History

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

  • [2024-01-14 04:34:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3588kb
  • [2024-01-14 04:34:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef int uci;
typedef long long ll;
#define int long long
#define F first
#define S second
#define ar array

int n;

void update(int v, int val, int l, int r, int lq, int rq, vector<ar<int, 2>> &seg){
    if(l > r || lq > r || rq < l)
        return;
    else if(lq <= l && r <= rq){
        seg[v][1] += val;
        seg[v][0] += val;
    }else{
        int mid = l + (r-l)/2;
        if(seg[v][1] != 0){
            update(v*2, seg[v][1], l, mid, l, mid, seg);
            update(v*2+1, seg[v][1], mid+1, r, mid+1, r, seg);
            seg[v][0] = max(seg[v*2][0], seg[v*2+1][0]);
            seg[v][1] = 0;
        }

        update(v*2, val, l, mid, lq, rq, seg);
        update(v*2+1, val, mid+1, r, lq, rq, seg);
    }
}

int query(int v, int l, int r, int lq, int rq, vector<ar<int, 2>> &seg){
    if(l > r || rq < l || lq > r)
        return 0;
    else if(lq <= l && r <= rq)
        return seg[v][0];
    else{
        int mid= l + (r-l)/2;
        if(seg[v][1] != 0){
            update(v*2, seg[v][1], l, mid, l, mid, seg);
            update(v*2+1, seg[v][1], mid+1, r, mid+1, r, seg);
            seg[v][0] = max(seg[v*2][0], seg[v*2+1][0]);
            seg[v][1] = 0;
        }
        return max(query(v*2, l, mid, lq, rq, seg), query(v*2+1, mid+1, r, lq, rq, seg));
    }
}

void solve(){
    cin >> n;
    vector<ar<int, 2>> a(n);
    for(int i{}; i < n; ++i){
        cin >> a[i][0];
        a[i][1] = i;
    }

    int m;
    cin >> m;
    vector<ar<int, 2>> b(m);
    for(int i{}; i < m; ++i){
        cin >> b[i][0] >> b[i][1];
        b[i][0]--, b[i][1]--;
    }
    sort(b.begin(), b.end(), [](auto a, auto b){
        return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0];
            });
    vector<ar<int, 2>> c;
    int furthest = -1;
    for(int i{}; i < m; ++i){
        if(b[i][1] > furthest)
            c.push_back(b[i]);
        furthest = max(furthest, c.back()[1]);
    }
    m = c.size();
    b.swap(c);

    vector<ar<int, 2>> seg(4*m);
    sort(a.rbegin(), a.rend());

    int out{};
    for(int i{}; i < n; ++i){
        int lb = m, rb{};
        int l = 0, r = m-1;
        while(l <= r){
            int mid = l + (r-l)/2;
            if(b[mid][0] <= a[i][1] && a[i][1] <= b[mid][1]){
                lb = mid;
                r = mid-1;
            }else{
                if(b[mid][1] < a[i][1])
                    l = mid+1;
                else
                    r = mid-1;
            }
        }
        l = 0, r = m-1;
        while(l <= r){
            int mid = l + (r-l)/2;
            if(b[mid][0] <= a[i][1] && a[i][1] <= b[mid][1]){
                rb = mid;
                l = mid+1;
            }else{
                if(b[mid][1] < a[i][1])
                    l = mid+1;
                else
                    r = mid-1;
            }
        }
        if(lb <= rb){
            int bb = query(1, 0, m-1, lb, rb, seg);
            out = max(out, a[i][0]*bb);
            update(1, 1, 0, m-1, lb, rb, seg);
        }
    }
    cout << out << '\n';
}

uci main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3520kb

input:

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

output:

9

result:

ok answer is '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

1
100
1
1 1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

20
451541695 690066663 673479208 448269517 560111835 982439295 929007403 955125568 735150915 829197546 256554877 435297385 348361716 763574893 202875223 881879899 590527232 256896900 31383620 400212120
5
4 8
4 17
11 13
19 20
17 18

output:

4480894680

result:

ok answer is '4480894680'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

100
310791482 148245051 114541081 918781914 681485137 656214017 226939378 970492592 431199764 162399115 490488808 3059986 487892489 611730708 952388887 418021477 917893766 587279310 363995315 342188612 72531000 156997725 896382592 359419647 144773021 872005978 496280920 65840663 56171913 273988049 6...

output:

23457460782

result:

ok answer is '23457460782'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

1000
653152089 378327983 557774751 390757038 4471201 856292034 205122039 30258841 396640873 159207453 703775065 793745674 681241216 876218560 582247644 205933914 957242345 112988670 939157518 525653622 262606938 993539583 451620719 700727137 142726078 430071359 426031860 471766448 94089907 167433741...

output:

241770338578

result:

wrong answer expected '242077104830', found '241770338578'