QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#861221#9982. Staircase Museumucup-team055#WA 9ms3712kbC++203.2kb2025-01-18 16:33:232025-01-18 16:36:39

Judging History

This is the latest submission verdict.

  • [2025-01-18 16:36:39]
  • Judged
  • Verdict: WA
  • Time: 9ms
  • Memory: 3712kb
  • [2025-01-18 16:33:23]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> int UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}



void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    int N;
    cin >> N;
    vector<int> L(N), R(N);
    rep(i, 0, N) cin >> L[i] >> R[i], L[i]--;
    vector<vector<pair<int, int>>> p(2);
    p[0].emplace_back(0, R[0]);
    rep(i, 0, N - 1){
        if (L[i] != L[i + 1]){
            p[0].emplace_back(i + 1, R[i + 1]);
        }
        if (R[i] != R[i + 1]){
            p[1].emplace_back(i + 1, L[i]);
        }
    }
    p[1].emplace_back(N, L.back());
    int X = p[0].size(), Y = p[1].size();
    vector<vector<int>> dp(2);
    dp[0].resize(X, 0);
    dp[1].resize(Y, 0);
    struct F{
        int i;
        int j;
    };
    vector<F> order;
    rep(i, 0, X) order.emplace_back(0, i);
    rep(i, 0, Y) order.emplace_back(1, i);
    sort(all(order), [&](F l, F r){
       return p[l.i][l.j].first + p[l.i][l.j].second < p[r.i][r.j].first + p[r.i][r.j].second;
    });
    auto f = [&](vector<pair<int, int>> &v, pair<int, int> a) -> int {
        int L = -1, R = v.size();
        while (R - L > 1){
            int M = (L + R) / 2;
            if (v[M].first < a.first && v[M].second < a.second) L = M;
            else R = M;
        }
        return R;
    };
    for (auto [i, j] : order){
        int a = f(p[i ^ 1], p[i][j]);
        if (a == 0) dp[i][j] = 1;
        else dp[i][j] = dp[i ^ 1][a - 1] + 2;
        if (j) chmax(dp[i][j], 1 + dp[i][j - 1]);
    }
    cout << max(vec_max(dp[0]), vec_max(dp[1])) << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1
1
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 9ms
memory: 3712kb

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
3
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
3
3
3
3
3
3
3
3
3
4
3
4
4
4
4
4
3
3
4
4
4
4
4
4
4
4
4
3
3
4
4
4
4
4
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
4
4
4
4
4
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'