#include <bits/stdc++.h>
using namespace std;
const int N = 200*1000+7;
int a[N];
int b[N];
int t[4*N];
int ind[4*N];
void build(int v,int l,int r){
if(l == r){
t[v] = a[l];
ind[l] = v;
return;
}
int m = (l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
t[v] = min(t[v*2],t[v*2+1]);
}
void update(int v,int s,int e,int l,int r,int val){
if(l>r) return;
if(s == l && e == r){
if(t[v]>val) return;
if(s == e){
if(t[v] == a[l]) t[v] = b[l];
else t[v] = a[l];
return;
}
}
int m = (s+e)/2;
update(v*2,s,m,l,min(m,r),val);
update(v*2+1,m+1,e,max(l,m+1),r,val);
t[v] = min(t[v*2],t[v*2+1]);
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i = 1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
build(1,1,n);
for(int i = 1;i<=k;i++){
int x;
scanf("%d",&x);
update(1,1,n,1,n,x);
}
long long ans = 0;
for(int i = 1;i<=n;i++){
ans+=t[ind[i]];
}
cout<<ans<<endl;
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
~~~~~^~~~~~~~~~~~~~
fortune_telling2.cpp:37:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x);
~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
524 KB |
Output is correct |
3 |
Correct |
15 ms |
524 KB |
Output is correct |
4 |
Correct |
15 ms |
556 KB |
Output is correct |
5 |
Correct |
18 ms |
716 KB |
Output is correct |
6 |
Correct |
14 ms |
716 KB |
Output is correct |
7 |
Correct |
18 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
756 KB |
Output is correct |
10 |
Correct |
8 ms |
780 KB |
Output is correct |
11 |
Correct |
17 ms |
872 KB |
Output is correct |
12 |
Correct |
18 ms |
976 KB |
Output is correct |
13 |
Correct |
16 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
524 KB |
Output is correct |
3 |
Correct |
15 ms |
524 KB |
Output is correct |
4 |
Correct |
15 ms |
556 KB |
Output is correct |
5 |
Correct |
18 ms |
716 KB |
Output is correct |
6 |
Correct |
14 ms |
716 KB |
Output is correct |
7 |
Correct |
18 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
756 KB |
Output is correct |
10 |
Correct |
8 ms |
780 KB |
Output is correct |
11 |
Correct |
17 ms |
872 KB |
Output is correct |
12 |
Correct |
18 ms |
976 KB |
Output is correct |
13 |
Correct |
16 ms |
1024 KB |
Output is correct |
14 |
Correct |
1300 ms |
1548 KB |
Output is correct |
15 |
Execution timed out |
3030 ms |
2248 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
524 KB |
Output is correct |
3 |
Correct |
15 ms |
524 KB |
Output is correct |
4 |
Correct |
15 ms |
556 KB |
Output is correct |
5 |
Correct |
18 ms |
716 KB |
Output is correct |
6 |
Correct |
14 ms |
716 KB |
Output is correct |
7 |
Correct |
18 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
756 KB |
Output is correct |
10 |
Correct |
8 ms |
780 KB |
Output is correct |
11 |
Correct |
17 ms |
872 KB |
Output is correct |
12 |
Correct |
18 ms |
976 KB |
Output is correct |
13 |
Correct |
16 ms |
1024 KB |
Output is correct |
14 |
Correct |
1300 ms |
1548 KB |
Output is correct |
15 |
Execution timed out |
3030 ms |
2248 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |