QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419900 | #6531. Base Station Construction | Beater | WA | 59ms | 9808kb | C++17 | 1.6kb | 2024-05-24 12:23:56 | 2024-05-24 12:23:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define int ll
const ll INF=0x3f3f3f3f3f3f3f3f;
void solve(){
int n;
cin>>n;
vector<ll> a(n+1,0);
for(int i=1;i<=n;i++){
cin>>a[i];
}
int m;
cin>>m;
vector<pair<int ,int > > b(m+1);
vector<vector<int > > res(n+1);
for(int i=1;i<=m;i++){
cin>>b[i].first>>b[i].second;
res[b[i].second].push_back(i);
}
vector<int > p(n+2,0);
for(int i=1;i<=n+1;i++){
p[i]=p[i-1];
if(res[i-1].empty()){
continue;
}
for(auto t:res[i-1]){
p[i]=max(p[i],b[t].first);
}
}
vector<ll > dp(n+1,0);
deque<int> Q; // 存储的是编号
Q.push_back(0);
for(int i=1;i<=n;i++){
if (!Q.empty() && Q.front()<p[i]) // 毕业
Q.pop_front();
dp[i]=dp[Q.front()]+a[i];
while (!Q.empty() && dp[Q.back()] > dp[i]) // 比新生弱的当场退役(求区间最小值把这里改成>即可)
Q.pop_back();
Q.push_back(i); // 新生入队
}
// for(int i=1;i<=n;i++){
// cout<<p[i]<<" \n"[i==n];
// }
// for(int i=1;i<=n;i++){
// cout<<dp[i]<<" \n"[i==n];
// }
ll ans=INF;
for(int i=n;i>=p[n+1];i--){
ans=min(ans,dp[i]);
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
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: 59ms
memory: 9808kb
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:
141 48 4 126 229 141 23 170 159 139 153 133 136 68 230 93 178 89 95 51 111 9 1 192 194 59 239 141 218 150 177 57 46 18 24 66 83 143 24 47 35 122 129 81 115 135 52 242 116 28 171 56 152 244 262 68 302 81 86 83 30 129 75 34 90 179 81 209 142 154 74 111 166 247 168 53 66 17 213 82 254 103 177 24 145 14...
result:
wrong answer 5th numbers differ - expected: '303', found: '229'