답안 #1095502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095502 2024-10-02T12:40:18 Z thangdz2k7 Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
17 ms 3144 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 4e6 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int mx, lz[N], Max[N];
const int inf = 4e6;

void update(int u, int v, int val, int s = 1, int l = 0, int r = mx - 1){
    if (u <= l && r <= v){
        Max[s] += val, lz[s] += val;
        return;
    }

    int mid = l + r >> 1;
    if (mid >= u) update(u, v, val, s << 1, l, mid);
    if (mid < v) update(u, v, val, s << 1 | 1, mid + 1, r);
    Max[s] = max(Max[s << 1], Max[s << 1 | 1]) + lz[s];
}

vi countScans(vi a, vi x, vi y){
    int n = a.size(), q = x.size();
    vector <ii> sr;

    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin())
    #define uq(sr) (sr).erase(unique(all((sr))), (sr).end())
    #define szv(v) (int((v).size()))

    for (int i = 0; i < n; ++ i) sr.pb({a[i], i});
    for (int i = 0; i < q; ++ i) sr.pb({y[i], x[i]});
    sort(all(sr)); uq(sr); mx = szv(sr);
    for (int i = 1; i <= 4 * mx; ++ i) Max[i] = -inf, lz[i] = 0;

    auto fix = [&](int i, int f) -> void {
        ii x = {a[i], i};
        int T = fd(sr, x);
        update(T, T, f * (inf + i));
        update(T, mx - 1, -f);
    };

    for (int i = 0; i < n; ++ i) fix(i, 1);
    for (int i = 0; i < q; ++ i){
        fix(x[i], -1);
        a[x[i]] = y[i];
        fix(x[i], 1);
        cout << Max[1] << endl;
    }
}

//void solve(){
//
//}
//
//int main(){
//    if (fopen("pqh.inp", "r")){
//        freopen("pqh.inp", "r", stdin);
//        freopen("pqh.out", "w", stdout);
//    }
//    ios_base::sync_with_stdio(0);
//    cin.tie(0); cout.tie(0);
//
//    int t = 1; // cin >> t;
//    while (t --) solve();
//    return 0;
//}

Compilation message

bubblesort2.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
bubblesort2.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
bubblesort2.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
bubblesort2.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
bubblesort2.cpp: In function 'void update(int, int, int, int, int, int)':
bubblesort2.cpp:30:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |     int mid = l + r >> 1;
      |               ~~^~~
bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:65:1: warning: no return statement in function returning non-void [-Wreturn-type]
   65 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 3144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -