답안 #773297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773297 2023-07-04T20:04:14 Z rominanafu Sails (IOI07_sails) C++11
45 / 100
227 ms 2448 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct ura {
    int h, k;
};

int n, tam;
ura masts[100005];
int ST[400005];
int diferencias[100005];

bool cmp(const ura &a, const ura &b) {
    return a.h < b.h;
}

void actualizar(int pos, int val, int nodo=1, int ini=1, int fin=100000) {
    if (pos < ini || pos > fin)
        return;
    if (ini == fin) {
        ST[nodo] += val;
        diferencias[ini] += val;
        return;
    }
    int mid = (ini+fin) / 2;
    actualizar(pos, val, nodo*2, ini, mid);
    actualizar(pos, val, nodo*2+1, mid+1, fin);
    ST[nodo] = ST[nodo*2] + ST[nodo*2+1];
}

ll suma(int pos, int nodo=1, int ini=1, int fin=100000) {
    if (pos < ini)
        return 0;
    if (pos >= fin)
        return ST[nodo];
    ll s=0;
    int mid = (ini + fin) / 2;
    s += suma(pos, nodo*2, ini, mid);
    s += suma(pos, nodo*2+1, mid+1, fin);
    return s;
}

int pos_primer_num_menor(ll &num) {
    int izq=1, der=100000, mid, r=0;
    while (izq <= der) {
        mid = (izq+der) / 2;
        if (suma(mid) < num) {
            r = mid;
            der = mid-1;
        } else {
            izq = mid+1;
        }
    }
    return r;
}

int pos_primer_num_igual(ll &num) {
    int izq=1, der=100000;
    int mid, r=0;
    while (izq <= der) {
        mid = (izq+der) / 2;
        if (suma(mid) > num) {
            izq = mid+1;
        } else {
            der = mid-1;
            r = mid;
        }
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> masts[i].h >> masts[i].k;
        tam = max(tam, masts[i].h);
    }
    sort(masts, masts+n, cmp);
    actualizar(1, 1);
    actualizar(masts[0].k+1, -1);
    ll s;
    int pos1, pos2;
    for(int i=1; i<n; i++) {
        if (diferencias[masts[i].h - masts[i].k + 1] < 0) {
            actualizar(masts[i].h - masts[i].k + 1, 1);
            actualizar(masts[i].h + 1, -1);
        } else {
            s = suma(masts[i].h - masts[i].k + 1);
            pos1 = pos_primer_num_igual(s);
            pos2 = pos_primer_num_menor(s);
            masts[i].k -= masts[i].h - pos2;
            actualizar(pos1, 1);
            actualizar(pos1 + masts[i].k - 1, -1);
            //---------
            actualizar(pos2, 1);
            actualizar(masts[i].h + 1, -1);
        }
    }
    ll resp=0;
    for(int i=1; i<=masts[n-1].h; i++) {
        s = suma(i);
        resp += (s * (s - 1)) / 2;
    }
    cout << resp;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Incorrect 10 ms 1760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 724 KB Output is correct
2 Correct 61 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 1440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 196 ms 2292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 2384 KB Output is correct
2 Incorrect 168 ms 2296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 227 ms 2448 KB Output isn't correct
2 Halted 0 ms 0 KB -