本地O2与重载运算符的玄学错误
查看原帖
本地O2与重载运算符的玄学错误
389985
最後の祈りを楼主2021/9/11 16:09

编译器名: MinGW GCC 4.8.1 32-bit Debug

用的是devc++6.7.5, 编译开了std=c++11, -Wall未警告

priority_queue加上结构体重载运算符和O2会乱掉

只有本地会错误,洛谷IDE不会出错

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#pragma GCC optimize(2)
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48;ch=getchar();}
    return x*f;
}const int N=1e5+10,p=1e9;

struct edge{
	int to,v;
	
	bool operator <(const edge x)const
	{
//		if(v!=x.v)		不加上注释会乱掉
			return v>x.v;
//		return to>x.to;
	}
};

priority_queue<edge> q;

signed main()
{
	int n=5;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	q.push((edge){i,j});

	while(!q.empty())
	{
		cout<<q.top().to<<" "<<q.top().v<<endl;
		q.pop();
	}
	
    return 0;
}


2021/9/11 16:09
加载中...