QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141042#6531. Base Station Constructioncy1999WA 160ms29180kbC++202.0kb2023-08-17 08:16:092023-08-17 08:16:11

Judging History

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

  • [2023-08-17 08:16:11]
  • 评测
  • 测评结果:WA
  • 用时:160ms
  • 内存:29180kb
  • [2023-08-17 08:16:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std ;

typedef long long ll ;
typedef pair<int , int> PII ;
const int N = 500010 ;
const ll inf = 1e17 ;
int n , a[N] , T , m , mx ;
ll dp[N] ;
PII b[N] ;
vector<int> c[N] ;
set<int> s ;

ll val[N * 4] ;

void build(int p , int l , int r) {
    val[p] = inf ;
    if(l == r) {
        return ;
    }
    int mid = (l + r) >>1 ;
    build(p * 2 , l, mid) ;
    build(p * 2 + 1 , mid + 1, r) ;
    return ;
}

void change(int p , int l , int r , int x , ll v) {
    if(l == r) {
        val[p] = v ;
        return ;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) change(p * 2 , l , mid , x , v) ;
    else change(p * 2 + 1 , mid + 1 , r , x , v) ;
    val[p] = min(val[p * 2] , val[p * 2 + 1]) ;
}

ll query(int p , int l , int r , int ql , int qr) {
    if(ql == 0 || qr == 0) return 0 ;
    if(ql <= l && r<= qr) {
        return val[p] ;
    }
    ll res = inf ; int mid = (l + r) >> 1 ;
    if(ql <= mid) res = min(res , query(p * 2 , l , mid , ql , qr)) ;
    if(qr > mid) res = min(res , query(p * 2 + 1 , mid + 1 , r , ql , qr)) ;
    return res ;
}

int main() {
    cin >> T ;
    while(T --) {
        scanf("%d" , &n) ;
        for(int i = 1 ; i <= n ; i ++) scanf("%d" , &a[i]) ;
        scanf("%d" , &m) ;
        for(int i = 1 ; i <= m ; i ++) scanf("%d%d" , &b[i].first , &b[i].second) ;
        sort(b + 1 , b + m + 1) ;
        for(int i = 1 ; i <= m ; i ++) {
            c[b[i].second].push_back(b[i].first) ;
        }
        mx = 0 ; build(1 , 0 , n) ; change(1 , 0 , n , 0 , 0) ;
        for(int i = 1 ; i <= n ; i ++) {
            dp[i] = query(1 , 0 , n , mx , i - 1) + a[i] ;
            change(1 , 0 , n , i , dp[i]) ;
            for(auto x : c[i]) {
                mx = max(mx , x) ;
            }
        }   
        ll res = inf ;
        for(int i = b[m].first ; i <= b[m].second ; i ++) {
            res = min(res , dp[i]) ;
        }
        printf("%lld\n" , res) ;
    }
    return 0 ;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 20236kb

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: 160ms
memory: 29180kb

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
48
24
193
390
141
113
557
369
166
533
372
727
694
268
169
691
227
624
149
762
658
1
296
853
561
239
608
569
228
177
57
253
314
358
245
499
587
263
133
35
187
768
728
1064
787
637
408
638
883
1132
165
609
244
810
142
302
491
980
427
30
790
238
424
162
179
81
947
174
773
937
878
939
1049
887
65
39...

result:

wrong answer 3rd numbers differ - expected: '4', found: '24'