You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<functional>intmain()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
for (int tt = 0; tt < t; tt++)
{
int n;
longlong x, y;
std::cin >> n >> x >> y;
std::vector<longlong> a(n);
for (int i = 0; i < n; i++) std::cin >> a[i];
std::vector<longlong> tree[(n + 7) << 2];
auto tree_build = [&](thisautoconst &tree_build, int v, int tl, int tr) -> void
{
if (tl == tr)
tree[v] = { a[tl] };
else
{
inttm = (tl + tr) >> 1;
tree_build(v << 1, tl, tm);
tree_build((v << 1) | 1, tm + 1, tr);
std::merge(tree[v << 1].begin(), tree[v << 1].end(),
tree[(v << 1) | 1].begin(), tree[(v << 1) | 1].end(),
std::back_inserter(tree[v]));
}
};
//std::function<long long(int, int, int, int, int, long long, long long)> tree_query;auto tree_query = [&](thisautoconst &tree_query, int v, int tl, int tr, int l, int r, longlong low, longlong high) -> longlong
{
if (l > r)
return0;
if (l == tl && tr == r)
{
auto it_low = std::lower_bound(tree[v].begin(), tree[v].end(), low);
auto it_high = std::upper_bound(tree[v].begin(), tree[v].end(), high);
returnstd::distance(it_low, it_high);
}
inttm = (tl + tr) >> 1;
returntree_query(v << 1, tl, tm, l, std::min(r, tm), low, high) +
tree_query((v << 1) | 1, tm + 1, tr, std::max(l,tm+1), r, low, high);
};
//tree_build(1, 0, n - 1);longlong sum = std::accumulate(a.begin(), a.end(), 0ll), ans = 0;
for (int i = 0; i < n - 1; i++)
{
//x <= sum - a[i] - a[j] <= y//x - sum + a[i] <= -a[j] <= y - sum + a[i]//sum - a[i] - y <= a[j] <= sum - a[i] - x
ans += tree_query(1, 0, n - 1, i + 1, n - 1, sum - a[i] - y, sum - a[i] - x);
}
std::cout << ans << '\n';
}
return0;
}
I compile it with g++ -O2 -std=c++23 main.cpp -o main, where main.cpp is a file with this code, and get the following message:
main.cpp: In lambda function:
main.cpp:31:17: internal compiler error: Segmentation fault
31 | tree[v] = { a[tl] };
| ^~~~
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://github.com/msys2/MINGW-packages/issues> for instructions.
Expected behavior
The code should be correctly compiled. It should behave something like the following code:
main.cpp -- std::function version
#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<functional>intmain()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
for (int tt = 0; tt < t; tt++)
{
int n;
longlong x, y;
std::cin >> n >> x >> y;
std::vector<longlong> a(n);
for (int i = 0; i < n; i++) std::cin >> a[i];
std::vector<longlong> tree[(n + 7) << 2];
std::function<void(int, int, int)> tree_build;
tree_build = [&](int v, int tl, int tr) -> void
{
if (tl == tr)
tree[v] = { a[tl] };
else
{
inttm = (tl + tr) >> 1;
tree_build(v << 1, tl, tm);
tree_build((v << 1) | 1, tm + 1, tr);
std::merge(tree[v << 1].begin(), tree[v << 1].end(),
tree[(v << 1) | 1].begin(), tree[(v << 1) | 1].end(),
std::back_inserter(tree[v]));
}
};
std::function<longlong(int, int, int, int, int, longlong, longlong)> tree_query;
tree_query = [&](int v, int tl, int tr, int l, int r, longlong low, longlong high) -> longlong
{
if (l > r)
return0;
if (l == tl && tr == r)
{
auto it_low = std::lower_bound(tree[v].begin(), tree[v].end(), low);
auto it_high = std::upper_bound(tree[v].begin(), tree[v].end(), high);
returnstd::distance(it_low, it_high);
}
inttm = (tl + tr) >> 1;
returntree_query(v << 1, tl, tm, l, std::min(r, tm), low, high) +
tree_query((v << 1) | 1, tm + 1, tr, std::max(l,tm+1), r, low, high);
};
tree_build(1, 0, n - 1);
longlong sum = std::accumulate(a.begin(), a.end(), 0ll), ans = 0;
for (int i = 0; i < n - 1; i++)
{
//x <= sum - a[i] - a[j] <= y//x - sum + a[i] <= -a[j] <= y - sum + a[i]//sum - a[i] - y <= a[j] <= sum - a[i] - x
ans += tree_query(1, 0, n - 1, i + 1, n - 1, sum - a[i] - y, sum - a[i] - x);
}
std::cout << ans << '\n';
}
return0;
}
std::function version successfully compiles.
Actual behavior
The code fails to compile.
The command g++ -std=c++23 -O2 -freport-bug main.cpp -o main gives:
main.cpp: In lambda function:
main.cpp:31:17: internal compiler error: Segmentation fault
31 | tree[v] = { a[tl] };
| ^~~~
Please submit a full bug report, with preprocessed source.
See <https://github.com/msys2/MINGW-packages/issues> for instructions.
g++: fatal error: cannot execute 'C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/cc1plus.exe': open temporary output file
compilation terminated.
But, I can manually execute C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/cc1plus.exe, so I submit report without -freport-bug output. It also asks for preprocessed source, so I attach it (zipped): main.zip
Description / Steps to reproduce the issue
Consider the following code:
main.cpp -- deducing this version
I compile it with
g++ -O2 -std=c++23 main.cpp -o main
, where main.cpp is a file with this code, and get the following message:Expected behavior
The code should be correctly compiled. It should behave something like the following code:
main.cpp -- std::function version
std::function version successfully compiles.
Actual behavior
The code fails to compile.
The command
g++ -std=c++23 -O2 -freport-bug main.cpp -o main
gives:But, I can manually execute
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/cc1plus.exe
, so I submit report without -freport-bug output. It also asks for preprocessed source, so I attach it (zipped):main.zip
Verification
Windows Version
MSYS_NT-10.0-22631
MINGW environments affected
Are you willing to submit a PR?
No response
The text was updated successfully, but these errors were encountered: