QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141167#6531. Base Station Constructioncy1999WA 171ms17676kbC++171.4kb2023-08-17 09:10:072023-08-17 09:10:08

Judging History

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

  • [2023-08-17 09:10:08]
  • 评测
  • 测评结果:WA
  • 用时:171ms
  • 内存:17676kb
  • [2023-08-17 09:10:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

int n,a[500100],m,l[500100],r[500100],cnt,tr[500100*4];
bool ok[500100];
int ans=0;

void build(int id,int l,int r){
	if(l==r){
		tr[id]=a[l];
		return;
	}
	int mid=(l+r)/2;
	build(id*2,l,mid);
	build(id*2+1,mid+1,r);
	tr[id]=min(tr[id*2],tr[id*2+1]);
//	cout<<id<<" "<<tr[id]<<endl;
}

int query(int id,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr){
		return tr[id];
	}
	int mid=(l+r)/2;
	int w1=1e9+10,w2=1e9+10;
	if(ql<=mid) w1=query(id*2,l,mid,ql,qr);
	if(qr>mid) w2=query(id*2+1,mid+1,r,ql,qr);
	return min(w1,w2);
}

signed main(){
	int t;cin>>t;
	while(t--){
		cin>>n;cnt=0;ans=0;
		a[0]=1e9+10;
		for(int i=1;i<=n;i++) {
			cin>>a[i];
		}
		build(1,1,n);
		cin>>m;
		for(int i=1;i<=m;i++) {
			cin>>l[i]>>r[i];
		}
		l[m+1]=n+100;
		for(int i=1;i<=m;i++){
			int w=0,w1=0,w2=0,idd=0;
			if(r[i]>=l[i+1]){
			//	cout<<i<<" "<<"done1"<<endl;
				w=query(1,1,n,max(l[i],l[i+1]),min(r[i],r[i+1]));
				if(i<m){
					w1=query(1,1,n,l[i],r[i]);
					w2=query(1,1,n,l[i+1],r[i+1]);
				}else{
					w1=1e9,w2=1e9;
				}	
				if(w1+w2<=w){
					ans+=w1;
				}else{
					ans+=w;
					i++;
				}
			}else{
			//	cout<<i<<" "<<"done2"<<endl;
				idd=query(1,1,n,l[i],r[i]);
				ans+=idd;
			} 
		//	cout<<idd<<" "<<w1<<" "<<w2<<" "<<w<<endl;
		}
		cout<<ans<<endl;
		 
	}
	
	
	return 0;
}

详细

Test #1:

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

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: 171ms
memory: 17676kb

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:

355
48
4
310
525
322
46
277
201
578
339
343
285
228
470
195
485
178
128
162
381
27
1
263
362
152
569
303
545
350
983
228
46
18
41
88
88
200
334
140
70
158
242
192
115
149
106
529
340
77
305
226
594
676
421
142
758
81
97
173
300
129
211
95
185
597
648
444
240
271
152
111
259
398
211
53
85
17
456
189
...

result:

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