QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388020 | #4590. Happy Travelling | kevinyang# | WA | 58ms | 13808kb | C++17 | 2.2kb | 2024-04-13 09:59:49 | 2024-04-13 09:59:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct SegTree{
int size;
vector<int>arr;
void init(int n){
size = 1;
while(size<n)size*=2;
arr.assign(2*size,-(int)1e18);
}
void set(int i, int v, int x, int lx, int rx){
if(rx-lx==1){
arr[x] = v;
return;
}
int m = (lx+rx)/2;
if(i<m){
set(i,v,2*x+1,lx,m);
}
else{
set(i,v,2*x+2,m,rx);
}
arr[x] = max(arr[2*x+1],arr[2*x+2]);
}
void set(int i,int v){
set(i,v,0,0,size);
}
int query(int l,int r, int x, int lx, int rx){
if(lx>=r||l>=rx)return -(int)1e18;
if(lx>=l&&rx<=r)return arr[x];
int m = (lx+rx)/2;
int s1 = query(l,r,2*x+1,lx,m);
int s2 = query(l,r,2*x+2,m,rx);
return max(s1,s2);
}
int query(int l, int r){
return query(l,r,0,0,size);
}
};
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,k,d;
cin >> n >> k >> d;
vector<int>h(n+1);
for(int i = 1; i<=n; i++){
cin >> h[i];
}
SegTree segtree;
segtree.init(k+5);
vector<set<pair<int,int>>>sets(k+5);
vector<int>add(k);// everything in sets[i] has value v + add[i]
vector<vector<pair<int,int>>>rem(n+5);
vector<int>t(n+1);
for(int i = 1; i<n; i++){
cin >> t[i];
}
for(int i = 1; i<=n; i++){
int dist = h[i];
add[i%k]-=d;
for(auto [dis,idx]: rem[i]){
sets[idx%k].erase({dis,idx});
if(sets[idx%k].size()){
segtree.set(idx%k,(*--sets[idx%k].end()).first + add[idx%k]);
}
else{
segtree.set(idx%k,-(int)1e18);
}
}
segtree.set(i%k,segtree.query(i%k,i%k+1)+add[i%k]);
if(i>1){
dist += segtree.query(0,k);
}
int nd = dist-add[i%k];
sets[i%k].insert({nd,i});
segtree.set(i%k,(*--sets[i%k].end()).first + add[i%k]);
rem[t[i]+1+i].push_back({nd,i});
if(i==n){
cout << dist << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
6 2 1 8 -7 -8 9 0 2 5 3 3 2 1
output:
18
result:
ok single line: '18'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
8 8 8 10 -5 -5 -5 -5 -5 -5 10 5 2 5 3 2 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
13 2 2 -5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7 3 10 9 8 7 6 5 4 3 2 1 1
output:
-9
result:
ok single line: '-9'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 1 0 -10000 10000 1
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 58ms
memory: 13808kb
input:
98987 4 3 -8225 -8961 -5537 -5621 -8143 -5214 -5538 -6912 -6601 -8839 -7872 -7867 -9553 -9793 -7333 -7360 -5820 -7459 -8824 -9716 -9757 -5846 -5300 -5912 -7953 -8360 -7609 -5937 -5525 -9748 -7326 -8311 -9979 -9292 -8542 -7589 -7939 -5914 -7985 -9999 -9212 -8274 -8084 -6620 -5991 -7826 -6327 -5228 -6...
output:
-89105
result:
wrong answer 1st lines differ - expected: '-84108', found: '-89105'