QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792040#6531. Base Station ConstructionFoedere0WA 40ms14640kbC++201.5kb2024-11-28 22:59:202024-11-28 22:59:20

Judging History

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

  • [2024-11-28 22:59:20]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:14640kb
  • [2024-11-28 22:59:20]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
int qmi(int a, int k, int p)
{
    int res = 1;
    while (k)
    {
        if (k & 1)
            res = res * a % p;
        a = a * a % p;
        k >>= 1;
    }
    return res;
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n, m;
int a[N];
struct node
{
    int l, r;
} b[N];
int dp[N];
int pre[N];
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        dp[i] = 0;
        pre[i] = 0;
    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i].l >> b[i].r;
        pre[b[i].r + 1] = max(pre[b[i].r + 1], b[i].l); // 最远能从那个点转移过来  两个点之间不能有完整的区间
    }
    for (int i = 1; i <= n + 1; i++)
        pre[i] = max(pre[i], pre[i - 1]);
    // sort(b + 1, b + 1 + n, cmp);
    dp[0] = 0;
    deque<int> heap;
    heap.push_back(0);
    for (int i = 1; i <= n + 1; i++)
    {
        while (heap.size() && heap.front() < pre[i])
            heap.pop_front();
        dp[i] = dp[heap.front()] + a[i];
        while (heap.size() && dp[i] <= dp[heap.back()])
        {
            heap.pop_back();
        }
        heap.push_back(i);
    }
    cout << dp[n + 1] << endl;
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9672kb

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: 40ms
memory: 14640kb

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
146
127
168
309
172
23
223
230
183
203
275
156
111
257
131
325
143
124
224
239
55
16
208
230
145
254
346
323
234
277
155
105
80
91
86
111
204
176
150
90
210
205
108
213
146
85
258
141
119
301
161
381
284
361
184
399
268
184
269
46
133
112
136
115
220
141
224
146
199
119
206
289
247
338
150
166
1...

result:

wrong answer 2nd numbers differ - expected: '48', found: '146'