Submission #1276048

#TimeUsernameProblemLanguageResultExecution timeMemory
1276048retr0foxxBubble Sort Machine (JOI25_bubble)C++20
5 / 100
2095 ms15856 KiB
#include <iostream>

#define MAXN 500005
#define int long long

int a[MAXN];
int pref[MAXN];

signed main()
{
    int n;
    std::cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        std::cin >> a[i];
        pref[i] = pref[i-1] + a[i];
    }
    int q;
    std::cin >> q;
    while (q--)
    {
        int t;
        std::cin >> t;

        if (t == 1)
        {
            for (int j = 1; j <= n-1; ++j)
            {
                if (a[j] > a[j+1]) std::swap(a[j], a[j+1]);
                pref[j] = pref[j-1] + a[j];
            }
        }
        else
        {
            int l, r;
            std::cin >> l >> r;

            std::cout << pref[r] - pref[l-1] << "\n";
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...