답안 #1055720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055720 2024-08-13T04:27:54 Z vjudge1 메기 농장 (IOI22_fish) C++17
84 / 100
1000 ms 156980 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<int>fishies[100010];
map<int,ll>fishiess[100010];
map<int,ll>dp[100010][2];
int N;
inline ll ones(int col,int len){
    auto it=fishiess[col].upper_bound(len);
    if(it==fishiess[col].begin())return 0;
    return (--it)->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){
        T[i]=max(T[i],x);if(l==r)return;
        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);
    }
};
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,dp[i][0][j]);
            Third.upd(1,0,N,j,dp[i][1][j]-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];
        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);
    fishies[N+1].insert(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:19:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |         return max(query(i*2,l,l+r>>1,ll,rr),
      |                                ~^~
fish.cpp:20:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |                 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:24:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |            ~^~
fish.cpp:24:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |                                ~^~
fish.cpp:25:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         else upd(i*2+1,l+r+2>>1,r,p,x);
      |                        ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 92248 KB Output is correct
2 Correct 300 ms 102404 KB Output is correct
3 Correct 132 ms 64156 KB Output is correct
4 Correct 134 ms 64084 KB Output is correct
5 Correct 966 ms 156980 KB Output is correct
6 Correct 819 ms 154416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 534 ms 120664 KB Output is correct
3 Correct 672 ms 136272 KB Output is correct
4 Correct 254 ms 92244 KB Output is correct
5 Correct 293 ms 102480 KB Output is correct
6 Correct 3 ms 23132 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 124 ms 63928 KB Output is correct
11 Correct 129 ms 63912 KB Output is correct
12 Correct 306 ms 88400 KB Output is correct
13 Correct 397 ms 97676 KB Output is correct
14 Correct 293 ms 90448 KB Output is correct
15 Correct 321 ms 97268 KB Output is correct
16 Correct 279 ms 90564 KB Output is correct
17 Correct 323 ms 97108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 63972 KB Output is correct
2 Correct 128 ms 63976 KB Output is correct
3 Correct 139 ms 65408 KB Output is correct
4 Correct 138 ms 67664 KB Output is correct
5 Correct 181 ms 74264 KB Output is correct
6 Correct 174 ms 73552 KB Output is correct
7 Correct 185 ms 74320 KB Output is correct
8 Correct 194 ms 74324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 23132 KB Output is correct
3 Correct 2 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 2 ms 23184 KB Output is correct
6 Correct 3 ms 23128 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 2 ms 23184 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 3 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 5 ms 23384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 23132 KB Output is correct
3 Correct 2 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 2 ms 23184 KB Output is correct
6 Correct 3 ms 23128 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 2 ms 23184 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 3 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 5 ms 23384 KB Output is correct
15 Correct 4 ms 23388 KB Output is correct
16 Correct 6 ms 23680 KB Output is correct
17 Correct 108 ms 35924 KB Output is correct
18 Correct 84 ms 35648 KB Output is correct
19 Correct 78 ms 35668 KB Output is correct
20 Correct 79 ms 35640 KB Output is correct
21 Correct 81 ms 35668 KB Output is correct
22 Correct 188 ms 48100 KB Output is correct
23 Correct 17 ms 25692 KB Output is correct
24 Correct 55 ms 31472 KB Output is correct
25 Correct 4 ms 23644 KB Output is correct
26 Correct 17 ms 25692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 23132 KB Output is correct
3 Correct 2 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 2 ms 23184 KB Output is correct
6 Correct 3 ms 23128 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 2 ms 23184 KB Output is correct
9 Correct 3 ms 23388 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 3 ms 23388 KB Output is correct
12 Correct 4 ms 23644 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 5 ms 23384 KB Output is correct
15 Correct 4 ms 23388 KB Output is correct
16 Correct 6 ms 23680 KB Output is correct
17 Correct 108 ms 35924 KB Output is correct
18 Correct 84 ms 35648 KB Output is correct
19 Correct 78 ms 35668 KB Output is correct
20 Correct 79 ms 35640 KB Output is correct
21 Correct 81 ms 35668 KB Output is correct
22 Correct 188 ms 48100 KB Output is correct
23 Correct 17 ms 25692 KB Output is correct
24 Correct 55 ms 31472 KB Output is correct
25 Correct 4 ms 23644 KB Output is correct
26 Correct 17 ms 25692 KB Output is correct
27 Correct 8 ms 25692 KB Output is correct
28 Correct 484 ms 82840 KB Output is correct
29 Correct 726 ms 107740 KB Output is correct
30 Correct 661 ms 107604 KB Output is correct
31 Correct 647 ms 107532 KB Output is correct
32 Correct 673 ms 105556 KB Output is correct
33 Correct 681 ms 107668 KB Output is correct
34 Correct 677 ms 107548 KB Output is correct
35 Correct 196 ms 56148 KB Output is correct
36 Correct 700 ms 107604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 63972 KB Output is correct
2 Correct 128 ms 63976 KB Output is correct
3 Correct 139 ms 65408 KB Output is correct
4 Correct 138 ms 67664 KB Output is correct
5 Correct 181 ms 74264 KB Output is correct
6 Correct 174 ms 73552 KB Output is correct
7 Correct 185 ms 74320 KB Output is correct
8 Correct 194 ms 74324 KB Output is correct
9 Correct 240 ms 103464 KB Output is correct
10 Correct 139 ms 62548 KB Output is correct
11 Correct 349 ms 101972 KB Output is correct
12 Correct 3 ms 23132 KB Output is correct
13 Correct 2 ms 23132 KB Output is correct
14 Correct 3 ms 23132 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 3 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 122 ms 64156 KB Output is correct
19 Correct 127 ms 63968 KB Output is correct
20 Correct 124 ms 64080 KB Output is correct
21 Correct 125 ms 63936 KB Output is correct
22 Correct 337 ms 104020 KB Output is correct
23 Correct 454 ms 118444 KB Output is correct
24 Correct 396 ms 120400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 92248 KB Output is correct
2 Correct 300 ms 102404 KB Output is correct
3 Correct 132 ms 64156 KB Output is correct
4 Correct 134 ms 64084 KB Output is correct
5 Correct 966 ms 156980 KB Output is correct
6 Correct 819 ms 154416 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 534 ms 120664 KB Output is correct
9 Correct 672 ms 136272 KB Output is correct
10 Correct 254 ms 92244 KB Output is correct
11 Correct 293 ms 102480 KB Output is correct
12 Correct 3 ms 23132 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 124 ms 63928 KB Output is correct
17 Correct 129 ms 63912 KB Output is correct
18 Correct 306 ms 88400 KB Output is correct
19 Correct 397 ms 97676 KB Output is correct
20 Correct 293 ms 90448 KB Output is correct
21 Correct 321 ms 97268 KB Output is correct
22 Correct 279 ms 90564 KB Output is correct
23 Correct 323 ms 97108 KB Output is correct
24 Correct 126 ms 63972 KB Output is correct
25 Correct 128 ms 63976 KB Output is correct
26 Correct 139 ms 65408 KB Output is correct
27 Correct 138 ms 67664 KB Output is correct
28 Correct 181 ms 74264 KB Output is correct
29 Correct 174 ms 73552 KB Output is correct
30 Correct 185 ms 74320 KB Output is correct
31 Correct 194 ms 74324 KB Output is correct
32 Correct 3 ms 23132 KB Output is correct
33 Correct 3 ms 23132 KB Output is correct
34 Correct 2 ms 23132 KB Output is correct
35 Correct 3 ms 23132 KB Output is correct
36 Correct 2 ms 23184 KB Output is correct
37 Correct 3 ms 23128 KB Output is correct
38 Correct 3 ms 23132 KB Output is correct
39 Correct 2 ms 23184 KB Output is correct
40 Correct 3 ms 23388 KB Output is correct
41 Correct 5 ms 23896 KB Output is correct
42 Correct 3 ms 23388 KB Output is correct
43 Correct 4 ms 23644 KB Output is correct
44 Correct 3 ms 23132 KB Output is correct
45 Correct 5 ms 23384 KB Output is correct
46 Correct 4 ms 23388 KB Output is correct
47 Correct 6 ms 23680 KB Output is correct
48 Correct 108 ms 35924 KB Output is correct
49 Correct 84 ms 35648 KB Output is correct
50 Correct 78 ms 35668 KB Output is correct
51 Correct 79 ms 35640 KB Output is correct
52 Correct 81 ms 35668 KB Output is correct
53 Correct 188 ms 48100 KB Output is correct
54 Correct 17 ms 25692 KB Output is correct
55 Correct 55 ms 31472 KB Output is correct
56 Correct 4 ms 23644 KB Output is correct
57 Correct 17 ms 25692 KB Output is correct
58 Correct 8 ms 25692 KB Output is correct
59 Correct 484 ms 82840 KB Output is correct
60 Correct 726 ms 107740 KB Output is correct
61 Correct 661 ms 107604 KB Output is correct
62 Correct 647 ms 107532 KB Output is correct
63 Correct 673 ms 105556 KB Output is correct
64 Correct 681 ms 107668 KB Output is correct
65 Correct 677 ms 107548 KB Output is correct
66 Correct 196 ms 56148 KB Output is correct
67 Correct 700 ms 107604 KB Output is correct
68 Correct 240 ms 103464 KB Output is correct
69 Correct 139 ms 62548 KB Output is correct
70 Correct 349 ms 101972 KB Output is correct
71 Correct 3 ms 23132 KB Output is correct
72 Correct 2 ms 23132 KB Output is correct
73 Correct 3 ms 23132 KB Output is correct
74 Correct 3 ms 23132 KB Output is correct
75 Correct 3 ms 23132 KB Output is correct
76 Correct 3 ms 23132 KB Output is correct
77 Correct 122 ms 64156 KB Output is correct
78 Correct 127 ms 63968 KB Output is correct
79 Correct 124 ms 64080 KB Output is correct
80 Correct 125 ms 63936 KB Output is correct
81 Correct 337 ms 104020 KB Output is correct
82 Correct 454 ms 118444 KB Output is correct
83 Correct 396 ms 120400 KB Output is correct
84 Execution timed out 1050 ms 154708 KB Time limit exceeded
85 Halted 0 ms 0 KB -