Submission #386810

# Submission time Handle Problem Language Result Execution time Memory
386810 2021-04-07T10:56:22 Z cpp219 Exhibition (JOI19_ho_t2) C++14
100 / 100
233 ms 11356 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]);
}

bool lf(LL x,LL y){
    return x.sc < y.sc||(x.sc == y.sc && x.fs < y.fs);
}

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 "test"
    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,lf); 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:65:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   65 |     for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
      |     ^~~
joi2019_ho_t2.cpp:65:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |     for (ll i = 1;i <= m;i++) cin>>c[i],v.push_back(c[i]); compress();
      |                                                            ^~~~~~~~
joi2019_ho_t2.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   60 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 6 ms 2884 KB Output is correct
21 Correct 4 ms 2796 KB Output is correct
22 Correct 5 ms 2796 KB Output is correct
23 Correct 5 ms 2796 KB Output is correct
24 Correct 5 ms 2796 KB Output is correct
25 Correct 4 ms 2796 KB Output is correct
26 Correct 4 ms 2796 KB Output is correct
27 Correct 5 ms 2796 KB Output is correct
28 Correct 5 ms 2796 KB Output is correct
29 Correct 5 ms 2796 KB Output is correct
30 Correct 6 ms 2796 KB Output is correct
31 Correct 4 ms 2796 KB Output is correct
32 Correct 3 ms 2796 KB Output is correct
33 Correct 4 ms 2796 KB Output is correct
34 Correct 4 ms 2796 KB Output is correct
35 Correct 4 ms 2796 KB Output is correct
36 Correct 5 ms 2796 KB Output is correct
37 Correct 5 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 3 ms 2668 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 6 ms 2884 KB Output is correct
21 Correct 4 ms 2796 KB Output is correct
22 Correct 5 ms 2796 KB Output is correct
23 Correct 5 ms 2796 KB Output is correct
24 Correct 5 ms 2796 KB Output is correct
25 Correct 4 ms 2796 KB Output is correct
26 Correct 4 ms 2796 KB Output is correct
27 Correct 5 ms 2796 KB Output is correct
28 Correct 5 ms 2796 KB Output is correct
29 Correct 5 ms 2796 KB Output is correct
30 Correct 6 ms 2796 KB Output is correct
31 Correct 4 ms 2796 KB Output is correct
32 Correct 3 ms 2796 KB Output is correct
33 Correct 4 ms 2796 KB Output is correct
34 Correct 4 ms 2796 KB Output is correct
35 Correct 4 ms 2796 KB Output is correct
36 Correct 5 ms 2796 KB Output is correct
37 Correct 5 ms 2796 KB Output is correct
38 Correct 210 ms 11292 KB Output is correct
39 Correct 189 ms 11260 KB Output is correct
40 Correct 188 ms 11228 KB Output is correct
41 Correct 211 ms 11228 KB Output is correct
42 Correct 208 ms 11228 KB Output is correct
43 Correct 210 ms 11232 KB Output is correct
44 Correct 212 ms 11228 KB Output is correct
45 Correct 207 ms 11228 KB Output is correct
46 Correct 184 ms 11228 KB Output is correct
47 Correct 192 ms 10480 KB Output is correct
48 Correct 159 ms 10332 KB Output is correct
49 Correct 165 ms 9444 KB Output is correct
50 Correct 147 ms 9428 KB Output is correct
51 Correct 226 ms 11228 KB Output is correct
52 Correct 206 ms 11228 KB Output is correct
53 Correct 211 ms 11228 KB Output is correct
54 Correct 161 ms 11228 KB Output is correct
55 Correct 221 ms 11228 KB Output is correct
56 Correct 90 ms 7908 KB Output is correct
57 Correct 46 ms 5352 KB Output is correct
58 Correct 59 ms 7908 KB Output is correct
59 Correct 92 ms 8036 KB Output is correct
60 Correct 49 ms 5352 KB Output is correct
61 Correct 106 ms 7636 KB Output is correct
62 Correct 218 ms 11356 KB Output is correct
63 Correct 221 ms 11232 KB Output is correct
64 Correct 223 ms 11228 KB Output is correct
65 Correct 227 ms 11272 KB Output is correct
66 Correct 233 ms 11356 KB Output is correct
67 Correct 223 ms 11304 KB Output is correct
68 Correct 226 ms 11228 KB Output is correct
69 Correct 225 ms 11228 KB Output is correct
70 Correct 206 ms 11228 KB Output is correct
71 Correct 218 ms 11200 KB Output is correct
72 Correct 194 ms 11248 KB Output is correct
73 Correct 190 ms 11228 KB Output is correct