답안 #1007406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007406 2024-06-24T19:20:47 Z c2zi6 코끼리 (Dancing Elephants) (IOI11_elephants) C++14
50 / 100
1497 ms 27472 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "elephants.h"

const int BUCKETSIZE = 400;

int l;
int m = 0;
int st[2*BUCKETSIZE + 20];
struct BUCKET {
    int n = 0;
    int b[2*BUCKETSIZE + 20];
    int cnt[2*BUCKETSIZE + 20];
    int mx[2*BUCKETSIZE + 20];
    void rem(int x) {
        while (b[n-1] > x) {
            st[m++] = b[--n];
        }
        --n;
        while (m) {
            b[n++] = st[--m];
        }
    }
    void add(int x) {
        while (n && b[n-1] > x) {
            st[m++] = b[--n];
        }
        b[n++] = x;
        while (m) {
            b[n++] = st[--m];
        }
    }
    void recalc() {
        reprl(i, n-1, 0) {
            int j = upper_bound(b, b+n, b[i] + l) - b;
            if (j == n) {
                cnt[i] = 1;
                mx[i] = b[i]+l;
            } else {
                cnt[i] = cnt[j]+1;
                mx[i] = mx[j];
            }
        }
    }
    void print() {
        rep(i, n) cout << b[i] << " "; cout << endl;
        /*rep(i, n) cout << cnt[i] << " "; cout << endl;*/
        /*rep(i, n) cout << mx[i] << " "; cout << endl;*/
    }
};

int n;
int a[60000];
int b[60000];
vector<BUCKET> buk;
void recalc() {
    rep(i, n) b[i] = a[i];
    sort(b, b+n);
    buk.clear();
    buk.pb(BUCKET());
    rep(i, n) {
        if (buk.back().n >= BUCKETSIZE) {
            buk.pb(BUCKET());
        }
        buk.back().add(b[i]);
    }
    for (BUCKET& p : buk) p.recalc();
}
void add(int x) {
    for (BUCKET& p : buk) if (p.n) {
        if (x <= p.b[p.n-1]) {
            p.add(x);
            p.recalc();
            return;
        }
    }
    buk.back().add(x);
    buk.back().recalc();
}
void rem(int x) {
    for (BUCKET& p : buk) if (p.n) {
        if (x <= p.b[p.n-1]) {
            p.rem(x);
            p.recalc();
            return;
        }
    }
}

int answer() {
    int ans = 0;
    int R = -2e9;
    for (BUCKET& p : buk) if (p.n) {
        int i = upper_bound(p.b, p.b + p.n, R) - p.b;
        if (i == p.n) continue;
        ans += p.cnt[i];
        R = p.mx[i];
    }
    return ans;
}

void print() {
    for (BUCKET& p : buk) {
        cout << "BUCKET: " << endl;
        p.print();
    }
    cout << "END OF PHASE ----------------------------------------------" << endl;
}

void init(int N, int L, int X[]) {
    n = N;
    l = L;
    rep(i, n) a[i] = X[i];
    /*cout << "START OF THE PROGRAM --------------------------------------" << endl;*/
    recalc();
    /*print();*/
}

int qr = 0;
int update(int i, int y) {
    if (qr++ % BUCKETSIZE == 0) {
        recalc();
        /*cout << "RECALCULATED" << endl;*/
    }
    /*print();*/
    rem(a[i]);
    a[i] = y;
    /*print();*/
    add(a[i]);
    /*print();*/
    return answer();
}






Compilation message

elephants.cpp: In member function 'void BUCKET::print()':
elephants.cpp:9:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    9 | #define rep(i, n) for (int i = 0; i < int(n); ++i)
      |                   ^~~
elephants.cpp:75:9: note: in expansion of macro 'rep'
   75 |         rep(i, n) cout << b[i] << " "; cout << endl;
      |         ^~~
elephants.cpp:75:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   75 |         rep(i, n) cout << b[i] << " "; cout << endl;
      |                                        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 637 ms 11184 KB Output is correct
8 Correct 618 ms 11436 KB Output is correct
9 Correct 644 ms 12156 KB Output is correct
10 Correct 723 ms 12164 KB Output is correct
11 Correct 654 ms 12152 KB Output is correct
12 Correct 1048 ms 12152 KB Output is correct
13 Correct 710 ms 12156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 637 ms 11184 KB Output is correct
8 Correct 618 ms 11436 KB Output is correct
9 Correct 644 ms 12156 KB Output is correct
10 Correct 723 ms 12164 KB Output is correct
11 Correct 654 ms 12152 KB Output is correct
12 Correct 1048 ms 12152 KB Output is correct
13 Correct 710 ms 12156 KB Output is correct
14 Correct 675 ms 11440 KB Output is correct
15 Correct 755 ms 11692 KB Output is correct
16 Correct 1497 ms 12256 KB Output is correct
17 Runtime error 28 ms 27472 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 637 ms 11184 KB Output is correct
8 Correct 618 ms 11436 KB Output is correct
9 Correct 644 ms 12156 KB Output is correct
10 Correct 723 ms 12164 KB Output is correct
11 Correct 654 ms 12152 KB Output is correct
12 Correct 1048 ms 12152 KB Output is correct
13 Correct 710 ms 12156 KB Output is correct
14 Correct 675 ms 11440 KB Output is correct
15 Correct 755 ms 11692 KB Output is correct
16 Correct 1497 ms 12256 KB Output is correct
17 Runtime error 28 ms 27472 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -