9048 | 2024-02-13 08:37:14 | Pedri | Bináris fa magassága (50 pont) | cpp17 | Compilation error |
#include <fstream>
#include <cmath>
using namespace std;
int n, m;
int main()
{
ifstream f("be.in");
cin>>n>>m;
int ossz=pow(2, n)-1;
int a[ossz]={1};
int l[ossz]={0};
for(int j=1;j<=n;j++){
for(int i=pow(2, j-1);i<pow(2, j);i++)l[i]=n-j+1;
}
for(int i=1;i<=ossz;i++)a[i]=1;
a[1]=0;
/*for(int i=1;i<=ossz;i++)cout<<l[i]<<" ";
cout<<endl;*/
for(int i=1;i<=m;i++){
int x, y;
cin>>x;
cin>>y;
int s=0;
if(y>a[x]){
a[x]=y;
while(x!=1 && l[x/2]<l[x]+a[x]){
l[x/2]=l[x]+a[x];
x=x/2;
}
}else {
a[x]=y;
while(x!=1){
if(x%2==0)l[x/2]=max(l[x]+a[x], l[x+1]+a[x+1]);
else l[x/2]=max(l[x]+a[x], l[x-1]+a[x-1]);
x=x/2;
}
}
cout<<l[1]-1<<endl;
}
return 0;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:11:5: error: 'cin' was not declared in this scope
11 | cin>>n>>m;
| ^~~
main.cpp:3:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
2 | #include <cmath>
+++ |+#include <iostream>
3 |
main.cpp:43:9: error: 'cout' was not declared in this scope
43 | cout<<l[1]-1<<endl;
| ^~~~
main.cpp:43:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
Exited with error status 1