这个G++编译错误是什么原因造成的?
用VC编译结果正确。。。[code]#include<iostream>#include<algorithm>usingnamespacestd;#defineMN100...
用VC编译结果正确。。。
[code]
#include<iostream>
#include<algorithm>
using namespace std;
#define MN 100005
#define inf 1000000000
int a[MN],c[18][MN],n,m;
struct seg{
int l,r;
}t[MN<<2];
int getval()
{
int ret(0),sgn=1;char c;
do
{c=getchar();}while((c<'0'||c>'9')&&c!='-');
if(c=='-')sgn=-1;else ret=c-'0';
while((c=getchar())>='0'&&c<='9')ret=ret*10+c-'0';
return sgn*ret;
}
void create_tree(int b=1,int e=n,int d=1,int dep=1){
t[d].l=b;
t[d].r=e;
int m=(b+e)>>1;
if(b==e)
c[dep][b]=a[b];
else{
create_tree(b,m,d*2,dep+1);
create_tree(m+1,e,d*2+1,dep+1);
int i=b,j=m+1,ind=b;
while(i<=m&&j<=e)
if(c[dep+1][i]<c[dep+1][j])
c[dep][ind++]=c[dep+1][i],++i;
else
c[dep][ind++]=c[dep+1][j],++j;
while(i<=m)
c[dep][ind++]=c[dep+1][i],++i;
while(j<=e)
c[dep][ind++]=c[dep+1][j],++j;
}
}
int count(int b,int e,int v,int d=1,int dep=1){
if(t[d].l==b&&e==t[d].r)
return upper_bound(&c[dep][b],&c[dep][e+1],v)-(&c[dep][b]);
else{
int m=(t[d].l+t[d].r)>>1;
if(e<=m)
return count(b,e,v,d*2,dep+1);
else if(b>m)
return count(b,e,v,d*2+1,dep+1);
else
return count(b,m,v,2*d,dep+1)+count(m+1,e,v,2*d+1,dep+1);
}
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
a[i]=getval();
create_tree();
int b,e,cnt,mid,x,y;
while(m--)
{ b=getval();
e=getval();
cnt=getval();
x=1,y=n;
while(x<=y){
mid=(x+y)>>1;
if(count(b,e,c[1][mid])<cnt)
x=mid+1;
else
y=mid-1;
}
printf("%d\n",c[1][x]);
}
}
}
[/code]
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h: In instantiation of `std::iterator_traits<int>':
0_0_1338683_9507.cpp:69: instantiated from here
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:129: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:130: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:131: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:132: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:133: error: `int' is not a class, struct, or union type
悲剧不是这个 int ret(0),sgn=1;
的问题。。。 展开
[code]
#include<iostream>
#include<algorithm>
using namespace std;
#define MN 100005
#define inf 1000000000
int a[MN],c[18][MN],n,m;
struct seg{
int l,r;
}t[MN<<2];
int getval()
{
int ret(0),sgn=1;char c;
do
{c=getchar();}while((c<'0'||c>'9')&&c!='-');
if(c=='-')sgn=-1;else ret=c-'0';
while((c=getchar())>='0'&&c<='9')ret=ret*10+c-'0';
return sgn*ret;
}
void create_tree(int b=1,int e=n,int d=1,int dep=1){
t[d].l=b;
t[d].r=e;
int m=(b+e)>>1;
if(b==e)
c[dep][b]=a[b];
else{
create_tree(b,m,d*2,dep+1);
create_tree(m+1,e,d*2+1,dep+1);
int i=b,j=m+1,ind=b;
while(i<=m&&j<=e)
if(c[dep+1][i]<c[dep+1][j])
c[dep][ind++]=c[dep+1][i],++i;
else
c[dep][ind++]=c[dep+1][j],++j;
while(i<=m)
c[dep][ind++]=c[dep+1][i],++i;
while(j<=e)
c[dep][ind++]=c[dep+1][j],++j;
}
}
int count(int b,int e,int v,int d=1,int dep=1){
if(t[d].l==b&&e==t[d].r)
return upper_bound(&c[dep][b],&c[dep][e+1],v)-(&c[dep][b]);
else{
int m=(t[d].l+t[d].r)>>1;
if(e<=m)
return count(b,e,v,d*2,dep+1);
else if(b>m)
return count(b,e,v,d*2+1,dep+1);
else
return count(b,m,v,2*d,dep+1)+count(m+1,e,v,2*d+1,dep+1);
}
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
a[i]=getval();
create_tree();
int b,e,cnt,mid,x,y;
while(m--)
{ b=getval();
e=getval();
cnt=getval();
x=1,y=n;
while(x<=y){
mid=(x+y)>>1;
if(count(b,e,c[1][mid])<cnt)
x=mid+1;
else
y=mid-1;
}
printf("%d\n",c[1][x]);
}
}
}
[/code]
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h: In instantiation of `std::iterator_traits<int>':
0_0_1338683_9507.cpp:69: instantiated from here
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:129: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:130: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:131: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:132: error: `int' is not a class, struct, or union type
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator_base_types.h:133: error: `int' is not a class, struct, or union type
悲剧不是这个 int ret(0),sgn=1;
的问题。。。 展开
2个回答
展开全部
他说int不是一个类、结构体或共用体类型,所以是int的用法有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询