QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#286515#7969. 套娃ucup-team022AC ✓108ms23288kbC++173.5kb2023-12-17 23:02:472023-12-17 23:02:48

Judging History

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

  • [2023-12-17 23:02:48]
  • 评测
  • 测评结果:AC
  • 用时:108ms
  • 内存:23288kb
  • [2023-12-17 23:02:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, a[100005], L[100005], c[100005], is[100005];
int mnv[400005], tag[400005], vl[400005], vr[400005], posl[400005];
vector<int> pos[100005], add[100005];
void U(int x, int y) {
    is[x] += y;
    if (y == 1 && is[x] != 1) return;
    if (y == -1 && is[x] != 0) return;
    // cout << "Uing:" << x << ' ' << y << '\n';
    while (x <= N) c[x] += y, x += x & -x;
}
int Q() {
    int r = 0;
    for (int i = 16; i >= 0; i--) {
        if (r + (1 << i) <= N && c[r + (1 << i)] == (1 << i)) {
            r += (1 << i);
        }
    }
    // cout << "R:" << r << '\n';
    return r;
}
void Build(int p, int l, int r) {
    mnv[p] = 1, tag[p] = -1, vl[p] = l, vr[p] = r, posl[p] = l;
    if (l == r) return;
    int mid = (l + r) / 2;
    Build(p * 2, l, mid), Build(p * 2 + 1, mid + 1, r);
}
void Pushup(int p) {
    vl[p] = vl[p * 2];
    vr[p] = vr[p * 2 + 1];
    mnv[p] = min(mnv[p * 2], mnv[p * 2 + 1]);
}
void Tag(int p, int z) { tag[p] = z, vl[p] = vr[p] = z, mnv[p] = posl[p] - z + 1; }
void Pushdown(int p) {
    if (tag[p] != -1) Tag(p * 2, tag[p]), Tag(p * 2 + 1, tag[p]), tag[p] = -1;
}
void Set(int p, int l, int r, int x, int y, int z) {
    if (x <= l && r <= y) return Tag(p, z);
    int mid = (l + r) >> 1;
    Pushdown(p);
    if (x <= mid) Set(p * 2, l, mid, x, y, z);
    if (mid < y) Set(p * 2 + 1, mid + 1, r, x, y, z);
    Pushup(p);
}
int Getmn(int p, int l, int r, int x, int y) {
    if (x <= l && r <= y) return mnv[p];
    int mid = (l + r) >> 1, res = 1e9;
    Pushdown(p);
    if (x <= mid) res = min(res, Getmn(p * 2, l, mid, x, y));
    if (mid < y) res = min(res, Getmn(p * 2 + 1, mid + 1, r, x, y));
    return res;
}
int GetL(int p, int l, int r, int x) {
    if (l == r) return vl[p];
    int mid = (l + r) >> 1;
    Pushdown(p);
    if (x <= mid) return GetL(p * 2, l, mid, x);
    return GetL(p * 2 + 1, mid + 1, r, x);
}
int GetL_ge(int x) {
    int l = 1, r = n, ans = n + 1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (GetL(1, 1, n, mid) >= x) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    return ans;
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]), a[i]++, pos[a[i]].push_back(i);
    }
    Build(1, 1, n);
    for (int i = 1; i <= N; i++) {
        pos[i].push_back(0), pos[i].push_back(n + 1);
        sort(pos[i].begin(), pos[i].end());
        for (int j = 0; j + 1 < pos[i].size(); j++) {
            int l = pos[i][j] + 1, r = pos[i][j + 1] - 1;
            if (l > r) continue;
            if (r - l + 1 < i - 1) continue;
            int p = GetL_ge(l);
            if (p > r) continue;
            int mn = Getmn(1, 1, n, p, r);
            /*for (int k = l; k <= r; k++) {
                if (L[k] >= l) {
                    mn = min(mn, k - L[k] + 1);
                }
            }*/
            int mx = r - l + 1;
            // cout << i << ' ' << l << ' ' << r << '\n';
            if (mn <= mx) {
                add[mn].push_back(i);
                add[mx + 1].push_back(-i);
                // cout << "Adding:" << mn << ' ' << mx << ' ' << i << '\n';
            }
            Set(1, 1, n, p, r, pos[i][j]);
            // for (int k = l; k <= r; k++) L[k] = min(L[k], pos[i][j]);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (auto j : add[i]) {
            if (j > 0) U(j, 1);
            else U(-j, -1);
        }
        cout << Q() << ' ';
    }
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 20740kb

input:

6
0 0 0 1 2 3

output:

2 3 4 0 0 0 

result:

ok single line: '2 3 4 0 0 0 '

Test #2:

score: 0
Accepted
time: 4ms
memory: 20956kb

input:

100
0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1

output:

2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #3:

score: 0
Accepted
time: 93ms
memory: 21172kb

input:

100000
127 145 474 139 36 135 75 670 76 433 206 214 283 56 214 440 147 280 244 190 181 565 31 550 261 93 526 404 125 390 17 552 5 364 53 337 52 506 277 279 15 248 46 61 826 69 166 297 171 289 150 175 111 151 317 342 166 13 199 152 308 19 156 347 205 166 45 115 177 235 422 425 109 4 658 232 347 370 4...

output:

2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...

result:

ok single line: '2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #4:

score: 0
Accepted
time: 90ms
memory: 21516kb

input:

100000
360 34 204 156 183 404 21 3 20 122 170 193 347 144 51 464 94 265 190 88 284 437 538 392 661 397 839 208 83 191 42 16 194 515 374 53 617 502 307 504 348 175 219 63 2 130 289 223 135 440 284 189 104 142 87 117 316 218 301 14 87 405 293 489 763 197 678 196 173 96 257 17 190 525 243 161 220 178 8...

output:

2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...

result:

ok single line: '2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #5:

score: 0
Accepted
time: 97ms
memory: 20616kb

input:

100000
322 408 29 271 168 161 265 412 230 177 325 60 331 226 298 143 343 83 274 706 47 234 287 46 329 248 174 351 235 38 172 171 251 355 274 307 468 11 222 309 666 137 18 440 1209 7 103 354 496 336 183 602 240 316 442 253 32 486 308 18 115 125 110 65 268 502 148 793 91 759 313 269 31 63 250 90 143 6...

output:

2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 ...

result:

ok single line: '2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #6:

score: 0
Accepted
time: 52ms
memory: 20248kb

input:

100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #7:

score: 0
Accepted
time: 108ms
memory: 23288kb

input:

100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...

output:

2 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:

ok single line: '2 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 0 '

Test #8:

score: 0
Accepted
time: 77ms
memory: 23224kb

input:

100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok single line: '2 3 4 5 6 7 8 9 10 11 12 13 14... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '