답안 #1056297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056297 2024-08-13T08:42:56 Z boyliguanhan 메기 농장 (IOI22_fish) C++17
100 / 100
998 ms 157380 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<int>fishies[100010];
map<int,ll>fishiess[100010];
unordered_map<int,ll>dp[100010][2];
int N;
inline ll ones(int col,int len){
    return (--fishiess[col].upper_bound(len))->second;
}
struct segtree{
    ll T[1<<18];
    ll query(int i,int l,int r,int ll,int rr){
        if(l>rr||ll>r) return -1e18;
        if(ll<=l&&r<=rr) return T[i];
        return max(query(i*2,l,l+r>>1,ll,rr),
                query(i*2+1,l+r+2>>1,r,ll,rr));
    }
    void upd(int i,int l,int r,int p,ll x){
        if(l==r)return void(T[i]=x);
        if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
        else upd(i*2+1,l+r+2>>1,r,p,x);
        T[i]=max(T[i*2],T[i*2+1]);
    }
};
struct a_data_type{
    segtree Sec,First,Overal,Third;
    inline ll sec(int pos){
        return Sec.query(1,0,N,pos,N);
    }
    inline ll first(int pos){
        return First.query(1,0,N,0,pos);
    }
    inline ll overal(int pos){
        return Overal.query(1,0,N,pos,N);
    }
    inline ll third(int pos){
        return Third.query(1,0,N,0,pos);
    }
    set<int>prv;
    void init(int i) {
        for(auto j:prv)
            Overal.upd(1,0,N,j,0),
            First.upd(1,0,N,j,0),
            Sec.upd(1,0,N,j,0),
            Third.upd(1,0,N,j,0);
        prv.clear();
        for(auto j:fishies[i]){
            prv.insert(--j);
            ll A=dp[i][0][j];
            ll B=dp[i][1][j];
            Overal.upd(1,0,N,j,max(A,B));
            First.upd(1,0,N,j,max(A,B)-ones(i+1,j));
            Sec.upd(1,0,N,j,A);
            Third.upd(1,0,N,j,B-ones(i,j)-ones(i+1,j));
        }
    }
} likehell[2];
ll max_weights(int N_,int M,vector<int> X,vector<int> Y,vector<int> W) {
    N=N_;
    for(int i=0;i<M;i++)
        fishies[X[i]+1].insert(Y[i]+1),
        fishiess[X[i]+1][Y[i]+1]=W[i];
    for(int i=1;i<=N;i++){
        fishiess[i][N+1];
        fishiess[i][0];
        auto it=++fishiess[i].begin();
        while(it!=fishiess[i].end())
            it->second+=prev(it)->second,it++;
    }
    for(int i=1;i<=N;i++)
        fishies[i].insert(1),
        fishies[i].insert(N+1);
    fishiess[N+1][0];
    for(auto i:fishies[1])
        dp[1][1][i-1]=ones(2,i-1);
    int b=0;
    likehell[b].init(1);
    for(int i=2;i<=N;i++){
        for(auto rw:fishies[i]) {
            ll cons=ones(i+1,rw-1)+ones(i-1,rw-1);
            ll F=likehell[!b].first(rw-1);
            ll S=likehell[!b].overal(rw)-ones(i-1,rw-1);
            dp[i][1][rw-1]=cons+max(F,S);
        }
        for(auto rw2:fishies[i]){
            ll cons=ones(i+1,rw2-1)+ones(i-1,rw2-1);
            ll F=likehell[b].third(rw2-1);
            ll S=likehell[b].overal(rw2);
            dp[i][1][rw2-1]=max(dp[i][1][rw2-1],F+cons);
            dp[i][0][rw2-1]=S-ones(i,rw2-1)-ones(i-1,rw2-1)+cons;
        }
        for(auto rw2:fishies[i]) {
            ll K=likehell[b].sec(rw2-1)-ones(i,rw2-1);
            dp[i][0][rw2-1]=max(dp[i][0][rw2-1],ones(i+1,rw2-1)+K);
        }
        b=!b;
        likehell[b].init(i);
    }
    return likehell[b].overal(0);
}

Compilation message

fish.cpp: In member function 'll segtree::query(int, int, int, int, int)':
fish.cpp:17:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |         return max(query(i*2,l,l+r>>1,ll,rr),
      |                                ~^~
fish.cpp:18:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |                 query(i*2+1,l+r+2>>1,r,ll,rr));
      |                             ~~~^~
fish.cpp: In member function 'void segtree::upd(int, int, int, int, ll)':
fish.cpp:22:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |            ~^~
fish.cpp:22:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |                                ~^~
fish.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         else upd(i*2+1,l+r+2>>1,r,p,x);
      |                        ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 100088 KB Output is correct
