답안 #1070268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070268 2024-08-22T12:39:23 Z jerzyk 송신탑 (IOI22_towers) C++17
17 / 100
1078 ms 28108 KB
#include <bits/stdc++.h>
#include "towers.h"

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<17;
int drz[2 * N], drz2[2 * N], drz3[2 * N], drz4[2 * N];
int drzmi[2 * N], drzma[2 * N];
vector<int> mrg[2 * N];

int tab[N], ml[N], mr[N], cdi[N], tim[N];
set<int> cur;
set<int>::iterator it;
set<pair<int, int>> dif;

int FindL(int v, int a, int b, int pz, int kz, int x)
{
    if(a > kz || b < pz || drzma[v] < x) return N;
    if(v >= N) return v - N;
    int ans = FindL(v * 2, a, (a + b) / 2, pz, kz, x);
    if(ans < N) return ans;
    ans = FindL(v * 2 + 1, (a + b) / 2 + 1, b, pz, kz, x);
    return ans;
}

int FindR(int v, int a, int b, int pz, int kz, int x)
{
    if(a > kz || b < pz || drzma[v] < x) return 0;
    if(v >= N) return v - N;
    int ans = FindR(v * 2 + 1, (a + b) / 2 + 1, b, pz, kz, x);
    if(ans != 0) return ans;
    ans = FindR(v * 2, a, (a + b) / 2, pz, kz, x);
    return ans;
}

bool ChkL(int a, int b, int k)
{
    //cerr << "Chkl: " << a << " " << b << "\n";
    vector<int> x, y;
    a += N - 1; b += N + 1;
    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) x.pb(a + 1);
        if(b % 2 == 1) y.pb(b - 1);
        a /= 2; b /= 2;
    }
    reverse(y.begin(), y.end());
    for(int j = 0; j < (int)y.size(); ++j) x.pb(y[j]);
    int curmi = II;
    for(int i = 0; i < (int)x.size(); ++i)
    {
        if(drz3[x[i]] >= k) return true;
        if(drz[x[i]] - curmi >= k) return true;
        curmi = min(curmi, drz2[x[i]]);
    }
    return false;
}

bool ChkR(int a, int b, int k)
{
    vector<int> x, y;
    a += N - 1; b += N + 1;
    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) x.pb(a + 1);
        if(b % 2 == 1) y.pb(b - 1);
        a /= 2; b /= 2;
    }
    reverse(y.begin(), y.end());
    for(int j = 0; j < (int)y.size(); ++j) x.pb(y[j]);
    int curma = 0;
    for(int i = 0; i < (int)x.size(); ++i)
    {
        if(drz4[x[i]] >= k) return true;
        if(curma - drz2[x[i]] >= k) return true;
        curma = max(curma, drz[x[i]]);
    }
    return false;
}

void DoT(int n)
{
    drz2[N] = II; drzmi[N] = II;
    for(int i = N; i < 2 * N; ++i)
    {
        drz3[i] = -II / 2;
        drz4[i] = -II / 2;
    }
    for(int i = 1; i <= n; ++i)
    {
        drzmi[i + N] = tim[i]; drzma[i + N] = tim[i];
        drz[i + N] = tab[i]; drz2[i + N] = tab[i];
        mrg[i + N] = {tim[i]};
    }
    for(int i = n + 1; i < N; ++i)
    {drzmi[i + N] = II; drz2[i + N] = II;}

    for(int i = N - 1; i >= 1; --i)
    {
        drzma[i] = max(drzma[2 * i], drzma[2 * i + 1]);
        drzmi[i] = min(drzmi[2 * i], drzmi[2 * i + 1]);

        drz[i] = max(drz[2 * i], drz[2 * i + 1]);
        drz2[i] = min(drz2[2 * i], drz2[2 * i + 1]);

        drz3[i] = max(drz3[i * 2], drz3[i * 2 + 1]);
        drz3[i] = max(drz3[i], drz[i * 2 + 1] - drz2[i * 2]);

        drz4[i] = max(drz4[i * 2], drz4[i * 2 + 1]);
        drz4[i] = max(drz4[i], drz[i * 2] - drz2[i * 2 + 1]);

        mrg[i] = mrg[i * 2];
        for(int j = 0; j < (int)mrg[i * 2 + 1].size(); ++j)
            mrg[i].pb(mrg[i * 2 + 1][j]);
        sort(mrg[i].begin(), mrg[i].end());
    }
}

