답안 #1055730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055730 2024-08-13T04:34:13 Z vjudge1 메기 농장 (IOI22_fish) C++17
100 / 100
961 ms 162472 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 262 ms 100196 KB Output is correct
2 Correct 299 ms 111304 KB Output is correct
3 Correct 168 ms 87220 KB Output is correct
4 Correct 178 ms 87380 KB Output is correct
5 Correct 793 ms 157504 KB Output is correct
6 Correct 854 ms 146432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32860 KB Output is correct
2 Correct 476 ms 123548 KB Output is correct
3 Correct 584 ms 139464 KB Output is correct
4 Correct 260 ms 100152 KB Output is correct
5 Correct 280 ms 111300 KB Output is correct
6 Correct 4 ms 32856 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 4 ms 32856 KB Output is correct
9 Correct 4 ms 32860 KB Output is correct
10 Correct 191 ms 87196 KB Output is correct
11 Correct 141 ms 87376 KB Output is correct
12 Correct 276 ms 104880 KB Output is correct
13 Correct 357 ms 115692 KB Output is correct
14 Correct 258 ms 102704 KB Output is correct
15 Correct 304 ms 111456 KB Output is correct
16 Correct 261 ms 102636 KB Output is correct
17 Correct 293 ms 111368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 87352 KB Output is correct
2 Correct 152 ms 87380 KB Output is correct
3 Correct 160 ms 86392 KB Output is correct
4 Correct 189 ms 90576 KB Output is correct
5 Correct 197 ms 95828 KB Output is correct
6 Correct 204 ms 95824 KB Output is correct
7 Correct 220 ms 95824 KB Output is correct
8 Correct 221 ms 95828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32932 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 5 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32852 KB Output is correct
6 Correct 5 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 5 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 6 ms 33372 KB Output is correct
11 Correct 5 ms 33156 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 5 ms 32860 KB Output is correct
14 Correct 5 ms 33148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32932 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 5 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32852 KB Output is correct
6 Correct 5 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 5 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 6 ms 33372 KB Output is correct
11 Correct 5 ms 33156 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 5 ms 32860 KB Output is correct
14 Correct 5 ms 33148 KB Output is correct
15 Correct 5 ms 33116 KB Output is correct
16 Correct 7 ms 33372 KB Output is correct
17 Correct 75 ms 42816 KB Output is correct
18 Correct 74 ms 43088 KB Output is correct
19 Correct 72 ms 43088 KB Output is correct
20 Correct 71 ms 43064 KB Output is correct
21 Correct 69 ms 42828 KB Output is correct
22 Correct 144 ms 53024 KB Output is correct
23 Correct 17 ms 34908 KB Output is correct
24 Correct 48 ms 39564 KB Output is correct
25 Correct 6 ms 33372 KB Output is correct
26 Correct 15 ms 34880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 32932 KB Output is correct
2 Correct 4 ms 32860 KB Output is correct
3 Correct 5 ms 32860 KB Output is correct
4 Correct 4 ms 32860 KB Output is correct
5 Correct 4 ms 32852 KB Output is correct
6 Correct 5 ms 32860 KB Output is correct
7 Correct 4 ms 32860 KB Output is correct
8 Correct 5 ms 32860 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 6 ms 33372 KB Output is correct
11 Correct 5 ms 33156 KB Output is correct
12 Correct 6 ms 33372 KB Output is correct
13 Correct 5 ms 32860 KB Output is correct
14 Correct 5 ms 33148 KB Output is correct
15 Correct 5 ms 33116 KB Output is correct
16 Correct 7 ms 33372 KB Output is correct
17 Correct 75 ms 42816 KB Output is correct
18 Correct 74 ms 43088 KB Output is correct
19 Correct 72 ms 43088 KB Output is correct
20 Correct 71 ms 43064 KB Output is correct
21 Correct 69 ms 42828 KB Output is correct
22 Correct 144 ms 53024 KB Output is correct
23 Correct 17 ms 34908 KB Output is correct
24 Correct 48 ms 39564 KB Output is correct
25 Correct 6 ms 33372 KB Output is correct
26 Correct 15 ms 34880 KB Output is correct
27 Correct 10 ms 35416 KB Output is correct
28 Correct 434 ms 81764 KB Output is correct
29 Correct 636 ms 103544 KB Output is correct
30 Correct 605 ms 98896 KB Output is correct
31 Correct 622 ms 96820 KB Output is correct
32 Correct 585 ms 97108 KB Output is correct
33 Correct 644 ms 94872 KB Output is correct
34 Correct 648 ms 94824 KB Output is correct
35 Correct 193 ms 55120 KB Output is correct
36 Correct 620 ms 97004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 87352 KB Output is correct
2 Correct 152 ms 87380 KB Output is correct
3 Correct 160 ms 86392 KB Output is correct
4 Correct 189 ms 90576 KB Output is correct
5 Correct 197 ms 95828 KB Output is correct
6 Correct 204 ms 95824 KB Output is correct
7 Correct 220 ms 95824 KB Output is correct
8 Correct 221 ms 95828 KB Output is correct
9 Correct 307 ms 112980 KB Output is correct
10 Correct 170 ms 71104 KB Output is correct
11 Correct 386 ms 113472 KB Output is correct
12 Correct 4 ms 28760 KB Output is correct
13 Correct 4 ms 28764 KB Output is correct
14 Correct 4 ms 28764 KB Output is correct
15 Correct 4 ms 28764 KB Output is correct
16 Correct 5 ms 30908 KB Output is correct
17 Correct 4 ms 32860 KB Output is correct
18 Correct 143 ms 87252 KB Output is correct
19 Correct 148 ms 87460 KB Output is correct
20 Correct 146 ms 87320 KB Output is correct
21 Correct 144 ms 87376 KB Output is correct
22 Correct 407 ms 112980 KB Output is correct
23 Correct 422 ms 125696 KB Output is correct
24 Correct 495 ms 126860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 100196 KB Output is correct
2 Correct 299 ms 111304 KB Output is correct
3 Correct 168 ms 87220 KB Output is correct
4 Correct 178 ms 87380 KB Output is correct
5 Correct 793 ms 157504 KB Output is correct
6 Correct 854 ms 146432 KB Output is correct
7 Correct 5 ms 32860 KB Output is correct
8 Correct 476 ms 123548 KB Output is correct
9 Correct 584 ms 139464 KB Output is correct
10 Correct 260 ms 100152 KB Output is correct
11 Correct 280 ms 111300 KB Output is correct
12 Correct 4 ms 32856 KB Output is correct
13 Correct 4 ms 32860 KB Output is correct
14 Correct 4 ms 32856 KB Output is correct
15 Correct 4 ms 32860 KB Output is correct
16 Correct 191 ms 87196 KB Output is correct
17 Correct 141 ms 87376 KB Output is correct
18 Correct 276 ms 104880 KB Output is correct
19 Correct 357 ms 115692 KB Output is correct
20 Correct 258 ms 102704 KB Output is correct
21 Correct 304 ms 111456 KB Output is correct
22 Correct 261 ms 102636 KB Output is correct
23 Correct 293 ms 111368 KB Output is correct
24 Correct 169 ms 87352 KB Output is correct
25 Correct 152 ms 87380 KB Output is correct
26 Correct 160 ms 86392 KB Output is correct
27 Correct 189 ms 90576 KB Output is correct
28 Correct 197 ms 95828 KB Output is correct
29 Correct 204 ms 95824 KB Output is correct
30 Correct 220 ms 95824 KB Output is correct
31 Correct 221 ms 95828 KB Output is correct
32 Correct 5 ms 32932 KB Output is correct
33 Correct 4 ms 32860 KB Output is correct
34 Correct 5 ms 32860 KB Output is correct
35 Correct 4 ms 32860 KB Output is correct
36 Correct 4 ms 32852 KB Output is correct
37 Correct 5 ms 32860 KB Output is correct
38 Correct 4 ms 32860 KB Output is correct
39 Correct 5 ms 32860 KB Output is correct
40 Correct 5 ms 33116 KB Output is correct
41 Correct 6 ms 33372 KB Output is correct
42 Correct 5 ms 33156 KB Output is correct
43 Correct 6 ms 33372 KB Output is correct
44 Correct 5 ms 32860 KB Output is correct
45 Correct 5 ms 33148 KB Output is correct
46 Correct 5 ms 33116 KB Output is correct
47 Correct 7 ms 33372 KB Output is correct
48 Correct 75 ms 42816 KB Output is correct
49 Correct 74 ms 43088 KB Output is correct
50 Correct 72 ms 43088 KB Output is correct
51 Correct 71 ms 43064 KB Output is correct
52 Correct 69 ms 42828 KB Output is correct
53 Correct 144 ms 53024 KB Output is correct
54 Correct 17 ms 34908 KB Output is correct
55 Correct 48 ms 39564 KB Output is correct
56 Correct 6 ms 33372 KB Output is correct
57 Correct 15 ms 34880 KB Output is correct
58 Correct 10 ms 35416 KB Output is correct
59 Correct 434 ms 81764 KB Output is correct
60 Correct 636 ms 103544 KB Output is correct
61 Correct 605 ms 98896 KB Output is correct
62 Correct 622 ms 96820 KB Output is correct
63 Correct 585 ms 97108 KB Output is correct
64 Correct 644 ms 94872 KB Output is correct
65 Correct 648 ms 94824 KB Output is correct
66 Correct 193 ms 55120 KB Output is correct
67 Correct 620 ms 97004 KB Output is correct
68 Correct 307 ms 112980 KB Output is correct
69 Correct 170 ms 71104 KB Output is correct
70 Correct 386 ms 113472 KB Output is correct
71 Correct 4 ms 28760 KB Output is correct
72 Correct 4 ms 28764 KB Output is correct
73 Correct 4 ms 28764 KB Output is correct
74 Correct 4 ms 28764 KB Output is correct
75 Correct 5 ms 30908 KB Output is correct
76 Correct 4 ms 32860 KB Output is correct
77 Correct 143 ms 87252 KB Output is correct
78 Correct 148 ms 87460 KB Output is correct
79 Correct 146 ms 87320 KB Output is correct
80 Correct 144 ms 87376 KB Output is correct
81 Correct 407 ms 112980 KB Output is correct
82 Correct 422 ms 125696 KB Output is correct
83 Correct 495 ms 126860 KB Output is correct
84 Correct 959 ms 152172 KB Output is correct
85 Correct 961 ms 162472 KB Output is correct
86 Correct 823 ms 152148 KB Output is correct
87 Correct 869 ms 158460 KB Output is correct
88 Correct 5 ms 32860 KB Output is correct
89 Correct 874 ms 158436 KB Output is correct
90 Correct 696 ms 151124 KB Output is correct
91 Correct 658 ms 151892 KB Output is correct