2 Correct 332 ms 111380 KB Output is correct
3 Correct 151 ms 87376 KB Output is correct
4 Correct 162 ms 87340 KB Output is correct
5 Correct 826 ms 157380 KB Output is correct
6 Correct 844 ms 146452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 32860 KB Output is correct
2 Correct 478 ms 123424 KB Output is correct
3 Correct 609 ms 139616 KB Output is correct
4 Correct 239 ms 100208 KB Output is correct
5 Correct 301 ms 111300 KB Output is correct
6 Correct 5 ms 32924 KB Output is correct
7 Correct 5 ms 32736 KB Output is correct
8 Correct 5 ms 32856 KB Output is correct
9 Correct 4 ms 32960 KB Output is correct
10 Correct 144 ms 87312 KB Output is correct
11 Correct 154 ms 87376 KB Output is correct
12 Correct 283 ms 104800 KB Output is correct
13 Correct 337 ms 115652 KB Output is correct
14 Correct 267 ms 102572 KB Output is correct
15 Correct 301 ms 111400 KB Output is correct
16 Correct 267 ms 102576 KB Output is correct
17 Correct 282 ms 111336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 87364 KB Output is correct
2 Correct 226 ms 87376 KB Output is correct
3 Correct 169 ms 86352 KB Output is correct
4 Correct 184 ms 90448 KB Output is correct
5 Correct 213 ms 95828 KB Output is correct
6 Correct 215 ms 95780 KB Output is correct
7 Correct 209 ms 95828 KB Output is correct
8 Correct 232 ms 95824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32856 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 4 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32980 KB Output is correct
6 Correct 4 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 4 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33372 KB Output is correct
13 Correct 4 ms 32856 KB Output is correct
14 Correct 5 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32856 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 4 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32980 KB Output is correct
6 Correct 4 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 4 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33372 KB Output is correct
13 Correct 4 ms 32856 KB Output is correct
14 Correct 5 ms 33116 KB Output is correct
15 Correct 5 ms 33116 KB Output is correct
16 Correct 7 ms 33372 KB Output is correct
17 Correct 74 ms 42632 KB Output is correct
18 Correct 82 ms 43136 KB Output is correct
19 Correct 72 ms 42864 KB Output is correct
20 Correct 70 ms 43016 KB Output is correct
21 Correct 68 ms 43084 KB Output is correct
22 Correct 146 ms 53060 KB Output is correct
23 Correct 17 ms 34904 KB Output is correct
24 Correct 50 ms 39560 KB Output is correct
25 Correct 6 ms 33372 KB Output is correct
26 Correct 16 ms 34904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32856 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 4 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32980 KB Output is correct
6 Correct 4 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 4 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33372 KB Output is correct
13 Correct 4 ms 32856 KB Output is correct
14 Correct 5 ms 33116 KB Output is correct
15 Correct 5 ms 33116 KB Output is correct
16 Correct 7 ms 33372 KB Output is correct
17 Correct 74 ms 42632 KB Output is correct
18 Correct 82 ms 43136 KB Output is correct
19 Correct 72 ms 42864 KB Output is correct
20 Correct 70 ms 43016 KB Output is correct
21 Correct 68 ms 43084 KB Output is correct
22 Correct 146 ms 53060 KB Output is correct
23 Correct 17 ms 34904 KB Output is correct
24 Correct 50 ms 39560 KB Output is correct
25 Correct 6 ms 33372 KB Output is correct
26 Correct 16 ms 34904 KB Output is correct
27 Correct 10 ms 35420 KB Output is correct
28 Correct 424 ms 81816 KB Output is correct
29 Correct 667 ms 103708 KB Output is correct
30 Correct 694 ms 98900 KB Output is correct
31 Correct 715 ms 98916 KB Output is correct
32 Correct 742 ms 101204 KB Output is correct
33 Correct 762 ms 98896 KB Output is correct
34 Correct 694 ms 98840 KB Output is correct
35 Correct 202 ms 59220 KB Output is correct
36 Correct 666 ms 100968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 87364 KB Output is correct
2 Correct 226 ms 87376 KB Output is correct
3 Correct 169 ms 86352 KB Output is correct
4 Correct 184 ms 90448 KB Output is correct
5 Correct 213 ms 95828 KB Output is correct
6 Correct 215 ms 95780 KB Output is correct
7 Correct 209 ms 95828 KB Output is correct
8 Correct 232 ms 95824 KB Output is correct
9 Correct 316 ms 112944 KB Output is correct
10 Correct 163 ms 73268 KB Output is correct
11 Correct 390 ms 115432 KB Output is correct
12 Correct 5 ms 32856 KB Output is correct
13 Correct 5 ms 32860 KB Output is correct
14 Correct 4 ms 32860 KB Output is correct
15 Correct 4 ms 32860 KB Output is correct
16 Correct 4 ms 32944 KB Output is correct
17 Correct 5 ms 32856 KB Output is correct
18 Correct 151 ms 87412 KB Output is correct
19 Correct 151 ms 87380 KB Output is correct
20 Correct 166 ms 87348 KB Output is correct
21 Correct 147 ms 87240 KB Output is correct
22 Correct 401 ms 112824 KB Output is correct
23 Correct 426 ms 125872 KB Output is correct
24 Correct 438 ms 126800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 100088 KB Output is correct
2 Correct 332 ms 111380 KB Output is correct
3 Correct 151 ms 87376 KB Output is correct
4 Correct 162 ms 87340 KB Output is correct
5 Correct 826 ms 157380 KB Output is correct
6 Correct 844 ms 146452 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 478 ms 123424 KB Output is correct
9 Correct 609 ms 139616 KB Output is correct
10 Correct 239 ms 100208 KB Output is correct
11 Correct 301 ms 111300 KB Output is correct
12 Correct 5 ms 32924 KB Output is correct
13 Correct 5 ms 32736 KB Output is correct
14 Correct 5 ms 32856 KB Output is correct
15 Correct 4 ms 32960 KB Output is correct
16 Correct 144 ms 87312 KB Output is correct
17 Correct 154 ms 87376 KB Output is correct
18 Correct 283 ms 104800 KB Output is correct
19 Correct 337 ms 115652 KB Output is correct
20 Correct 267 ms 102572 KB Output is correct
21 Correct 301 ms 111400 KB Output is correct
22 Correct 267 ms 102576 KB Output is correct
23 Correct 282 ms 111336 KB Output is correct
24 Correct 147 ms 87364 KB Output is correct
25 Correct 226 ms 87376 KB Output is correct
26 Correct 169 ms 86352 KB Output is correct
27 Correct 184 ms 90448 KB Output is correct
28 Correct 213 ms 95828 KB Output is correct
29 Correct 215 ms 95780 KB Output is correct
30 Correct 209 ms 95828 KB Output is correct
31 Correct 232 ms 95824 KB Output is correct
32 Correct 5 ms 32856 KB Output is correct
33 Correct 4 ms 32860 KB Output is correct
34 Correct 4 ms 32860 KB Output is correct
35 Correct 4 ms 32860 KB Output is correct
36 Correct 4 ms 32980 KB Output is correct
37 Correct 4 ms 32860 KB Output is correct
38 Correct 4 ms 32860 KB Output is correct
39 Correct 4 ms 32860 KB Output is correct
40 Correct 5 ms 33116 KB Output is correct
41 Correct 7 ms 33372 KB Output is correct
42 Correct 5 ms 33116 KB Output is correct
43 Correct 5 ms 33372 KB Output is correct
44 Correct 4 ms 32856 KB Output is correct
45 Correct 5 ms 33116 KB Output is correct
46 Correct 5 ms 33116 KB Output is correct
47 Correct 7 ms 33372 KB Output is correct
48 Correct 74 ms 42632 KB Output is correct
49 Correct 82 ms 43136 KB Output is correct
50 Correct 72 ms 42864 KB Output is correct
51 Correct 70 ms 43016 KB Output is correct
52 Correct 68 ms 43084 KB Output is correct
53 Correct 146 ms 53060 KB Output is correct
54 Correct 17 ms 34904 KB Output is correct
55 Correct 50 ms 39560 KB Output is correct
56 Correct 6 ms 33372 KB Output is correct
57 Correct 16 ms 34904 KB Output is correct
58 Correct 10 ms 35420 KB Output is correct
59 Correct 424 ms 81816 KB Output is correct
60 Correct 667 ms 103708 KB Output is correct
61 Correct 694 ms 98900 KB Output is correct
62 Correct 715 ms 98916 KB Output is correct
63 Correct 742 ms 101204 KB Output is correct
64 Correct 762 ms 98896 KB Output is correct
65 Correct 694 ms 98840 KB Output is correct
66 Correct 202 ms 59220 KB Output is correct
67 Correct 666 ms 100968 KB Output is correct
68 Correct 316 ms 112944 KB Output is correct
69 Correct 163 ms 73268 KB Output is correct
70 Correct 390 ms 115432 KB Output is correct
71 Correct 5 ms 32856 KB Output is correct
72 Correct 5 ms 32860 KB Output is correct
73 Correct 4 ms 32860 KB Output is correct
74 Correct 4 ms 32860 KB Output is correct
75 Correct 4 ms 32944 KB Output is correct
76 Correct 5 ms 32856 KB Output is correct
77 Correct 151 ms 87412 KB Output is correct
78 Correct 151 ms 87380 KB Output is correct
79 Correct 166 ms 87348 KB Output is correct
80 Correct 147 ms 87240 KB Output is correct
81 Correct 401 ms 112824 KB Output is correct
82 Correct 426 ms 125872 KB Output is correct
83 Correct 438 ms 126800 KB Output is correct
84 Correct 961 ms 152144 KB Output is correct
85 Correct 998 ms 157008 KB Output is correct
86 Correct 869 ms 145944 KB Output is correct
87 Correct 856 ms 152148 KB Output is correct
88 Correct 5 ms 32856 KB Output is correct
89 Correct 995 ms 152160 KB Output is correct
90 Correct 714 ms 145492 KB Output is correct
91 Correct 737 ms 146552 KB Output is correct