Submission #160489

#TimeUsernameProblemLanguageResultExecution timeMemory
160489jhnah917조화행렬 (KOI18_matrix)C++14
100 / 100
311 ms36152 KiB
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<ll, ll> p;

struct asdf{
    int a, b, c;
    asdf(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
    bool operator < (const asdf &t) const {
        if(a != t.a) return a < t.a;
        if(b != t.b) return b < t.b;
        return c < t.c;
    }
};

int k, n;
int arr[4][202020];
vector<asdf> tmp;
vector<p> v;
set<p> st[202020];

int solve(){
    int ans = 0;
    for(int i=0; i<n; i++){
        int l = 1, r = ans + 1;
        while(l < r){
            int m = l + r >> 1;
            auto it = st[m].lower_bound(v[i]);
            if(it == st[m].begin()) r = m;
            else{
                if(prev(it)->y < v[i].y) l = m + 1;
                else r = m;
            }
        }
        ans = max(ans, l);
        auto it = st[l].insert(v[i]).first;
        it++;
        while(it != st[l].end() && it->y >= v[i].y){
            auto tmp = it; it++;
            st[l].erase(tmp);
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> k >> n;
    for(int i=1; i<=3; i++) for(int j=1; j<=n; j++){
        if(k < i) arr[i][j] = arr[i-1][j];
        else cin >> arr[i][j];
    }

    for(int i=1; i<=n; i++) tmp.pb({arr[1][i], arr[2][i], arr[3][i]});
    sort(all(tmp));
    for(auto &i : tmp) v.pb({i.b, i.c});
    cout << solve();
}

Compilation message (stderr)

matrix.cpp: In function 'int solve()':
matrix.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int m = l + r >> 1;
                     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...