QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709732#6531. Base Station ConstructionSunwkingWA 44ms5180kbC++201.1kb2024-11-04 16:32:582024-11-04 16:32:58

Judging History

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

  • [2024-11-04 16:32:58]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:5180kb
  • [2024-11-04 16:32:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using PII = pair<int , int>;

const int N = 1e6 + 10 , Mod = 1e9 + 7;

int q[N];

void solved(){
    int n;
    cin >> n;

    vector<int> a(n + 1) , l(n + 1);
    vector<int> ls(n + 1);
    for(int i = 1 ; i <= n ; i ++ )
        cin >> a[i];
    int m;
    cin >> m;
    while(m -- ){
        int L , R;
        cin >> L >> R;
        l[R] = max(l[R] , L + 1);
    }

    int last = 0;
    for(int i = 1 ; i <= n ; i ++ ){
        if(l[i]) last = max(l[i] , last);
        ls[i] = last;
    }

    vector<LL> f(n + 1 , 2e18);
    f[0] = 0;
    int tt = 0 , hh = 0;
    q[0] = 0;

    for(int i = 1 ; i <= n ; i ++ ){
        if(hh <= tt && q[hh] < ls[i - 1] - 1) hh ++;

        f[i] = f[q[hh]] + a[i];
        while(hh <= tt && f[q[tt]] >= f[i]) tt --;
        q[++ tt] = i;
    }

    cout << f[n] << endl;
}

int main() {

//     freopen("D:\\dev\\code\\sunwking\\1.in" , "r" , stdin);

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;

    while(t -- )
        solved();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

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: 44ms
memory: 5180kb

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
88
59
126
229
141
45
170
159
139
222
133
217
114
230
93
218
89
95
51
111
107
100
192
228
59
239
141
218
150
177
57
50
38
90
128
83
143
24
47
35
122
129
81
115
215
77
242
116
28
210
56
152
244
262
156
302
177
93
148
30
129
75
52
96
179
81
209
142
172
102
111
166
247
258
77
120
49
213
99
262
103
1...

result:

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