firegod_galactus's blog

By firegod_galactus, history, 3 years ago, In English

I am doing a task in which there are 300000(3e5) queries, after using assertion, I came to know only 5000 queries are left. I want to know if there are any other some c++ optimizations to squeeze my solution to AC.

I am currently using:
1. scanf
2. printf
3. #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops")
4. Fast I/O

  • Vote: I like it
  • -14
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

Edited: In some cases you should improve your algorithms better instead of depending on many optimization tricks to get accepted

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Some of the information you are saying is false. I once got around 50 points with unrolling loops optimization with an $$$O(N^2)$$$ solution and surprisingly, I got more points than a $$$O(Nlog_2(N)^2)$$$ segment tree solution. My constant factor was very low while a segment tree constant factor is considerably high. I was able to do $$$4*10^{10}$$$ operations in less than 5 seconds.

    • »
      »
      »
      3 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Ah yes, you are right and there are actually many algorithms with high complexity like flow algorithms actually runs very fast

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you show your code (preferably with the problem statement)?

In general there are very few "universal optimizations" that work for any kind of code. Even the pragmas that you wrote only work if the code does things that gcc "knows how to optimize" (AFAIK these pragmas mostly just turn on autovectorization). But it's more feasible to do constant optimization for some specific case.