답안 #1055725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055725 2024-08-13T04:31:43 Z vjudge1 메기 농장 (IOI22_fish) C++17
84 / 100
1000 ms 150612 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){
        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];
        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 250 ms 90628 KB Output is correct
2 Correct 291 ms 100716 KB Output is correct
3 Correct 123 ms 69972 KB Output is correct
4 Correct 123 ms 70000 KB Output is correct
5 Correct 950 ms 150612 KB Output is correct
6 Correct 809 ms 147772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31372 KB Output is correct
2 Correct 550 ms 117804 KB Output is correct
3 Correct 652 ms 132684 KB Output is correct
4 Correct 240 ms 90640 KB Output is correct
5 Correct 290 ms 100692 KB Output is correct
6 Correct 3 ms 31320 KB Output is correct
7 Correct 3 ms 31408 KB Output is correct
8 Correct 3 ms 31324 KB Output is correct
9 Correct 3 ms 31324 KB Output is correct
10 Correct 129 ms 70144 KB Output is correct
11 Correct 122 ms 70000 KB Output is correct
12 Correct 314 ms 93008 KB Output is correct
13 Correct 368 ms 101840 KB Output is correct
14 Correct 275 ms 91984 KB Output is correct
15 Correct 326 ms 98640 KB Output is correct
16 Correct 273 ms 91984 KB Output is correct
17 Correct 316 ms 97444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 69968 KB Output is correct
2 Correct 126 ms 69972 KB Output is correct
3 Correct 139 ms 70484 KB Output is correct
4 Correct 143 ms 73268 KB Output is correct
5 Correct 179 ms 78596 KB Output is correct
6 Correct 193 ms 78680 KB Output is correct
7 Correct 184 ms 78672 KB Output is correct
8 Correct 177 ms 78772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31324 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 4 ms 31320 KB Output is correct
4 Correct 3 ms 31324 KB Output is correct
5 Correct 3 ms 31324 KB Output is correct
6 Correct 3 ms 31324 KB Output is correct
7 Correct 3 ms 31320 KB Output is correct
8 Correct 3 ms 31372 KB Output is correct
9 Correct 3 ms 31352 KB Output is correct
10 Correct 5 ms 32092 KB Output is correct
11 Correct 4 ms 31580 KB Output is correct
12 Correct 4 ms 31820 KB Output is correct
13 Correct 3 ms 31324 KB Output is correct
14 Correct 5 ms 31544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31324 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 4 ms 31320 KB Output is correct
4 Correct 3 ms 31324 KB Output is correct
5 Correct 3 ms 31324 KB Output is correct
6 Correct 3 ms 31324 KB Output is correct
7 Correct 3 ms 31320 KB Output is correct
8 Correct 3 ms 31372 KB Output is correct
9 Correct 3 ms 31352 KB Output is correct
10 Correct 5 ms 32092 KB Output is correct
11 Correct 4 ms 31580 KB Output is correct
12 Correct 4 ms 31820 KB Output is correct
13 Correct 3 ms 31324 KB Output is correct
14 Correct 5 ms 31544 KB Output is correct
15 Correct 4 ms 31576 KB Output is correct
16 Correct 6 ms 31836 KB Output is correct
17 Correct 85 ms 43132 KB Output is correct
18 Correct 90 ms 43072 KB Output is correct
19 Correct 82 ms 43092 KB Output is correct
20 Correct 78 ms 42956 KB Output is correct
21 Correct 78 ms 43092 KB Output is correct
22 Correct 186 ms 54616 KB Output is correct
23 Correct 19 ms 33628 KB Output is correct
24 Correct 62 ms 39248 KB Output is correct
25 Correct 5 ms 31576 KB Output is correct
26 Correct 15 ms 33664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 31324 KB Output is correct
2 Correct 4 ms 31324 KB Output is correct
3 Correct 4 ms 31320 KB Output is correct
4 Correct 3 ms 31324 KB Output is correct
5 Correct 3 ms 31324 KB Output is correct
6 Correct 3 ms 31324 KB Output is correct
7 Correct 3 ms 31320 KB Output is correct
8 Correct 3 ms 31372 KB Output is correct
9 Correct 3 ms 31352 KB Output is correct
10 Correct 5 ms 32092 KB Output is correct
11 Correct 4 ms 31580 KB Output is correct
12 Correct 4 ms 31820 KB Output is correct
13 Correct 3 ms 31324 KB Output is correct
14 Correct 5 ms 31544 KB Output is correct
15 Correct 4 ms 31576 KB Output is correct
16 Correct 6 ms 31836 KB Output is correct
17 Correct 85 ms 43132 KB Output is correct
18 Correct 90 ms 43072 KB Output is correct
19 Correct 82 ms 43092 KB Output is correct
20 Correct 78 ms 42956 KB Output is correct
21 Correct 78 ms 43092 KB Output is correct
22 Correct 186 ms 54616 KB Output is correct
23 Correct 19 ms 33628 KB Output is correct
24 Correct 62 ms 39248 KB Output is correct
25 Correct 5 ms 31576 KB Output is correct
26 Correct 15 ms 33664 KB Output is correct
27 Correct 9 ms 33372 KB Output is correct
28 Correct 492 ms 87420 KB Output is correct
29 Correct 740 ms 110412 KB Output is correct
30 Correct 645 ms 110160 KB Output is correct
31 Correct 665 ms 110164 KB Output is correct
32 Correct 665 ms 108884 KB Output is correct
33 Correct 684 ms 110156 KB Output is correct
34 Correct 675 ms 110156 KB Output is correct
35 Correct 203 ms 62252 KB Output is correct
36 Correct 690 ms 110100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 69968 KB Output is correct
2 Correct 126 ms 69972 KB Output is correct
3 Correct 139 ms 70484 KB Output is correct
4 Correct 143 ms 73268 KB Output is correct
5 Correct 179 ms 78596 KB Output is correct
6 Correct 193 ms 78680 KB Output is correct
7 Correct 184 ms 78672 KB Output is correct
8 Correct 177 ms 78772 KB Output is correct
9 Correct 265 ms 101968 KB Output is correct
10 Correct 144 ms 66900 KB Output is correct
11 Correct 317 ms 104532 KB Output is correct
12 Correct 4 ms 31324 KB Output is correct
13 Correct 4 ms 31324 KB Output is correct
14 Correct 3 ms 31324 KB Output is correct
15 Correct 3 ms 31324 KB Output is correct
16 Correct 3 ms 31324 KB Output is correct
17 Correct 3 ms 31340 KB Output is correct
18 Correct 139 ms 69976 KB Output is correct
19 Correct 125 ms 70044 KB Output is correct
20 Correct 129 ms 69968 KB Output is correct
21 Correct 122 ms 70380 KB Output is correct
22 Correct 373 ms 101872 KB Output is correct
23 Correct 395 ms 120548 KB Output is correct
24 Correct 425 ms 121936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 90628 KB Output is correct
2 Correct 291 ms 100716 KB Output is correct
3 Correct 123 ms 69972 KB Output is correct
4 Correct 123 ms 70000 KB Output is correct
5 Correct 950 ms 150612 KB Output is correct
6 Correct 809 ms 147772 KB Output is correct
7 Correct 4 ms 31372 KB Output is correct
8 Correct 550 ms 117804 KB Output is correct
9 Correct 652 ms 132684 KB Output is correct
10 Correct 240 ms 90640 KB Output is correct
11 Correct 290 ms 100692 KB Output is correct
12 Correct 3 ms 31320 KB Output is correct
13 Correct 3 ms 31408 KB Output is correct
14 Correct 3 ms 31324 KB Output is correct
15 Correct 3 ms 31324 KB Output is correct
16 Correct 129 ms 70144 KB Output is correct
17 Correct 122 ms 70000 KB Output is correct
18 Correct 314 ms 93008 KB Output is correct
19 Correct 368 ms 101840 KB Output is correct
20 Correct 275 ms 91984 KB Output is correct
21 Correct 326 ms 98640 KB Output is correct
22 Correct 273 ms 91984 KB Output is correct
23 Correct 316 ms 97444 KB Output is correct
24 Correct 122 ms 69968 KB Output is correct
25 Correct 126 ms 69972 KB Output is correct
26 Correct 139 ms 70484 KB Output is correct
27 Correct 143 ms 73268 KB Output is correct
28 Correct 179 ms 78596 KB Output is correct
29 Correct 193 ms 78680 KB Output is correct
30 Correct 184 ms 78672 KB Output is correct
31 Correct 177 ms 78772 KB Output is correct
32 Correct 4 ms 31324 KB Output is correct
33 Correct 4 ms 31324 KB Output is correct
34 Correct 4 ms 31320 KB Output is correct
35 Correct 3 ms 31324 KB Output is correct
36 Correct 3 ms 31324 KB Output is correct
37 Correct 3 ms 31324 KB Output is correct
38 Correct 3 ms 31320 KB Output is correct
39 Correct 3 ms 31372 KB Output is correct
40 Correct 3 ms 31352 KB Output is correct
41 Correct 5 ms 32092 KB Output is correct
42 Correct 4 ms 31580 KB Output is correct
43 Correct 4 ms 31820 KB Output is correct
44 Correct 3 ms 31324 KB Output is correct
45 Correct 5 ms 31544 KB Output is correct
46 Correct 4 ms 31576 KB Output is correct
47 Correct 6 ms 31836 KB Output is correct
48 Correct 85 ms 43132 KB Output is correct
49 Correct 90 ms 43072 KB Output is correct
50 Correct 82 ms 43092 KB Output is correct
51 Correct 78 ms 42956 KB Output is correct
52 Correct 78 ms 43092 KB Output is correct
53 Correct 186 ms 54616 KB Output is correct
54 Correct 19 ms 33628 KB Output is correct
55 Correct 62 ms 39248 KB Output is correct
56 Correct 5 ms 31576 KB Output is correct
57 Correct 15 ms 33664 KB Output is correct
58 Correct 9 ms 33372 KB Output is correct
59 Correct 492 ms 87420 KB Output is correct
60 Correct 740 ms 110412 KB Output is correct
61 Correct 645 ms 110160 KB Output is correct
62 Correct 665 ms 110164 KB Output is correct
63 Correct 665 ms 108884 KB Output is correct
64 Correct 684 ms 110156 KB Output is correct
65 Correct 675 ms 110156 KB Output is correct
66 Correct 203 ms 62252 KB Output is correct
67 Correct 690 ms 110100 KB Output is correct
68 Correct 265 ms 101968 KB Output is correct
69 Correct 144 ms 66900 KB Output is correct
70 Correct 317 ms 104532 KB Output is correct
71 Correct 4 ms 31324 KB Output is correct
72 Correct 4 ms 31324 KB Output is correct
73 Correct 3 ms 31324 KB Output is correct
74 Correct 3 ms 31324 KB Output is correct
75 Correct 3 ms 31324 KB Output is correct
76 Correct 3 ms 31340 KB Output is correct
77 Correct 139 ms 69976 KB Output is correct
78 Correct 125 ms 70044 KB Output is correct
79 Correct 129 ms 69968 KB Output is correct
80 Correct 122 ms 70380 KB Output is correct
81 Correct 373 ms 101872 KB Output is correct
82 Correct 395 ms 120548 KB Output is correct
83 Correct 425 ms 121936 KB Output is correct
84 Execution timed out 1036 ms 149556 KB Time limit exceeded
85 Halted 0 ms 0 KB -