Unexpected TLE in O(NlogN) Algorithm with N = 2e5

Правка en1, от Riyad_Hossain, 2024-06-28 12:57:35

Hello coders,

I've recently encountered a perplexing issue while working on a problem where the input size (N) is up to 200,000. Despite my algorithm's O( n log n ) complexity, it consistently hits a Time Limit Exceeded (TLE) error on the 8th test case. I've optimized my code to the best of my ability and ensured it's running in O(NlogN) time complexity, but the problem persists.

Problem: 1955D - Inaccurate Subsequence Search Submission: 267829049

Main Code: Iterate over n and log n for

    int cnt = 0;
    map<int, int> mpp;
    for (int i = 0; i < m; i++)
    {
        mpp[a[i]]++;
        if (ms.count(a[i]) >= mpp[a[i]])
            cnt++;
    }
 
    int ans = cnt >= k;
    for (int i = 0; i < n - m; i++)
    {
        mpp[a[i]]--;
        if (ms.count(a[i]) > mpp[a[i]])
            cnt--;
 
        mpp[a[i + m]]++;
        if (ms.count(a[i + m]) >= mpp[a[i + m]])
            cnt++;
        ans += cnt >= k;
    }
 
    print(ans);
Теги tle, help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Riyad_Hossain 2024-06-29 06:17:00 1 Tiny change: 'lo coders,\n\nI've r' -> 'lo coders, \n\nI've r'
en2 Английский Riyad_Hossain 2024-06-28 13:05:06 368
en1 Английский Riyad_Hossain 2024-06-28 12:57:35 1051 Initial revision (published)