QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795691#6531. Base Station ConstructionRUOHUIWA 0ms3636kbC++201.0kb2024-11-30 23:17:532024-11-30 23:17:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-30 23:17:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-11-30 23:17:53]
  • 提交

answer

#include "bits/stdc++.h"
#define int long long
using namespace std;

int n, m;

void solve()
{
    cin >> n;
    vector<int> a(n + 2), R(n + 2);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        int l, r;
        cin >> l >> r;
        R[r] = max(R[r], l);
    }
    deque<int> q;
    q.emplace_back(0);
    vector<int> dp(n + 2);
    for (int i = 1; i <= n + 1; i++)
    {
        dp[i] = dp[q.front()] + a[i];
        while (q.size() && dp[q.back()] > dp[i])
        {
            q.pop_back();
        }
        q.emplace_back(i);
        if (q.size() && q.front() < R[i])
        {
            q.pop_front();
        }
    }
    cout << dp[n + 1] << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

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:

3
4

result:

wrong answer 1st numbers differ - expected: '102', found: '3'