这个代码为什么编译错误?

P1725 琪露诺

FishingStar @ 2020-11-20 22:47:02

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
struct qwq{
    long long time, t;
};
qwq a[300005];
long long s[300005];
int main(){
    register int n, l, r;
    cin >> n >> l >> r;
    for(int i = 0; i <= n; i++){
        cin >> a[i].t;
        a[i].time = i;
    }
    deque<qwq> q;
    for(int i = 1; i <= n + r; i++){
        while(!q.empty() && q.front().time < i - r){
            q.pop_front();
        }
        while(!q.empty() && q.end().t < a[i].t){
            q.pop_back();
        }
        q.push_back(a[i]);
        s[i] = q.front() + a[i].t;
    }
    long long ans  = -1e18;
    for(int i = n + 1; i <= n + r; i++){
        ans = max(ans, s[i]);
    }
    cout << ans;
    return 0;
}

by _5011_ @ 2020-11-20 22:49:39

#include<queue>


by Ryo_Yamada @ 2020-11-20 22:49:56

#include <deque>


by FishingStar @ 2020-11-20 22:53:25

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<deque>
#include<queue>
using namespace std;
struct qwq{
    long long time, t;
};
qwq a[300005];
long long s[300005];
int main(){
    register int n, l, r;
    cin >> n >> l >> r;
    for(int i = 0; i <= n; i++){
        cin >> a[i].t;
        a[i].time = i;
    }
    deque<qwq> q;
    for(int i = 1; i <= n + r; i++){
        while(!q.empty() && q.front().time < i - r){
            q.pop_front();
        }
        while(!q.empty() && q.end().t < a[i].t){
            q.pop_back();
        }
        q.push_back(a[i]);
        s[i] = q.front() + a[i].t;
    }
    long long ans  = -1e18;
    for(int i = n + 1; i <= n + r; i++){
        ans = max(ans, s[i]);
    }
    cout << ans;
    return 0;
}

还是爆炸啊


by FishingStar @ 2020-11-20 22:53:46

@BreezeEnder 这……


by Ryo_Yamada @ 2020-11-20 22:55:02

@星星之火 q.end() 可还行


by Ryo_Yamada @ 2020-11-20 22:55:54

@星星之火 q.end() -> q.back(),还有下面 s[i] = q.front() + a[i].t;


by FishingStar @ 2020-11-21 00:01:31

@BreezeEnder 谢谢,已A


|