QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#868134#9982. Staircase MuseumAndyqian7WA 7ms7912kbC++261.3kb2025-01-24 13:01:232025-01-24 13:01:29

Judging History

This is the latest submission verdict.

  • [2025-01-24 13:01:29]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 7912kb
  • [2025-01-24 13:01:23]
  • Submitted

answer

#include <bits/stdc++.h>
#define rep(i, s, e) for (int i = s; i <= e; i++)
using namespace std;
const int N = 1e6 + 10;
int n, l[N], r[N], tr[N];
int query(int x)
{
    int ret = 0;
    for (; x; x -= x & -x)
        ret = max(ret, tr[x]);
    return ret;
}
void update(int x, int k)
{
    for (; x <= 2 * n; x += x & -x)
        tr[x] = max(tr[x], k);
}
struct node
{
    int x, y, no;
};
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        cin >> n;
        rep(i, 1, 2 * n) tr[i] = 0;
        rep(i, 1, n) cin >> l[i] >> r[i];
        vector<node> v = {{2, 2 * l[1]}};
        rep(i, 2, n)
        {
            if (l[i] > l[i - 1])
                v.push_back({2 * i + 1, 2 * l[i]});
            if (r[i] > r[i - 1])
                v.push_back({2 * i, 2 * r[i - 1] + 1});
        }
        sort(v.begin(), v.end(), [](node a, node b)
             { return a.y < b.y; });
        for (int i = 0; i < v.size(); i++)
        {
            v[i].no = i + 1;
        }
        sort(v.begin(), v.end(), [](node a, node b)
             { return a.x < b.x; });
        for (int i = 0; i < v.size(); i++)
        {
            update(v[i].no, query(v[i].no) + 1);
        }
        cout << query(2 * n) << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7912kb

input:

1
1
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

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
3
3
2
2
2
3
3
3
3
2
2
3
3
3
3
3
2
2
2
3
3
3
3
3
4
4
4
3
3
3
4
4
4
4
3
3
4
4
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
4
4
3
3
4
4
4
4
4
2
2
2
3
3
3
3
3
3
3
3
3
4
4
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 20th numbers differ - expected: '2', found: '3'