QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471812#4563. Radio TowersA_programmer0 83ms50448kbC++173.5kb2024-07-11 09:08:342024-07-11 09:08:34

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 09:08:34]
  • 评测
  • 测评结果:0
  • 用时:83ms
  • 内存:50448kb
  • [2024-07-11 09:08:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e5 + 5;

int a[maxn], n, sz;
int stk[maxn], tp;
int L[maxn], R[maxn], d[maxn], b[maxn];
int nxt[18][maxn], pre[18][maxn];

struct ST
{
    int mi[18], lg[maxn];
    int f[18][maxn];

    void build()
    {
        for (int i = 0; i <= 17; i++) mi[i] = 1 << i;
        for (int i = 1, k = 0; i <= n; i++)
        {
            lg[i] = k; if (i == (1 << (k + 1))) lg[i] = ++k;
            f[0][i] = a[i];
        }
        for (int j = 1; j <= 17; j++)
            for (int i = 1; i + mi[j] - 1 <= n; i++)
                f[j][i] = max(f[j - 1][i], f[j - 1][i + mi[j - 1]]);
    }

    int query(int l, int r)
    {
        int k = lg[r - l + 1];
        return max(f[k][l], f[k][r - mi[k] + 1]);
    }
}st;

int rt[maxn], sum[maxn * 20], ls[maxn * 20], rs[maxn * 20], cnt;
void build(int &k, int l, int r)
{
    k = ++cnt;
    if (l == r) return;
    int mid = (l + r) >> 1; build(ls[k], l, mid); build(rs[k], mid + 1, r);
}
void update(int &k, int p, int l, int r, int x)
{
    k = ++cnt;
    sum[k] = sum[p] + 1, ls[k] = ls[p], rs[k] = rs[p];
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (x <= mid) update(ls[k], ls[p], l, mid, x);
    else update(rs[k], rs[p], mid + 1, r, x);
    sum[k] = sum[ls[k]] + sum[rs[k]];
}
int find(int a, int b, int l, int r, int x)
{
    if (l == r) return sum[b] - sum[a];
    int mid = (l + r) >> 1;
    if (x > mid) return find(rs[a], rs[b], mid + 1, r, x);
    else return find(ls[a], ls[b], l, mid, x) + sum[rs[b]] - sum[rs[a]];
}

void init(int N, vector<int> H)
{
    n = N;
    for (int i = 1; i <= N; i++) a[i] = H[i - 1]; st.build();

    tp = 0;
    for (int i = 1; i <= N; i++)
    {
        while (tp && a[stk[tp]] > a[i]) tp--;
        L[i] = tp ? stk[tp] + 1 : 1;
        stk[++tp] = i;
    }

    tp = 0;
    for (int i = N; i; i--)
    {
        while (tp && a[stk[tp]] > a[i]) tp--;
        R[i] = tp ? stk[tp] - 1 : n;
        d[i] = min(st.query(L[i], i), st.query(i, R[i])) - a[i], b[i] = d[i];
        stk[++tp] = i;
    }
    sort(b + 1, b + N + 1); sz = unique(b + 1, b + N + 1) - b - 1;
    for (int i = 1; i <= N; i++) d[i] = lower_bound(b + 1, b + sz + 1, d[i]) - b;

    build(rt[0], 1, sz);
    for (int i = 1; i <= N; i++) update(rt[i], rt[i - 1], 1, sz, d[i]);

    for (int i = 1; i <= N; i++) nxt[0][i] = R[i] + 1; nxt[0][N + 1] = N + 1;
    for (int j = 1; j <= 17; j++)
        for (int i = 1; i <= N + 1; i++) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
    for (int i = 1; i <= N; i++) pre[0][i] = L[i] - 1;
    for (int j = 1; j <= 17; j++)
        for (int i = 1; i <= N; i++) pre[j][i] = pre[j - 1][pre[j - 1][i]];
}

int max_towers(int l, int r, int D)
{
    l++, r++;
    int ans = find(rt[l - 1], rt[r], 1, n, lower_bound(b + 1, b + sz + 1, D) - b);
    int x = l;
    for (int i = 17; ~i; i--)
        if (nxt[i][x] <= n && L[nxt[i][x]] < l) x = nxt[i][x];
    if (st.query(x, R[x]) - a[x] >= D) ans++;
    x = r;
    for (int i = 17; ~i; i--)
        if (pre[i][x] && R[pre[i][x]] > r) x = pre[i][x];
    if (st.query(L[x], x) - a[x] >= D) ans++;
    return max(1, ans);
}

// vector<int> p;

// int main()
// {
//     int nn, q;
//     cin >> nn >> q; p.resize(nn);
//     for (int i = 0; i < nn; i++) cin >> p[i];
//     init(nn, p);
//     while (q--)
//     {
//         int l, r, d;
//         cin >> l >> r >> d;
//         cout << max_towers(l, r, d) << "\n";
//     }
//     return 0;
// }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 41ms
memory: 29028kb

input:

59640
49885 57346 58504 87383 113182 129676 204090 205404 259925 276583 300332 324014 333675 359377 364049 408489 414852 428310 438038 440113 458193 554789 643468 666525 683112 690791 707313 720088 741028 748785 789826 796576 800966 832867 851750 861044 862283 900756 926925 939560 955678 965636 9740...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 14th lines differ - expected: '2', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 28456kb

input:

425
753881706 405729786 890889563 29736246 598281970 208352067 357783003 663497023 178397034 4832890 562140755 510307001 354540290 538848551 436879256 86659033 42928516 24145404 749159097 118423198 506851985 204895765 719719998 726244368 991372008 681703480 799303017 657138050 88278945 417801236 260...

output:

16

result:

wrong answer 3rd lines differ - expected: '13', found: '16'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #65:

score: 0
Wrong Answer
time: 83ms
memory: 50220kb

input:

99308
491693640 24020487 317364185 726230755 737284540 951143270 709116045 641023337 360629062 964879440 47884022 532494780 803629825 635450854 688041998 573937055 113198481 191311841 929603572 636688 598629732 895342035 396521271 619919754 716589045 657789547 373121546 866402108 609316614 60046511 ...

output:

11904
4772
14280
13958
572
9310
4391
11
22099
16786
26039
2815
8489
16603
2031
6160
17238
29709
19865
12085
20817
18092
4197
11614
4625
6659
7662
625
9839
13014
14476
11801
14797
6366
7310
5983
13615
14210
15924
17327
6021
10293
1821
29078
3118
6640
5812
28747
14946
9542
5500
1016
5003
20940
306
199...

result:

wrong answer 3rd lines differ - expected: '11903', found: '11904'

Subtask #5:

score: 0
Wrong Answer

Test #86:

score: 0
Wrong Answer
time: 21ms
memory: 35392kb

input:

23881
605288257 422163932 155875880 339929874 76049859 196344969 958160745 767945284 469191956 997116006 387749577 15911341 920437918 367576975 800789357 351557615 283723284 369507452 841548133 643412903 309731505 256549694 370065644 699518122 559017597 347646657 469353381 575240521 501893001 454519...

output:

7733
7688
5370
7006
7072
7778
5917
7558
5996
7305
6955
7826
6862
6249
7118
7487
7888
7745
7933
6246
7439
7685
7768
6912
5475
6001
7214
5982
7408
6963
6985
6994
6374
5582
7271
6328
7903
7656
5971
7291
7734
6913
5748
7517
6310
5619
7533
7673
7746
7357
7058
7526
6106
6015
6775
7246
6808
6079
7561
5903
...

result:

wrong answer 3rd lines differ - expected: '7197', found: '7733'

Subtask #6:

score: 0
Wrong Answer

Test #97:

score: 0
Wrong Answer
time: 74ms
memory: 50448kb

input:

88768
238644804 620122421 789364401 899010695 885388612 437964772 845379533 657562749 773925456 625793781 916240972 291506550 379611161 905077982 629848170 530056471 520438258 806293637 326792996 785404568 74285074 565304193 846963319 63529729 804909008 212070492 69936548 656129389 408708069 3070450...

output:

7994
20515
5437
20897
25766
2197
22903
10073
23303
17237
124
12894
9386
21038
10317
10041
5944
22066
1847
4380
24831
6495
19632
14168
6281
13593
23723
17314
708
5937
18649
8367
6723
1952
6921
688
845
3375
9688
12671
7892
2904
17388
2483
2206
10663
26313
5101
9734
5518
2633
22151
9127
15960
18066
725...

result:

wrong answer 3rd lines differ - expected: '7293', found: '7994'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%