inline int Il(int v, int x)
{
    return (mrg[v].end() - lower_bound(mrg[v].begin(), mrg[v].end(), x));
}

int Query(int a, int b, int x)
{
    a += N - 1; b += N + 1;
    int ans = 0;
    while(a / 2 != b / 2)
    {
        if(a % 2 == 0) ans += Il(a + 1, x);
        if(b % 2 == 1) ans += Il(b - 1, x);
        a /= 2; b /= 2;
    }

    return ans;
}

int GetL(int v)
{
    it = cur.lower_bound(v);
    if(it == cur.begin()) return 0;
    --it; return *it;
}

int GetR(int v)
{
    it = cur.upper_bound(v);
    if(it == cur.end()) return 0;
    return *it;
}

void init(int _N, vector<int> _H)
{
    int n = _N;
    for(int i = 1; i <= n; ++i) tab[i] = _H[i - 1];
    for(int i = 1; i <= n; ++i)
    {
        ml[i] = 0LL; mr[i] = 0LL;
        cur.insert(i);
    }
    ml[1] = II; mr[n] = II;
    for(int i = 1; i <= n; ++i)
    {
        cdi[i] = min(ml[i], mr[i]) - tab[i];
        dif.insert(make_pair(cdi[i], i));
    }
    while((int)cur.size() > 1)
    {
        int v = (*dif.begin()).nd;
        dif.erase(dif.begin());
        cur.erase(v);
        tim[v] = cdi[v];
        int l = GetL(v), r = GetR(v);
        int xd = max(tab[v], max(mr[v], ml[v]));
        if(l != 0)
        {
            dif.erase(make_pair(cdi[l], l));
            mr[l] = max(mr[l], xd);
            cdi[l] = min(ml[l], mr[l]) - tab[l];
            dif.insert(make_pair(cdi[l], l));
        }
        if(r != 0)
        {
            dif.erase(make_pair(cdi[r], r));
            ml[r] = max(ml[r], xd);
            cdi[r] = min(ml[r], mr[r]) - tab[r];
            dif.insert(make_pair(cdi[r], r));
        }
    }
    for(int i = 1; i <= n; ++i)
        tim[i] = max(tim[i], 0);
    tim[*cur.begin()] = II;
    DoT(n);
    //for(int i = 1; i <= n; ++i)
        //cerr << tim[i] << " ";
    //cerr << "\n";
}

