QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#418680 | #6531. Base Station Construction | DaDian# | WA | 122ms | 30564kb | C++20 | 1.5kb | 2024-05-23 15:06:50 | 2024-05-23 15:06:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5+7,mod=1e9+7,INF=1e15;
struct Node{
ll mn = INF;
};
struct SegmentTree{
vector<Node>t;
SegmentTree(int n) {
t.resize(n << 5);
}
void modify(int p, int l, int r, int x, ll d) {
if(l == r) {
t[p].mn = d;
return;
}
int mid = (l + r) >> 1;
if(x <= mid) modify(p << 1, l, mid, x, d);
else modify(p << 1 | 1, mid + 1, r, x, d);
t[p].mn = min(t[p << 1].mn, t[p << 1 | 1].mn);
}
ll query(int p, int l , int r, int ql, int qr) {
if(ql <= l && qr >= r) {
return t[p].mn;
}
ll ans = INF, mid = (l + r) >> 1;
if(ql <= mid) {
ans = query(p << 1, l, mid, ql, qr);
}
if(qr > mid) {
ans = min(ans, query(p << 1 | 1, mid + 1, r, ql, qr));
}
return ans;
}
};
void solve(){
int n, m;
cin >> n;
vector<ll>a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> m;
map<ll, ll>mp;
ll mxl = 0;
for(int i = 1; i <= m; i++) {
ll l, r; cin >> l >> r;
mp[r] = max(mp[r], l);
// mxl = max(mxl, l);
}
SegmentTree seg(n + 1);
ll ans;
for(int i = 1; i <= n; i++) {
if(!mxl) ans = 0;
else ans = seg.query(1, 1, n ,mxl, i);
if(mp.find(i) != mp.end()) mxl = mp[i];
seg.modify(1, 1, n, i, ans + a[i]);
}
ans = INF;
for(int i = mxl; i <= n; i++) ans = min(ans, seg.query(1, 1, n, i, i));
cout << ans << "\n";
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
ll T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 5 3 2 4 1 100 3 1 3 2 4 5 5 5 7 3 4 2 2 3 1 4 2 3 4 5
output:
102 5
result:
ok 2 number(s): "102 5"
Test #2:
score: -100
Wrong Answer
time: 122ms
memory: 30564kb
input:
6201 12 88 78 46 95 84 98 55 3 68 42 6 18 19 6 9 10 11 12 12 8 11 8 12 2 3 2 3 1 5 9 9 7 8 6 11 2 4 12 12 2 4 2 9 7 10 8 8 1 7 6 11 5 76 27 48 66 61 2 1 4 3 5 8 64 81 20 6 86 9 4 55 1 7 7 9 1 43 18 81 11 22 9 61 83 14 5 6 2 6 5 8 1 4 9 9 9 9 7 7 2 5 8 9 5 6 4 8 5 8 9 9 6 6 10 66 41 84 7 80 31 22 96 ...
output:
73 48 4 95 303 141 23 170 159 139 131 194 95 68 230 93 109 89 120 130 143 27 1 193 36 93 239 303 152 150 177 57 46 18 24 66 83 160 108 62 35 122 111 81 115 111 45 211 94 7 94 86 272 244 262 87 302 81 86 16 30 129 40 91 60 179 81 88 142 97 77 111 110 247 211 53 65 17 213 101 184 137 171 24 194 153 10...
result:
wrong answer 1st numbers differ - expected: '141', found: '73'