QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#216202#7579. Nonsense TimeSolitaryDream#AC ✓7774ms4904kbC++171.0kb2023-10-15 16:40:302023-10-15 16:40:31

Judging History

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

  • [2023-10-15 16:40:31]
  • 评测
  • 测评结果:AC
  • 用时:7774ms
  • 内存:4904kb
  • [2023-10-15 16:40:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
int n, a[N], b[N], f[N], vis[N];
inline void Solve(int l, int r) {
    if (f[l - 1] == f[r + 1]) {
        for (int i = l; i <= r; ++i) f[i] = f[l - 1];
        return;
    }
    int m = (l + r) >> 1;
    for (int i = 1; i <= m; ++i) vis[b[i]] = 1;
    vector<int> h(1, 0);
    for (int i = 1; i <= n; ++i) if (vis[i]) {
        int fi = lower_bound(h.begin(), h.end(), a[i]) - h.begin();
        if (fi == h.size()) h.push_back(a[i]);
        else h[fi] = a[i];
    }
    f[m] = h.size() - 1;
    for (int i = 1; i <= m; ++i) vis[b[i]] = 0;
    if (l < m) Solve(l, m - 1);
    if (m < r) Solve(m + 1, r);
}
int main() {
    int Case;
    scanf("%d", &Case);
    while (Case--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%d", a + i);
        for (int i = 1; i <= n; ++i) scanf("%d", b + i);
        f[0] = 0; f[n + 1] = n + 1;
        Solve(1, n);
        for (int i = 1; i <= n; ++i) printf("%d ", f[i]);
        puts("");
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

1
5
2 5 3 1 4
1 4 5 3 2

output:

1 1 2 3 3 

result:

ok 5 number(s): "1 1 2 3 3"

Test #2:

score: 0
Accepted
time: 7774ms
memory: 4904kb

input:

3
50000
22166 21423 37322 49151 2245 43507 37354 30961 32198 31003 32257 22468 27730 18919 2196 31303 3176 37808 4455 10088 18018 39466 29912 379 1832 17454 15968 4355 43806 24661 23628 14892 28610 44878 34190 33667 21697 4707 35211 12330 30832 8775 39434 26352 44030 31455 41042 11966 1147 39695 240...

output:

1 2 2 2 2 2 2 3 4 4 5 6 6 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 9 9 9 10 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 17 17 17 17 17 17 17 18 18 18 18...

result:

ok 150000 numbers