QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196999#5150. Alternating AlgorithmRobeZHWA 1ms7828kbC++142.9kb2023-10-02 07:09:072023-10-02 07:09:07

Judging History

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

  • [2023-10-02 07:09:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7828kb
  • [2023-10-02 07:09:07]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define subnb true
#define Lnb true
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int N = (int)4e5 + 50;
const int INF = (int)1e9;
#define lson(x) 2*x+1
#define rson(x) 2*x+2

struct node {
    ll mx, add;
    void add_val(int x) {
        add += x;
        mx += x;
    }

    void merge(node &ls, node &rs) {
        mx = max(ls.mx, rs.mx);
    }
};

struct Tree {
    node dat[N * 4];

    void init(int n) {
        fill(dat, dat + 4 * n, node{-INF, 0});
    }
    void push_down(int x, int l, int r) {
        if(dat[x].add) {
            if(l < r) {
                dat[lson(x)].add_val(dat[x].add);
                dat[rson(x)].add_val(dat[x].add);
            }
            dat[x].add = 0;
        }
    }
    void update(int a, int b, int x, int l, int r, int d) {
        int mid = (l + r) / 2;
        if(r < a || l > b) return;
        push_down(x, l, r);
        if(l >= a && r <= b) {
            dat[x].add_val(d);
            return;
        }
        update(a, b, lson(x), l, mid, d);
        update(a, b, rson(x), mid + 1, r, d);
        dat[x].merge(dat[lson(x)], dat[rson(x)]);
    }

    void upd(int pos, int x, int l, int r, int val) {
        if(l == r) {
            dat[x] = {val, 0};
            return;
        }
        push_down(x, l, r);
        int mid = (l + r) / 2;
        if(pos <= mid) upd(pos, lson(x), l, mid, val);
        else upd(pos, rson(x), mid + 1, r, val);
        dat[x].merge(dat[lson(x)], dat[rson(x)]);

    }
//    int query(int a, int b, int x, int l, int r) {
//        int mid = (l + r) / 2;
//        if(r < a || l > b) return -INF;
//        push_down(x, l, r);
//        if(l >= a && r <= b) return dat[x].mx;
//        return max(query(a, b, lson(x), l, mid), query(a, b, rson(x), mid + 1, r));
//    }

} tree;

int n;
int a[N];
vector<pii> ps;
int in[N];
int pf = 0;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    n++;
    rep(i, 0, n) cin >> a[i], ps.push_back({a[i], i});
    sort(all(ps));
    tree.init(n);
    ll res = 0;
    int c = 0;
    for (auto p : ps) {
        c++;
        tree.update(0, p.second, 0, 0, n - 1, 2);
        tree.upd(p.second, 0, 0, n - 1, p.second + (p.second % 2 == 0));

        in[p.second] = 1;
        while(pf < n && in[pf]) {
            tree.upd(pf, 0, 0, n - 1, -INF);
            pf++;
        }
        if(pf == c) {
            continue;
        }
//        cout << p.first << " " << tree.dat[0].mx - (c - 1) << endl;

        res = max(res, tree.dat[0].mx - (c - 1));
    }
    cout << res << endl;



}

详细

Test #1:

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

input:

3
8 13 4 10

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7748kb

input:

5
13 12 14 10 14 12

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

2
2 2 1

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5644kb

input:

1
300172042 474444146

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7696kb

input:

1
636357447 557539481

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 1ms
memory: 7648kb

input:

2
139715426 368724097 417561009

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 1ms
memory: 7776kb

input:

2
77784868 542697475 509604021

output:

2

result:

ok single line: '2'

Test #8:

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

input:

2
698395658 71848686 699775597

output:

1

result:

ok single line: '1'

Test #9:

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

input:

2
487635147 571273621 442673389

output:

3

result:

ok single line: '3'

Test #10:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

2
502022170 254766224 258867503

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 1ms
memory: 7788kb

input:

2
783651505 271735448 154090385

output:

3

result:

ok single line: '3'

Test #12:

score: 0
Accepted
time: 1ms
memory: 7764kb

input:

3
423187900 701340783 708457090 788989478

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 1ms
memory: 7784kb

input:

3
172068101 507957913 237246316 805323765

output:

2

result:

ok single line: '2'

Test #14:

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

input:

3
309846480 218704879 536482379 754210806

output:

1

result:

ok single line: '1'

Test #15:

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

input:

3
150235215 485036833 52089968 645641645

output:

3

result:

ok single line: '3'

Test #16:

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

input:

3
735389981 669677621 733676260 858050940

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 1ms
memory: 7788kb

input:

3
635103474 551413670 85269704 730878535

output:

3

result:

ok single line: '3'

Test #18:

score: 0
Accepted
time: 1ms
memory: 7828kb

input:

3
287528440 314452762 846234936 452787633

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 1ms
memory: 7736kb

input:

3
276069955 969481471 992185356 536479156

output:

2

result:

ok single line: '2'

Test #20:

score: 0
Accepted
time: 1ms
memory: 7696kb

input:

3
225096493 88165689 415816372 360778803

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

3
651934487 760368054 975264908 206290402

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

3
668819975 16012633 798541220 258404088

output:

2

result:

ok single line: '2'

Test #23:

score: 0
Accepted
time: 1ms
memory: 7644kb

input:

3
303955151 276719749 324951113 63908344

output:

3

result:

ok single line: '3'

Test #24:

score: 0
Accepted
time: 1ms
memory: 5744kb

input:

3
419862649 709195111 424612582 548104611

output:

3

result:

ok single line: '3'

Test #25:

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

input:

3
46436854 762650424 543885894 63420906

output:

2

result:

wrong answer 1st lines differ - expected: '3', found: '2'