QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317233 | #8006. Dinosaur Bones Digging | ucup-team2307# | WA | 0ms | 3648kb | C++20 | 3.0kb | 2024-01-28 18:27:26 | 2024-01-28 18:27:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a;i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
//#define int ll
struct Node {
int sm = 0, mx = 0;
Node(int x = 0) : sm(x), mx(max(0, x)) {}
friend Node operator+(const Node &a, const Node &b) {
Node r;
r.sm = a.sm + b.sm;
r.mx = max(a.mx, a.sm + b.mx);
return r;
}
};
struct SegTree {
int n;
vector<Node> tree;
SegTree(int N) : n(2<<__lg(N)), tree(2*n) {}
void add(int pos, int x) {
pos += n;
tree[pos] = Node(tree[pos].sm + x);
while(pos/=2) tree[pos] = tree[2*pos] + tree[2*pos + 1];
}
Node acc(int l, int r) {
Node L, R;
for(l += n, r += n; l < r; l>>=1,r>>=1) {
if(l & 1) L = L + tree[l++];
if(r & 1) R = tree[--r] + R;
}
return L + R;
}
int solve(int l, int r) {
Node pref = acc(0, l + 1);//base is l-th element
Node seg = acc(l + 1, r);//can change to l+1 ... r-1
return pref.sm + seg.mx;
}
};
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, q;
cin >> n;
vector<array<int, 2>> vals(n);
for(int i = 0; i < n; i++) {
cin >> vals[i][0];
vals[i][1] = i;
}
sort(all(vals), greater<>());
cin >> q;
vector<array<int, 2>> queries(q);
for(auto &[l, r] : queries)
cin >> l >> r, l--, r--, r *= -1;
sort(all(queries));
for(auto &[l, r] : queries) r *= -1;
{
vector<array<int, 2>> tmp;
int maxR = -1;
for(auto [l, r] : queries) {
if(r > maxR) {
maxR = r;
tmp.push_back({l, r});
}
}
queries = tmp;
q = tmp.size();
}
vector<array<int, 2>> ranges(n);
for(int l = 0, r = 0, i = 0; i < n; i++) {
while(l < q && queries[l][1] < i) l++;
while(r < q && queries[r][0] <= i) r++;
ranges[i] = {l, r};
// cout << i << " " << l << " " << r << endl;
}
SegTree st(q);
ll ans = 0;
vector<int> stupid(n);
for(auto [val, pos] : vals) {
auto [l, r] = ranges[pos];
ans = max(ans, st.solve(l, r) * 1ll * val);
// cout << val << " " << pos << " " << st.get() << endl;
st.add(l, 1);
st.add(r, -1);
// if(1) {
// for(int i = l; i < r; i++)
// stupid[i]++;
// for(int l = 0; l < q; l++) {
// int cur = 0;
// for(int r = l + 1; r <= q; r++) {
// cur = max(cur, stupid[r- 1]);
// assert(st.solve(l, r) == cur);
// }
// }
// }
}
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3644kb
input:
1 100 1 1 1
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
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:
4830466641
result:
wrong answer expected '4480894680', found '4830466641'