[Solved] Competitive programming: “Time exceeded error”

Calculate the cumulative sum of the array and store it in another one, that is to say, accumulated[i] = sum of numbers of the array up to ith index. This can be computed in O(n). Then for a query, the answer will be accumulated[r] – accumulated[l]. This is O(1) solved Competitive programming: “Time exceeded error”

[Solved] gcc 4.7 Give me error message

The error says it all. Trying adding -std=c++11 or -std=gnu++11 to the compiler options in your NetBeans IDE. I’ve not used Netbeans but see this link where a snapshot of build variables is shown and that is where you need to add the compiler options. 1 solved gcc 4.7 Give me error message

[Solved] wildly different behaviour between O2 and O3 optimized FP code [closed]

From GCC manual: -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options. No of these optimizations are particularly unsafe. The only optimization that I see can change the result is -ftree-vectorize. In some cases, using vector instructions … Read more

[Solved] Changing gcc/g++ version causes segfault [closed]

You should try to use valgrind. Valgrind is a debugging tool only requiring for your code to be compiled with the -g flag. It’s the best way to spot segmentation fault over a program, or any memory leak. Think about using valgrind options while debugging (it’s at the bottom of the valgrind report) something like … Read more

[Solved] Can’t use global variables with gcc

You can declare global variables but you have to initialize inside main like this: char* vidmem; char* vidmem; int main() { vidmem = (char*)0xb8000; vidmem[0] = ‘x’; vidmem[1] = 0x0f; } 1 solved Can’t use global variables with gcc

[Solved] Does (p+x)-x always result in p for pointer p and integer x in gcc linux x86-64 C++

Yes, for gcc5.x and later specifically, that specific expression is optimized very early to just p, even with optimization disabled, regardless of any possible runtime UB. This happens even with a static array and compile-time constant size. gcc -fsanitize=undefined doesn’t insert any instrumentation to look for it either. Also no warnings at -Wall -Wextra -Wpedantic … Read more

[Solved] std::remove_if GCC implementation isn’t efficient?

Looks to me as though you’re running remove_if on a range of 100 characters since size is 100, but the “homebrew” runs until you find the nul terminator (which is only 10 characters in). Dealing with that using the change in your comment below, on GCC with -O2 I still see a difference of about … Read more