QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#861535#9982. Staircase Museumucup-team6275#WA 7ms3584kbC++202.4kb2025-01-18 17:56:282025-01-18 17:56:35

Judging History

This is the latest submission verdict.

  • [2025-01-18 17:56:35]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3584kb
  • [2025-01-18 17:56:28]
  • Submitted

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector <pair <int, int>> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;

    vector <int> dp1(n), dp2(n);
    vector <int> ok1(n), ok2(n);
    for (int i = 0; i < n; ++i) {
        if (i < n - 1 && a[i + 1].first == a[i].first) continue;
        ok1[i] = 1;
    }
    for (int i = 0; i < n; ++i) {
        if (i && a[i - 1].second == a[i].second) continue;
        ok2[i] = 1;
    }

    vector <int> oks1, oks2;

    for (int i = 0; i < n; ++i) {
        if (ok1[i]) oks1.push_back(i);
        if (ok2[i]) oks2.push_back(i);
    }

    for (int i = 0; i < n; ++i) {
        if (ok1[i]) dp1[i] = max(dp1[i], 1);
        if (ok2[i]) dp2[i] = max(dp2[i], 1);

        auto it = lower_bound(oks1.begin(), oks1.end(), i + 1);
        if (it != oks1.end() && ok1[i]) dp1[*it] = max(dp1[*it], dp1[i] + 1);

        it = lower_bound(oks2.begin(), oks2.end(), i + 1);
        if (it != oks2.end() && ok2[i]) dp2[*it] = max(dp2[*it], dp2[i] + 1);

        it = lower_bound(oks2.begin(), oks2.end(), i + 2);
        if (it != oks2.end() && ok1[i]) dp2[*it] = max(dp2[*it], dp1[i] + 1);

        int l = i;
        int r = n;

        while (r - l > 1) {
            int m = (l + r) / 2;
            if (a[m].first > a[i].second) r = m;
            else l = m;
        }

        if (r == n) continue;
        it = lower_bound(oks1.begin(), oks1.end(), r);
        if (it != oks1.end() && ok2[i]) dp1[*it] = max(dp1[*it], dp2[i] + 2);
    }
//    for (int i : oks1) cout << i << " ";
//    cout << '\n';
//    for (int i : oks2) cout << i << " ";
//    cout << "\n";
//
//    for (int i : dp1) cout << i << " ";
//    cout << "\n";
//    for (int i : dp2) cout << i << " ";
//    cout << "\n";

    cout << max(*max_element(dp1.begin(), dp1.end()), *max_element(dp2.begin(), dp2.end())) << "\n";
}

signed main() {
    if (1) {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    }
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

/*
4
3
1 2
1 3
1 3
3
1 2
2 3
3 3
3
1 1
1 3
3 3
4
1 2
2 3
3 4
4 5
 */

详细

Test #1:

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

input:

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

output:

2
3
3
4

result:

ok 4 number(s): "2 3 3 4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

1
1
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 3584kb

input:

9653
1
1 1
2
1 1
1 1
3
1 1
1 1
1 1
4
1 1
1 1
1 1
1 1
5
1 1
1 1
1 1
1 1
1 1
6
1 1
1 1
1 1
1 1
1 1
1 1
6
1 2
1 2
1 2
1 2
1 2
2 2
6
1 1
1 1
1 1
1 1
1 1
1 2
6
1 2
1 2
1 2
1 2
1 2
2 3
5
1 2
1 2
1 2
1 2
2 2
6
1 2
1 2
1 2
1 2
2 2
2 2
6
1 3
1 3
1 3
1 3
2 3
3 3
6
1 2
1 2
1 2
1 2
2 2
2 3
6
1 3
1 3
1 3
1 3
2 3...

output:

1
1
1
1
1
1
2
2
2
2
2
3
2
3
2
2
2
3
3
3
3
2
2
3
3
3
3
3
2
2
2
3
2
3
3
3
4
3
4
2
2
3
3
3
3
3
3
3
4
3
4
4
4
2
2
2
2
3
3
3
3
3
3
2
2
3
3
3
3
3
3
3
3
3
3
4
4
3
3
4
4
4
4
3
3
3
4
4
3
3
4
4
4
4
3
3
4
3
4
3
3
4
4
4
4
4
2
2
2
3
3
3
3
3
3
3
3
3
4
3
4
4
4
4
4
3
3
3
4
4
3
3
4
4
4
4
3
3
4
4
4
4
4
4
4
4
4
3
3
4
...

result:

wrong answer 13th numbers differ - expected: '3', found: '2'