QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#157739#6531. Base Station Constructioncy1999TL 3ms10068kbC++1.1kb2023-09-02 15:47:332023-09-02 15:47:33

Judging History

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

  • [2023-09-02 15:47:33]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:10068kb
  • [2023-09-02 15:47:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int const maxn = 5e5 + 10;
int const inf = 1e9+10;

struct node {
	int l,r;
	
}p[maxn];

bool cmp(node a,node b){
	if(a.l==b.l){
		return a.r<b.r;
	}else return a.l < b.l;
}
int a[maxn];

int f[maxn];
signed main(){
	int t;
	cin >> t ;
	while(t--){
	 	int n;
	 	memset(f,0,sizeof f);
	    cin >> n;
	    for(int i = 1;i <= n;i ++){
	    	cin >> a[i];
	    }
	    int m;
	    cin >> m ;
	    for(int i = 1;i <= m;i ++){
	    	cin >> p[i].l>>p[i].r;
	    }
	    sort(p+1,p+m+1,cmp);
	    
	    for(int i = 1;i <= m;i ++){
	    	int tmp = inf;
			for(int j = p[i].l;j <= p[i].r;j ++){
	    		if(f[j]){
	    			tmp = min(f[j],tmp);
	    		}
	    	}
	    	int minn = p[i].l;
	    	if(tmp == inf){
	    		for(int j = p[i].l;j <= p[i].r;j ++){
	    			if(a[j] < a[minn]){
	    				minn = j;
	    			}
	    		}
	    	}
	    	f[minn] = a[minn];
	    }
	    int ans = 0;
	    for(int i = 1;i <= n;i ++){
	    	ans += f[i];
	    }
	    cout << ans <<'\n';
	}
    
	 	
}

详细

Test #1:

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

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
Time Limit Exceeded

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:

460
75
4
311
366
200
78
170
159
192
366
293
459
310
268
169
439
161
220
130
443
27
1
193
493
168
239
354
434
150
177
57
46
18
138
96
232
160
175
78
35
122
262
118
199
277
157
314
302
369
483
126
416
244
503
142
302
81
217
271
30
129
145
204
131
179
81
593
200
285
311
190
330
469
211
53
220
17
255
21...

result: