用g++编译c++程序的时候,出现了报错Floating point exception: 8
后来一经测试,发现rand() % 0搞的鬼,对0取模就会这样,所以用%前一定要判断下非0才行。文章来源:https://www.toymoban.com/news/detail-622522.html
是因为使用我的gcd,然后没有对a=0时进行特判文章来源地址https://www.toymoban.com/news/detail-622522.html
#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
#define int long long
struct Query
{
int id, l, r;
} q[N];
set<int> st; // 开一个set维护当前区间出现的袜子
int cnt[N], block;
int n, m, a[N], ans[N], ans2[N], sum;
int gcd(int a, int b)
{
return !b ? a : gcd(b, a % b);
}
int get_block(int x)
{
return x / block;
}
bool cmp(const Query &x, const Query &y)
{
int a = get_block(x.l);
int b = get_block(y.l);
if (a != b)
return a < b;
if (a & 1)
return x.r < y.r;
return x.r > y.r;
}
void add(int x, int &res)
{
// st.insert(x);
sum += cnt[x];
cnt[x]++;
}
void del(int x, int &res)
{
// if (cnt[x] == 0)
// {
// st.erase(x);
// return;
// }
cnt[x]--;
sum -= cnt[x];
// if (cnt[x] == 0)
// st.erase(x);
}
signed main()
{
scanf("%lld%lld", &n, &m);
block = n/sqrt(m*2/3);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= m; i++)
{
int l, r;
scanf("%lld%lld", &l, &r);
q[i] = {i, l, r};
ans2[i] = (r - l) * (r - l + 1) / 2;
}
sort(q + 1, q + 1 + m, cmp);
for (int k = 1, res = 0, i = 0, j = 1; k <= m; k++)
{
int id = q[k].id, l = q[k].l, r = q[k].r;
while (i < r)
add(a[++i], res);
while (i > r)
del(a[i--], res);
while (j < l)
del(a[j++], res);
while (j > l)
add(a[--j], res);
// res = 0;
// for (int it : st)
// res += cnt[it] * (cnt[it] - 1) / 2;
ans[id] = sum;
}
for (int i = 1; i <= m; i++)
{
if(ans[i] == 0) {cout << "0/1" <<endl;continue;}
int d = gcd(ans[i], ans2[i]);
printf("%lld/%lld\n", ans[i]/d, ans2[i]/d);
}
}
到了这里,关于洛谷 Floating point exception: 8 Floating-point exception. 报错的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!