Submission #386798

# Submission time Handle Problem Language Result Execution time Memory
386798 2021-04-07T10:31:28 Z cpp219 Exhibition (JOI19_ho_t2) C++14
0 / 100
3 ms 2688 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e5 + 6;
const ll Log2 = 19;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<ll> v;
ll n,m,c[N],bit[N],dp[N];
LL a[N];

ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
    for (ll i = 1;i <= n;i++) a[i].fs = Find(a[i].fs),a[i].sc = Find(a[i].sc);
    for (ll i = 1;i <= m;i++) c[i] = Find(c[i]);
}

void upd(ll p,ll val){
    for (ll i = p;i < N;i += i & -i) bit[i] = max(bit[i],val);
}

ll Get(ll p){
    ll res = 0;
    for (ll i = p;i > 0;i -= i & -i) res = max(res,bit[i]);
    return res;
}
/// fs size    sc value
bool chk(ll mid){
    memset(bit,0,sizeof(bit));
    ll start = m - mid + 1;
    for (ll i = 1;i <= n;i++){
        ll p = Get(a[i].sc) + 1; dp[i] = 0;
        if (c[start + p - 1] >= a[i].fs) dp[i] = p;
        upd(a[i].sc,dp[i]);
        if (dp[i] >= mid) return 1;
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m;
    for (ll i = 1;i <= n;i++) cin>>a[i].fs>>a[i].sc,v.push_back(a[i].fs),v.push_back(a[i].sc);
    for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
    sort(a + 1,a + n + 1); sort(c + 1,c + m + 1);
    ll l,mid,h; //cout<<chk(2); return 0;
    l = 0; h = m;
    while(l <= h){
        mid = (l + h)/2;
        if (chk(mid)) l = mid + 1;
        else h = mid - 1;
    }
    cout<<h;
}

Compilation message

joi2019_ho_t2.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
joi2019_ho_t2.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:61:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   61 |     for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
      |     ^~~
joi2019_ho_t2.cpp:61:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   61 |     for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
      |                                                            ^~~~~~~~
joi2019_ho_t2.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Incorrect 3 ms 2668 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Incorrect 3 ms 2668 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Incorrect 3 ms 2668 KB Output isn't correct
6 Halted 0 ms 0 KB -