QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473741 | #6531. Base Station Construction | zzisjtu | WA | 45ms | 5256kb | C++23 | 1.2kb | 2024-07-12 13:47:07 | 2024-07-12 13:47:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
#define LF(x) fixed<<setprecision(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
void solve()
{
int n;
cin>>n;
vector<int>a(n+2);
for(int i=1;i<=n;i++){
cin>>a[i];
}
// a[++n]=0;
int m;
cin>>m;
vector<int>l(m+1),r(m+1);
vector<int>L(n+1);
for(int i=1;i<=m;i++){
cin>>l[i]>>r[i];
L[r[i]]=max(l[i],L[r[i]]);
}
vector<ll>dp(n+1,INF);
deque<int>dq;
dq.push_back(0);
dp[0]=0;
for(int i=1;i<=n;i++){
dp[i]=min(dp[i],dp[dq.front()]+a[i]);
while(!dq.empty()&&dp[dq.back()]>dp[i])dq.pop_back();
dq.push_back(i);
while(!dq.empty()&&dq.front()<L[i])dq.pop_front();
}
cout<<dp[n]<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: 45ms
memory: 5256kb
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 88 59 126 303 141 45 170 159 139 222 194 217 147 230 93 287 89 124 130 148 125 100 193 228 111 239 303 236 150 177 57 59 38 90 128 83 160 108 62 35 122 156 81 115 229 110 242 126 28 210 86 311 244 262 162 302 177 93 238 30 129 75 109 96 179 81 224 142 172 119 111 215 247 301 121 120 56 213 118 3...
result:
wrong answer 2nd numbers differ - expected: '48', found: '88'