QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639673#7729. Permutation Compression IIFangYifanWA 120ms3852kbC++172.1kb2024-10-13 21:22:542024-10-13 21:22:55

Judging History

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

  • [2024-10-13 21:22:55]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:3852kb
  • [2024-10-13 21:22:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
constexpr int mod = 998244353;
constexpr int N = 1e6 + 10;

template <typename T>
struct BIT {
    const int maxn;
    vector<T> c;
    BIT(int n) : maxn(n), c(n + 1) {}
    int lowbit(int x) { return x & -x; }
    void insert(int x, T val) { // 注意 x > 0, 且同一个位置插入的值必须单调不减
        for (; x <= maxn; x += lowbit(x)) {
            c[x] = max(c[x], val);
        }
    }
    T query(int x) {
        T ans = 0;
        for (; x; x -= lowbit(x)) ans = max(ans, c[x]);
        return ans;
    }
};
void solve() {
    int n;
    cin >> n;
    vector<int> p(n + 1), pos(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        pos[p[i]] = i;
    }
    int ans = 0;
    BIT<int> bit(n);
    vector<int> dp(n + 1);
    vector<vector<int>> len(n + 1);
    for (int i = 1; i <= n; i++) {
        dp[i] = bit.query(p[i]) + 1;
        bit.insert(p[i], dp[i]);
        len[dp[i]].push_back(i);
        ans = max(ans, dp[i]);
    }
    if (ans == 1) {
        cout << "1 0\n";
        return;
    }
    int x = -1;
    vector<int> lis;
    priority_queue<int> q;
    for (int i = n; i >= 1; i--) {
        if (dp[i] == 2) q.push(p[i]);
        if (dp[i] == 1 && !q.empty() && p[i] < q.top()) x = i;
    }
    lis.push_back(x);
    for (int i = 1; i <= n; i++) {
        if (i > lis.back() && p[i] > p[lis.back()] && dp[i] == lis.size() + 1) {
            lis.push_back(i);
        }
    }
    while (!q.empty()) q.pop();
    int j = 1;
    vector<int> del;
    for (auto i : lis) {
        while (j < i) q.push(p[j++]);
        while (!q.empty() && q.top() > p[i]) {
            del.push_back(pos[q.top()]);
            q.pop();
        }
        j = i + 1;
    }
    cout << ans << ' ' << del.size() << "\n";
    for (auto x : del) cout << x << ' '; cout << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3852kb

input:

2
3
3 1 2
3
1 2 3

output:

2 1
1 
3 0


result:

ok ok n = 3

Test #2:

score: -100
Wrong Answer
time: 120ms
memory: 3676kb

input:

100000
7
2 6 7 1 4 3 5
6
1 5 6 3 2 4
3
1 2 3
3
2 1 3
14
9 6 13 10 4 7 5 14 1 12 8 3 2 11
3
1 2 3
14
1 9 3 14 5 7 4 6 12 2 8 11 13 10
8
7 1 3 6 2 5 8 4
16
9 3 4 8 7 16 10 6 11 1 14 2 13 12 5 15
3
3 1 2
33
9 10 23 3 16 1 19 32 25 4 5 31 28 7 22 27 30 8 6 17 2 14 13 29 20 33 26 18 24 11 12 15 21
2
2 1
...

output:

3 0

3 0

3 0

2 0

4 0

3 0

7 0

4 1
1 
7 1
1 
2 1
1 
9 0

1 0
2 0

1 0
2 0

5 0

2 0

6 0

3 0

2 0

5 0

1 0
3 1
1 
2 0

4 1
1 
10 0

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

4 0

4 0

3 0

4 0

5 2
1 2 
8 0

2 1
1 
4 0

1 0
5 0

5 1
1 
1 0
6 1
1 
2 0

1 0
3 0

3 0

5 0

3 0

4 0

4 1
1 
1 0
3 1
1 
3...

result:

wrong answer #prefix maximum is wrong