int max_towers(int L, int R, int D)
{
    ++L; ++R;
    int ans = Query(L, R, D);
    if(ans == 0) return 1;
    int l = FindL(1, 0, N - 1, L, R, D);
    int r = FindR(1, 0, N - 1, L, R, D);
    //cerr << "Que: " << l << " " << r << "\n";
    if(l != L && ChkL(L, l - 1, D)) ++ans;
    if(r != R && ChkR(r + 1, R, D)) ++ans;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 435 ms 22476 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 5 ms 15108 KB Output is correct
3 Correct 5 ms 15192 KB Output is correct
4 Correct 5 ms 15192 KB Output is correct
5 Correct 5 ms 15192 KB Output is correct
6 Correct 9 ms 15060 KB Output is correct
7 Correct 9 ms 15192 KB Output is correct
8 Correct 6 ms 15072 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 4 ms 14920 KB Output is correct
12 Incorrect 3 ms 14680 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 5 ms 15108 KB Output is correct
3 Correct 5 ms 15192 KB Output is correct
4 Correct 5 ms 15192 KB Output is correct
5 Correct 5 ms 15192 KB Output is correct
6 Correct 9 ms 15060 KB Output is correct
7 Correct 9 ms 15192 KB Output is correct
8 Correct 6 ms 15072 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 4 ms 14920 KB Output is correct
12 Incorrect 3 ms 14680 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 825 ms 27992 KB Output is correct
2 Correct 1077 ms 28104 KB Output is correct
3 Correct 1050 ms 28104 KB Output is correct
4 Correct 1078 ms 28064 KB Output is correct
5 Correct 1066 ms 28104 KB Output is correct
6 Correct 1057 ms 28104 KB Output is correct
7 Correct 1045 ms 28104 KB Output is correct
8 Correct 781 ms 27944 KB Output is correct
9 Correct 840 ms 28104 KB Output is correct
10 Correct 825 ms 28100 KB Output is correct
11 Correct 878 ms 28108 KB Output is correct
12 Incorrect 707 ms 28092 KB 170th lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 17964 KB Output is correct
2 Correct 1014 ms 28104 KB Output is correct
3 Correct 963 ms 28104 KB Output is correct
4 Correct 1054 ms 28104 KB Output is correct
5 Correct 1037 ms 28104 KB Output is correct
6 Correct 901 ms 28008 KB Output is correct
7 Correct 1034 ms 27920 KB Output is correct
8 Correct 880 ms 28104 KB Output is correct
9 Correct 817 ms 28036 KB Output is correct
10 Correct 883 ms 28104 KB Output is correct
11 Correct 859 ms 28104 KB Output is correct
12 Correct 247 ms 28056 KB Output is correct
13 Correct 243 ms 27952 KB Output is correct
14 Correct 251 ms 27940 KB Output is correct
15 Correct 84 ms 28104 KB Output is correct
16 Correct 90 ms 28104 KB Output is correct
17 Correct 216 ms 27592 KB Output is correct
18 Correct 224 ms 28104 KB Output is correct
19 Correct 225 ms 27920 KB Output is correct
20 Correct 237 ms 28060 KB Output is correct
21 Correct 233 ms 27964 KB Output is correct
22 Correct 235 ms 28104 KB Output is correct
23 Correct 233 ms 28100 KB Output is correct
24 Correct 79 ms 28104 KB Output is correct
25 Correct 72 ms 28104 KB Output is correct
26 Correct 89 ms 28100 KB Output is correct
27 Correct 102 ms 27968 KB Output is correct
28 Correct 6 ms 15192 KB Output is correct
29 Correct 6 ms 15192 KB Output is correct
30 Correct 6 ms 15192 KB Output is correct
31 Correct 5 ms 14936 KB Output is correct
32 Correct 4 ms 15068 KB Output is correct
33 Correct 4 ms 14936 KB Output is correct
34 Correct 6 ms 15192 KB Output is correct
35 Correct 6 ms 15192 KB Output is correct
36 Correct 5 ms 15192 KB Output is correct
37 Correct 5 ms 15192 KB Output is correct
38 Correct 6 ms 15196 KB Output is correct
39 Correct 6 ms 15192 KB Output is correct
40 Correct 5 ms 15068 KB Output is correct
41 Correct 4 ms 15036 KB Output is correct
42 Correct 5 ms 14936 KB Output is correct
43 Correct 5 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 5 ms 15108 KB Output is correct
3 Correct 5 ms 15192 KB Output is correct
4 Correct 5 ms 15192 KB Output is correct
5 Correct 5 ms 15192 KB Output is correct
6 Correct 9 ms 15060 KB Output is correct
7 Correct 9 ms 15192 KB Output is correct
8 Correct 6 ms 15072 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 4 ms 14920 KB Output is correct
12 Incorrect 3 ms 14680 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 435 ms 22476 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -