QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#702109#6531. Base Station Constructionlibantian#WA 46ms6376kbC++231015b2024-11-02 15:19:082024-11-02 15:19:09

Judging History

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

  • [2024-11-02 15:19:09]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:6376kb
  • [2024-11-02 15:19:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()
#define rep(i,p,q) for (int i=(p);i<=(q);i++)
#define pre(i,p,q) for (int i=(p);i>=(q);i--)
const int N=1e5+5; int n,a[N],p[N],f[N];
void solve(){
    int m,l,r; queue<int>q;
    cin>>n;
    rep(i,1,n) cin>>a[i];
    n++;
    rep(i,1,n) f[i]=1e9,p[i]=0;
    cin>>m;
    rep(i,1,m) cin>>l>>r,p[r]=max(p[r],l);
    rep(i,1,n) p[i]=max(p[i],p[i-1]);
    q.push(0);
    rep(i,1,n) {
        for (;q.size()&&q.front()<p[i-1];) q.pop();
        f[i]=f[q.front()]+a[i];
        for (;q.size()&&f[q.front()]>f[i];) q.pop();
        q.push(i);
    }
    cout<<f[n]<<"\n";
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << setiosflags(ios::fixed) << setprecision(15);
    int T;
    T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5660kb

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: 46ms
memory: 6376kb

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:

209
146
72
199
368
172
42
273
245
183
226
287
156
126
257
165
325
143
215
224
239
74
16
208
267
127
254
346
323
234
277
155
105
144
158
86
111
204
219
150
90
256
205
108
269
184
85
258
141
212
387
161
381
284
432
184
399
172
330
269
46
133
112
158
132
220
141
382
178
208
77
323
289
373
248
153
236
1...

result:

wrong answer 1st numbers differ - expected: '141', found: '209'