[Solved] Add 1 day to todays date whenever value gets repeated

Use Application.Countifs: Sub Add_date2() Dim ws As Worksheet Set ws = ActiveSheet ‘better to set the actual sheet WorkSheets(“Sheet1”) With ws Dim lastRow As Long lastRow = .Cells(Rows.Count, 1).End(xlUp).Row Dim iCntr As Long For iCntr = 2 To lastRow If .Cells(iCntr, 1) <> “” Then .Cells(iCntr, 2) = Date + Application.CountIfs(.Range(.Cells(2, 1), .Cells(iCntr, 1)), .Cells(iCntr, … Read more

[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] Comparing 2 different scenarios on 2 different architectures when finding the max element of an array

I think you’re really trying to ask about branchless vs. branching ways to do m = max(m, array[i]). C compilers will already compile the if() version to branchless code (using cmov) depending on optimization settings. It can even auto-vectorize to a packed compare or packed-max function. Your 0.5 * abs() version is obviously terrible (a … Read more

[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] How can I still optimize the code?

You can slightly improve your code by removing queue, you don’t need this. The rest of the code looks algorithmically optimal. #include <map> #include <iostream> using namespace std; int main() { int a,b; map<int, int> AB; map<int, int>::iterator it; std::ios::sync_with_stdio(false); while (1) { cin >> a; if (a == -1)break; cin >> b; AB.insert(pair<int, int>(a, … Read more