QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196995 | #5150. Alternating Algorithm | RobeZH# | WA | 1ms | 7696kb | C++14 | 2.8kb | 2023-10-02 07:06:41 | 2023-10-02 07:06:41 |
Judging History
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 == 1));
in[p.second] = 1;
while(pf < n && in[pf]) {
tree.upd(pf, 0, 0, n - 1, pf);
pf++;
}
if(pf == c) {
continue;
}
// cout << p.first << " " <<
res = max(res, tree.dat[0].mx - (c - 1));
}
cout << res << endl;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7696kb
input:
3 8 13 4 10
output:
2
result:
wrong answer 1st lines differ - expected: '3', found: '2'