Submission #1276077

#TimeUsernameProblemLanguageResultExecution timeMemory
1276077sakkaBubble Sort Machine (JOI25_bubble)C++20
5 / 100
2095 ms15936 KiB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pll pair<long long, long long>
using namespace std;
void freop(){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}
const ll MOD = 1e9+7, INF = 1e18;
ll n , Q;
vector<ll> vec(5e5 + 2);
vector<ll> pref(5e5 + 2,0);

void solve(){
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> vec[i];
        pref[i] = pref[i-1] + vec[i];
    }
    
    cin >> Q;
    while(Q--){
        int op; cin >> op;
        if(op == 1){
            for(int i=1; i<=n-1; i++){
                if(vec[i] > vec[i+1]) swap(vec[i], vec[i+1]);
                pref[i] = pref[i-1] + vec[i];
            }
        }
        else{
            ll l, r; cin >> l >> r;
            cout << pref[r] - pref[l-1] << endl;
        }
    }
}

int main(){
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freop();
    solve();
}

Compilation message (stderr)

bubble.cpp: In function 'void freop()':
bubble.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bubble.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...