답안 #1024468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024468 2024-07-16T05:35:45 Z hotboy2703 Rectangles (IOI19_rect) C++17
100 / 100
2816 ms 955056 KB
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 2510;
const ll MAXK = 13;
vector <pll> row[MAXN][MAXN];
vector <pair <ll,pll> > col[MAXN][MAXN];
pll bound[MAXN][MAXN];
vector <ll> down[MAXN][MAXN];
ll sp[MAXK][MAXN];
vector <ll> b;
ll highest(ll x,ll y){
    if (b[y]>b[x])return y;
    return x;
}
ll query(ll l,ll r){
    ll sz = __lg(r-l+1);
    return highest(sp[sz][l],sp[sz][r-MASK(sz)+1]);
}
void solve(ll l,ll r,vector <pll> &ans){
    if (l > r)return;
    ll mid = query(l,r);
    solve(l,mid-1,ans);
    solve(mid+1,r,ans);
    ans[mid] = MP(l,r);
}
vector <pll> build(){
    ll n = sz(b);
    for (ll i = 0;i < n;i ++){
        sp[0][i] = i;
    }
    for (ll j = 1;j < MAXK;j ++){
        for (ll i = 0;i + MASK(j) - 1 < n;i ++){
            sp[j][i] = highest(sp[j-1][i],sp[j-1][i+MASK(j-1)]);
        }
    }
    vector <pll> res(n);
    solve(0,n-1,res);
    for (ll i = 0;i < n;i ++){
        if (res[i].fi == 0 || res[i].se == n-1 || b[res[i].fi-1] <= b[i] || b[res[i].se+1] <= b[i])res[i] = MP(-1,-1);
    }
    return res;
}
long long count_rectangles(std::vector<std::vector<int> > a){
    ll n = sz(a);
    ll m = sz(a[0]);
//    cout<<n<<' '<<m<<endl;
    for (ll i = 0;i < n; i ++){
        b = a[i];
        vector <pll> tmp = build();
        for (ll j = 0;j < m;j ++){
            bound[i][j] = tmp[j];
            if (bound[i][j].fi != -1)row[bound[i][j].fi][bound[i][j].se].push_back(MP(i,0));
        }
    }
    for (ll i = 0;i < m;i ++){
        for (ll j = i;j < m;j ++){
            for (ll k = sz(row[i][j])-1;k>=0;k--){
                if (k == sz(row[i][j])-1 || row[i][j][k].fi + 1 < row[i][j][k+1].fi)row[i][j][k].se = row[i][j][k].fi ;
                else row[i][j][k].se = row[i][j][k+1].se;
//                if (i==j&&j==1)cout<<row[i][j][k].fi<<' '<<row[i][j][k].se<<endl;
            }
        }
    }
    for (ll j = 0;j < m;j ++){
        b.resize(n);
        for (ll i = 0;i < n;i ++){
            b[i] = a[i][j];
        }
        vector <pll> tmp = build();
        for (auto x:tmp){
            if (x.fi==-1)continue;
            col[x.fi][x.se].push_back(MP(j,MP(0,0)));
            down[x.fi][j].push_back(x.se);
        }
    }
    for (ll i = 0;i < n;i ++){
        for (ll j = i;j < n;j ++){
            for (ll k = sz(col[i][j])-1;k>=0;k--){
                if (k == sz(col[i][j])-1 || col[i][j][k].fi + 1 < col[i][j][k+1].fi)col[i][j][k].se.se = col[i][j][k].fi;
                else col[i][j][k].se.se = col[i][j][k+1].se.se;
            }
            for (ll k = 0;k < sz(col[i][j]);k ++){
                if (k == 0 || col[i][j][k].fi - 1 > col[i][j][k-1].fi)col[i][j][k].se.fi = col[i][j][k].fi;
                else col[i][j][k].se.fi = col[i][j][k-1].se.fi;
            }
        }
    }
    ll res = 0;
    for (ll i = 0;i < n;i ++){
        for (ll j = 0;j < m;j ++){
            if (bound[i][j].fi==-1)continue;
            ll l = bound[i][j].fi,r = bound[i][j].se;
            ll max1 = (*lower_bound(row[l][r].begin(),row[l][r].end(),MP(i,-1))).se;
//            cout<<i<<' '<<j<<' '<<l<<' '<<r<<' '<<max1<<endl;
            for (auto x:down[i][j]){

                pll tmp = (*lower_bound(col[i][x].begin(),col[i][x].end(),MP(j,MP(-1,-1)))).se;
//                cout<<x<<' '<<tmp.fi<<' '<<tmp.se<<endl;
                if (tmp.fi <= l && tmp.se >= r && x <= max1){
//                    cout<<i<<' '<<l<<' '<<x<<' '<<r<<endl;
                    res++;
                }
            }

        }
    }
    return res;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444500 KB Output is correct
2 Correct 125 ms 444496 KB Output is correct
3 Correct 121 ms 444496 KB Output is correct
4 Correct 126 ms 444500 KB Output is correct
5 Correct 125 ms 444500 KB Output is correct
6 Correct 119 ms 444624 KB Output is correct
7 Correct 109 ms 444576 KB Output is correct
8 Correct 107 ms 444568 KB Output is correct
9 Correct 122 ms 444500 KB Output is correct
10 Correct 118 ms 444552 KB Output is correct
11 Correct 150 ms 444500 KB Output is correct
12 Correct 123 ms 444496 KB Output is correct
13 Correct 128 ms 444496 KB Output is correct
14 Correct 127 ms 444496 KB Output is correct
15 Correct 110 ms 444524 KB Output is correct
16 Correct 122 ms 444500 KB Output is correct
17 Correct 127 ms 444496 KB Output is correct
18 Correct 130 ms 444448 KB Output is correct
19 Correct 120 ms 444496 KB Output is correct
20 Correct 128 ms 444496 KB Output is correct
21 Correct 128 ms 444536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444500 KB Output is correct
2 Correct 125 ms 444496 KB Output is correct
3 Correct 121 ms 444496 KB Output is correct
4 Correct 126 ms 444500 KB Output is correct
5 Correct 125 ms 444500 KB Output is correct
6 Correct 119 ms 444624 KB Output is correct
7 Correct 109 ms 444576 KB Output is correct
8 Correct 107 ms 444568 KB Output is correct
9 Correct 122 ms 444500 KB Output is correct
10 Correct 118 ms 444552 KB Output is correct
11 Correct 150 ms 444500 KB Output is correct
12 Correct 123 ms 444496 KB Output is correct
13 Correct 128 ms 444496 KB Output is correct
14 Correct 127 ms 444496 KB Output is correct
15 Correct 110 ms 444524 KB Output is correct
16 Correct 122 ms 444500 KB Output is correct
17 Correct 127 ms 444496 KB Output is correct
18 Correct 130 ms 444448 KB Output is correct
19 Correct 120 ms 444496 KB Output is correct
20 Correct 128 ms 444496 KB Output is correct
21 Correct 128 ms 444536 KB Output is correct
22 Correct 127 ms 445264 KB Output is correct
23 Correct 110 ms 445264 KB Output is correct
24 Correct 125 ms 445264 KB Output is correct
25 Correct 128 ms 445008 KB Output is correct
26 Correct 155 ms 445136 KB Output is correct
27 Correct 129 ms 445008 KB Output is correct
28 Correct 128 ms 445008 KB Output is correct
29 Correct 130 ms 445008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444500 KB Output is correct
2 Correct 125 ms 444496 KB Output is correct
3 Correct 121 ms 444496 KB Output is correct
4 Correct 126 ms 444500 KB Output is correct
5 Correct 125 ms 444500 KB Output is correct
6 Correct 119 ms 444624 KB Output is correct
7 Correct 109 ms 444576 KB Output is correct
8 Correct 107 ms 444568 KB Output is correct
9 Correct 122 ms 444500 KB Output is correct
10 Correct 118 ms 444552 KB Output is correct
11 Correct 150 ms 444500 KB Output is correct
12 Correct 123 ms 444496 KB Output is correct
13 Correct 128 ms 444496 KB Output is correct
14 Correct 127 ms 444496 KB Output is correct
15 Correct 110 ms 444524 KB Output is correct
16 Correct 122 ms 444500 KB Output is correct
17 Correct 127 ms 445264 KB Output is correct
18 Correct 110 ms 445264 KB Output is correct
19 Correct 125 ms 445264 KB Output is correct
20 Correct 128 ms 445008 KB Output is correct
21 Correct 155 ms 445136 KB Output is correct
22 Correct 129 ms 445008 KB Output is correct
23 Correct 128 ms 445008 KB Output is correct
24 Correct 130 ms 445008 KB Output is correct
25 Correct 127 ms 444496 KB Output is correct
26 Correct 130 ms 444448 KB Output is correct
27 Correct 120 ms 444496 KB Output is correct
28 Correct 128 ms 444496 KB Output is correct
29 Correct 128 ms 444536 KB Output is correct
30 Correct 142 ms 448416 KB Output is correct
31 Correct 119 ms 448592 KB Output is correct
32 Correct 130 ms 448492 KB Output is correct
33 Correct 135 ms 446800 KB Output is correct
34 Correct 149 ms 447824 KB Output is correct
35 Correct 157 ms 448080 KB Output is correct
36 Correct 181 ms 447824 KB Output is correct
37 Correct 135 ms 447828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444500 KB Output is correct
2 Correct 125 ms 444496 KB Output is correct
3 Correct 121 ms 444496 KB Output is correct
4 Correct 126 ms 444500 KB Output is correct
5 Correct 125 ms 444500 KB Output is correct
6 Correct 119 ms 444624 KB Output is correct
7 Correct 109 ms 444576 KB Output is correct
8 Correct 107 ms 444568 KB Output is correct
9 Correct 122 ms 444500 KB Output is correct
10 Correct 118 ms 444552 KB Output is correct
11 Correct 150 ms 444500 KB Output is correct
12 Correct 123 ms 444496 KB Output is correct
13 Correct 128 ms 444496 KB Output is correct
14 Correct 127 ms 444496 KB Output is correct
15 Correct 110 ms 444524 KB Output is correct
16 Correct 122 ms 444500 KB Output is correct
17 Correct 127 ms 445264 KB Output is correct
18 Correct 110 ms 445264 KB Output is correct
19 Correct 125 ms 445264 KB Output is correct
20 Correct 128 ms 445008 KB Output is correct
21 Correct 155 ms 445136 KB Output is correct
22 Correct 129 ms 445008 KB Output is correct
23 Correct 128 ms 445008 KB Output is correct
24 Correct 130 ms 445008 KB Output is correct
25 Correct 142 ms 448416 KB Output is correct
26 Correct 119 ms 448592 KB Output is correct
27 Correct 130 ms 448492 KB Output is correct
28 Correct 135 ms 446800 KB Output is correct
29 Correct 149 ms 447824 KB Output is correct
30 Correct 157 ms 448080 KB Output is correct
31 Correct 181 ms 447824 KB Output is correct
32 Correct 135 ms 447828 KB Output is correct
33 Correct 127 ms 444496 KB Output is correct
34 Correct 130 ms 444448 KB Output is correct
35 Correct 120 ms 444496 KB Output is correct
36 Correct 128 ms 444496 KB Output is correct
37 Correct 128 ms 444536 KB Output is correct
38 Correct 214 ms 481100 KB Output is correct
39 Correct 203 ms 480924 KB Output is correct
40 Correct 197 ms 474960 KB Output is correct
41 Correct 205 ms 474960 KB Output is correct
42 Correct 235 ms 487508 KB Output is correct
43 Correct 235 ms 487500 KB Output is correct
44 Correct 239 ms 488052 KB Output is correct
45 Correct 232 ms 485676 KB Output is correct
46 Correct 202 ms 463440 KB Output is correct
47 Correct 223 ms 466640 KB Output is correct
48 Correct 318 ms 477776 KB Output is correct
49 Correct 321 ms 479828 KB Output is correct
50 Correct 230 ms 463760 KB Output is correct
51 Correct 218 ms 462160 KB Output is correct
52 Correct 286 ms 477140 KB Output is correct
53 Correct 291 ms 478288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 445064 KB Output is correct
2 Correct 127 ms 444816 KB Output is correct
3 Correct 133 ms 444692 KB Output is correct
4 Correct 122 ms 444748 KB Output is correct
5 Correct 128 ms 444860 KB Output is correct
6 Correct 127 ms 444900 KB Output is correct
7 Correct 128 ms 444984 KB Output is correct
8 Correct 138 ms 444788 KB Output is correct
9 Correct 126 ms 444980 KB Output is correct
10 Correct 125 ms 444752 KB Output is correct
11 Correct 125 ms 444676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444496 KB Output is correct
2 Correct 130 ms 444448 KB Output is correct
3 Correct 120 ms 444496 KB Output is correct
4 Correct 128 ms 444496 KB Output is correct
5 Correct 128 ms 444536 KB Output is correct
6 Correct 123 ms 444500 KB Output is correct
7 Correct 607 ms 543060 KB Output is correct
8 Correct 1229 ms 653372 KB Output is correct
9 Correct 1194 ms 653904 KB Output is correct
10 Correct 1201 ms 654180 KB Output is correct
11 Correct 311 ms 499192 KB Output is correct
12 Correct 502 ms 551364 KB Output is correct
13 Correct 547 ms 554936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 444500 KB Output is correct
2 Correct 125 ms 444496 KB Output is correct
3 Correct 121 ms 444496 KB Output is correct
4 Correct 126 ms 444500 KB Output is correct
5 Correct 125 ms 444500 KB Output is correct
6 Correct 119 ms 444624 KB Output is correct
7 Correct 109 ms 444576 KB Output is correct
8 Correct 107 ms 444568 KB Output is correct
9 Correct 122 ms 444500 KB Output is correct
10 Correct 118 ms 444552 KB Output is correct
11 Correct 150 ms 444500 KB Output is correct
12 Correct 123 ms 444496 KB Output is correct
13 Correct 128 ms 444496 KB Output is correct
14 Correct 127 ms 444496 KB Output is correct
15 Correct 110 ms 444524 KB Output is correct
16 Correct 122 ms 444500 KB Output is correct
17 Correct 127 ms 445264 KB Output is correct
18 Correct 110 ms 445264 KB Output is correct
19 Correct 125 ms 445264 KB Output is correct
20 Correct 128 ms 445008 KB Output is correct
21 Correct 155 ms 445136 KB Output is correct
22 Correct 129 ms 445008 KB Output is correct
23 Correct 128 ms 445008 KB Output is correct
24 Correct 130 ms 445008 KB Output is correct
25 Correct 142 ms 448416 KB Output is correct
26 Correct 119 ms 448592 KB Output is correct
27 Correct 130 ms 448492 KB Output is correct
28 Correct 135 ms 446800 KB Output is correct
29 Correct 149 ms 447824 KB Output is correct
30 Correct 157 ms 448080 KB Output is correct
31 Correct 181 ms 447824 KB Output is correct
32 Correct 135 ms 447828 KB Output is correct
33 Correct 214 ms 481100 KB Output is correct
34 Correct 203 ms 480924 KB Output is correct
35 Correct 197 ms 474960 KB Output is correct
36 Correct 205 ms 474960 KB Output is correct
37 Correct 235 ms 487508 KB Output is correct
38 Correct 235 ms 487500 KB Output is correct
39 Correct 239 ms 488052 KB Output is correct
40 Correct 232 ms 485676 KB Output is correct
41 Correct 202 ms 463440 KB Output is correct
42 Correct 223 ms 466640 KB Output is correct
43 Correct 318 ms 477776 KB Output is correct
44 Correct 321 ms 479828 KB Output is correct
45 Correct 230 ms 463760 KB Output is correct
46 Correct 218 ms 462160 KB Output is correct
47 Correct 286 ms 477140 KB Output is correct
48 Correct 291 ms 478288 KB Output is correct
49 Correct 131 ms 445064 KB Output is correct
50 Correct 127 ms 444816 KB Output is correct
51 Correct 133 ms 444692 KB Output is correct
52 Correct 122 ms 444748 KB Output is correct
53 Correct 128 ms 444860 KB Output is correct
54 Correct 127 ms 444900 KB Output is correct
55 Correct 128 ms 444984 KB Output is correct
56 Correct 138 ms 444788 KB Output is correct
57 Correct 126 ms 444980 KB Output is correct
58 Correct 125 ms 444752 KB Output is correct
59 Correct 125 ms 444676 KB Output is correct
60 Correct 123 ms 444500 KB Output is correct
61 Correct 607 ms 543060 KB Output is correct
62 Correct 1229 ms 653372 KB Output is correct
63 Correct 1194 ms 653904 KB Output is correct
64 Correct 1201 ms 654180 KB Output is correct
65 Correct 311 ms 499192 KB Output is correct
66 Correct 502 ms 551364 KB Output is correct
67 Correct 547 ms 554936 KB Output is correct
68 Correct 127 ms 444496 KB Output is correct
69 Correct 130 ms 444448 KB Output is correct
70 Correct 120 ms 444496 KB Output is correct
71 Correct 128 ms 444496 KB Output is correct
72 Correct 128 ms 444536 KB Output is correct
73 Correct 1660 ms 882656 KB Output is correct
74 Correct 1486 ms 882876 KB Output is correct
75 Correct 1104 ms 801872 KB Output is correct
76 Correct 1006 ms 801920 KB Output is correct
77 Correct 1723 ms 955056 KB Output is correct
78 Correct 1564 ms 678484 KB Output is correct
79 Correct 1733 ms 716776 KB Output is correct
80 Correct 2816 ms 831308 KB Output is correct
81 Correct 1645 ms 695932 KB Output is correct
82 Correct 2205 ms 795456 KB Output is correct
83 Correct 2744 ms 860308 KB Output is correct
84 Correct 1473 ms 674708 KB Output is correct
85 Correct 2583 ms 843836 KB Output is correct
86 Correct 2598 ms 833016 KB Output is correct
87 Correct 1069 ms 758052 KB Output is correct
88 Correct 1817 ms 954712 KB Output is correct
89 Correct 1851 ms 954848 KB Output is correct
90 Correct 1869 ms 954960 KB Output is correct