Submission #721341

# Submission time Handle Problem Language Result Execution time Memory
721341 2023-04-10T17:56:00 Z bin9638 Catfish Farm (IOI22_fish) C++17
100 / 100
816 ms 96716 KB
#include <bits/stdc++.h>

#ifndef SKY
#include "fish.h"
#endif // SKY

using namespace std;

#define N 100010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,ll>
#define pb push_back

struct IT
{
    vector<ll>ST;
    int num_node=0;

    void init(int n)
    {
        num_node=n;
        ST.resize(n*4+1,-1e18);
    }

    void update(int id,int l,int r,int i,ll val)
    {
        if(l>i||r<i)
            return;
        if(l==r)
        {
            ST[id]=max(ST[id],val);
            return;
        }
        int mid=(l+r)/2;
        update(id*2,l,mid,i,val);
        update(id*2+1,mid+1,r,i,val);
        ST[id]=max(ST[id*2],ST[id*2+1]);
    }

    void gan(int i,ll val)
    {
        update(1,1,num_node,i,val);
    }

    ll get(int id,int l,int r,int u,int v)
    {
        if(l>v||r<u)
            return -1e18;
        if(l>=u&&r<=v)
            return ST[id];
        int mid=(l+r)/2;
        return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
    }

    ll solve(int u,int v)
    {
        return get(1,1,num_node,u,v);
    }
}T[N][4];

int n,m;
vector<ii>lis[N];
vector<ll>sum[N];
ll ans=0;

ll get_cost(int i,int heigh)
{
    if(lis[i].empty())
        return 0;
    if(heigh<lis[i][0].fs)
        return 0;
    //cout<<i<<" "<<heigh<<" "<<prev(upper_bound(lis[i].begin(),lis[i].end(),ii{heigh,1e18}))-lis[i].begin()<<endl;
    return sum[i][prev(upper_bound(lis[i].begin(),lis[i].end(),ii{heigh,1e18}))-lis[i].begin()];
}

ll max_weights(int nnn, int mmm, vector<int> X, vector<int> Y,vector<int> W)
{
    n=nnn;
    m=mmm;
    for(int i=0;i<m;i++)
    {
        lis[X[i]+1].pb({Y[i]+1,W[i]});
    }
    for(int i=1;i<=n;i++)
    {
        lis[i].pb({n+1,0});
        sort(lis[i].begin(),lis[i].end());
    }
    for(int i=1;i<=n;i++)
    {
        T[i][0].init(lis[i].size());
        T[i][1].init(lis[i].size());
        T[i][2].init(lis[i].size());
        T[i][3].init(lis[i].size());
        sum[i].resize(lis[i].size()+1,0);
        for(int j=0;j<lis[i].size();j++)
            sum[i][j]=(j>0 ? sum[i][j-1] : 0)+lis[i][j].sc;
    }
    for(int j=0;j<lis[1].size();j++)
    {
        T[1][0].gan(j+1,get_cost(2,lis[1][j].fs-1));
        T[1][1].gan(j+1,-get_cost(1,lis[1][j].fs-1));
       // if(j==0)cout<<lis[1][j].fs<<" "<<-get_cost(1,lis[1][j].fs-1)<<endl;
        T[1][2].gan(j+1,get_cost(2,lis[1][j].fs-1));
        T[1][3].gan(j+1,0);
    }
    //cout<<n<<" "<<m<<endl;
  // return 0;
    for(int i=2;i<=n;i++)
        for(int j=0;j<lis[i].size();j++)
        {
           //  cout<<i<<" "<<j<<endl;
            if(lis[i][j].fs<=lis[i-1].back().fs)
            {
                int vt=lower_bound(lis[i-1].begin(),lis[i-1].end(),ii{lis[i][j].fs,0})-lis[i-1].begin()+1;
              //  cout<<vt<<endl;
                ll val=T[i-1][0].solve(vt,lis[i-1].size())-get_cost(i,lis[i][j].fs-1);
                ans=max(ans,val);
              //  cout<<val<<endl;
                T[i][0].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                T[i][2].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                T[i][3].gan(j+1,val);
            }
            if(lis[i][j].fs>=lis[i-1][0].fs)
            {
                int vt=(lis[i][j].fs>=lis[i-1].back().fs ? lis[i-1].size() :
                         prev(upper_bound(lis[i-1].begin(),lis[i-1].end(),ii{lis[i][j].fs,1e18}))-lis[i-1].begin()+1);
                ll val=T[i-1][1].solve(1,vt)+get_cost(i-1,lis[i][j].fs-1);
             //    cout<<val<<" "<<vt<<" "<<T[i-1][1].solve(1,vt)<<endl;
                ans=max(ans,val);
                T[i][0].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                T[i][1].gan(j+1,val-get_cost(i,lis[i][j].fs-1));
                T[i][2].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                T[i][3].gan(j+1,val);
            }
            if(i>2)
            {
                if(lis[i][j].fs<=lis[i-2].back().fs)
                {
                    int vt=lower_bound(lis[i-2].begin(),lis[i-2].end(),ii{lis[i][j].fs,0})-lis[i-2].begin()+1;
                    ll val=T[i-2][2].solve(vt,lis[i-2].size());//-get_cost(i,lis[i][j].fs-1);
                    ans=max(ans,val);
                    T[i][0].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                    T[i][1].gan(j+1,val-get_cost(i,lis[i][j].fs-1));
                    T[i][2].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                    T[i][3].gan(j+1,val);
                }
                if(lis[i][j].fs>=lis[i-2][0].fs)
                {
                    int vt=(lis[i][j].fs>=lis[i-2].back().fs ? lis[i-2].size() :
                            prev(upper_bound(lis[i-2].begin(),lis[i-2].end(),ii{lis[i][j].fs,1e18}))-lis[i-2].begin()+1);
                    ll val=T[i-2][1].solve(1,vt)+get_cost(i-1,lis[i][j].fs-1);
                    ans=max(ans,val);
                    T[i][0].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                    T[i][1].gan(j+1,val-get_cost(i,lis[i][j].fs-1));
                    T[i][2].gan(j+1,val+get_cost(i+1,lis[i][j].fs-1));
                    T[i][3].gan(j+1,val);
                }
            }
        }
    return ans;
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int>X(m),Y(m),W(m);
    for(int i=0;i<m;i++)
        cin>>X[i];//>>Y[i]>>W[i];
          for(int i=0;i<m;i++)
        cin>>Y[i];//>>Y[i]>>W[i];
          for(int i=0;i<m;i++)
        cin>>W[i];//>>Y[i]>>W[i];
    cout<<max_weights(n,m,X,Y,W);
    return 0;
}
#endif

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:98:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(int j=0;j<lis[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
fish.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int j=0;j<lis[1].size();j++)
      |                 ~^~~~~~~~~~~~~~
fish.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for(int j=0;j<lis[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 124 ms 54076 KB Output is correct
2 Correct 151 ms 60272 KB Output is correct
3 Correct 53 ms 42508 KB Output is correct
4 Correct 67 ms 42444 KB Output is correct
5 Correct 425 ms 94736 KB Output is correct
6 Correct 377 ms 96500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 17492 KB Output is correct
2 Correct 276 ms 68104 KB Output is correct
3 Correct 304 ms 77564 KB Output is correct
4 Correct 124 ms 54516 KB Output is correct
5 Correct 141 ms 60224 KB Output is correct
6 Correct 9 ms 17492 KB Output is correct
7 Correct 9 ms 17492 KB Output is correct
8 Correct 10 ms 17452 KB Output is correct
9 Correct 9 ms 17532 KB Output is correct
10 Correct 56 ms 42488 KB Output is correct
11 Correct 49 ms 42436 KB Output is correct
12 Correct 108 ms 54496 KB Output is correct
13 Correct 139 ms 60228 KB Output is correct
14 Correct 120 ms 54400 KB Output is correct
15 Correct 164 ms 58540 KB Output is correct
16 Correct 162 ms 54528 KB Output is correct
17 Correct 160 ms 58504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 42560 KB Output is correct
2 Correct 50 ms 42500 KB Output is correct
3 Correct 101 ms 49064 KB Output is correct
4 Correct 90 ms 48648 KB Output is correct
5 Correct 137 ms 59724 KB Output is correct
6 Correct 135 ms 59616 KB Output is correct
7 Correct 141 ms 59632 KB Output is correct
8 Correct 136 ms 59620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 17492 KB Output is correct
2 Correct 9 ms 17536 KB Output is correct
3 Correct 9 ms 17492 KB Output is correct
4 Correct 11 ms 17492 KB Output is correct
5 Correct 9 ms 17492 KB Output is correct
6 Correct 9 ms 17492 KB Output is correct
7 Correct 9 ms 17464 KB Output is correct
8 Correct 9 ms 17528 KB Output is correct
9 Correct 10 ms 17620 KB Output is correct
10 Correct 11 ms 18004 KB Output is correct
11 Correct 11 ms 17620 KB Output is correct
12 Correct 13 ms 17748 KB Output is correct
13 Correct 10 ms 17528 KB Output is correct
14 Correct 11 ms 17748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 17492 KB Output is correct
2 Correct 9 ms 17536 KB Output is correct
3 Correct 9 ms 17492 KB Output is correct
4 Correct 11 ms 17492 KB Output is correct
5 Correct 9 ms 17492 KB Output is correct
6 Correct 9 ms 17492 KB Output is correct
7 Correct 9 ms 17464 KB Output is correct
8 Correct 9 ms 17528 KB Output is correct
9 Correct 10 ms 17620 KB Output is correct
10 Correct 11 ms 18004 KB Output is correct
11 Correct 11 ms 17620 KB Output is correct
12 Correct 13 ms 17748 KB Output is correct
13 Correct 10 ms 17528 KB Output is correct
14 Correct 11 ms 17748 KB Output is correct
15 Correct 9 ms 17620 KB Output is correct
16 Correct 13 ms 17876 KB Output is correct
17 Correct 110 ms 26032 KB Output is correct
18 Correct 114 ms 26456 KB Output is correct
19 Correct 95 ms 26336 KB Output is correct
20 Correct 98 ms 26300 KB Output is correct
21 Correct 97 ms 26292 KB Output is correct
22 Correct 201 ms 34636 KB Output is correct
23 Correct 26 ms 19356 KB Output is correct
24 Correct 71 ms 23364 KB Output is correct
25 Correct 10 ms 17748 KB Output is correct
26 Correct 22 ms 19176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 17492 KB Output is correct
2 Correct 9 ms 17536 KB Output is correct
3 Correct 9 ms 17492 KB Output is correct
4 Correct 11 ms 17492 KB Output is correct
5 Correct 9 ms 17492 KB Output is correct
6 Correct 9 ms 17492 KB Output is correct
7 Correct 9 ms 17464 KB Output is correct
8 Correct 9 ms 17528 KB Output is correct
9 Correct 10 ms 17620 KB Output is correct
10 Correct 11 ms 18004 KB Output is correct
11 Correct 11 ms 17620 KB Output is correct
12 Correct 13 ms 17748 KB Output is correct
13 Correct 10 ms 17528 KB Output is correct
14 Correct 11 ms 17748 KB Output is correct
15 Correct 9 ms 17620 KB Output is correct
16 Correct 13 ms 17876 KB Output is correct
17 Correct 110 ms 26032 KB Output is correct
18 Correct 114 ms 26456 KB Output is correct
19 Correct 95 ms 26336 KB Output is correct
20 Correct 98 ms 26300 KB Output is correct
21 Correct 97 ms 26292 KB Output is correct
22 Correct 201 ms 34636 KB Output is correct
23 Correct 26 ms 19356 KB Output is correct
24 Correct 71 ms 23364 KB Output is correct
25 Correct 10 ms 17748 KB Output is correct
26 Correct 22 ms 19176 KB Output is correct
27 Correct 12 ms 18780 KB Output is correct
28 Correct 525 ms 57424 KB Output is correct
29 Correct 651 ms 72016 KB Output is correct
30 Correct 629 ms 71816 KB Output is correct
31 Correct 611 ms 71832 KB Output is correct
32 Correct 701 ms 73040 KB Output is correct
33 Correct 643 ms 71700 KB Output is correct
34 Correct 604 ms 71676 KB Output is correct
35 Correct 223 ms 39756 KB Output is correct
36 Correct 698 ms 73152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 42560 KB Output is correct
2 Correct 50 ms 42500 KB Output is correct
3 Correct 101 ms 49064 KB Output is correct
4 Correct 90 ms 48648 KB Output is correct
5 Correct 137 ms 59724 KB Output is correct
6 Correct 135 ms 59616 KB Output is correct
7 Correct 141 ms 59632 KB Output is correct
8 Correct 136 ms 59620 KB Output is correct
9 Correct 140 ms 59572 KB Output is correct
10 Correct 117 ms 48440 KB Output is correct
11 Correct 241 ms 79428 KB Output is correct
12 Correct 9 ms 17528 KB Output is correct
13 Correct 10 ms 17524 KB Output is correct
14 Correct 10 ms 17492 KB Output is correct
15 Correct 9 ms 17524 KB Output is correct
16 Correct 9 ms 17492 KB Output is correct
17 Correct 9 ms 17444 KB Output is correct
18 Correct 60 ms 42480 KB Output is correct
19 Correct 54 ms 42576 KB Output is correct
20 Correct 49 ms 42564 KB Output is correct
21 Correct 49 ms 42560 KB Output is correct
22 Correct 161 ms 60040 KB Output is correct
23 Correct 235 ms 79300 KB Output is correct
24 Correct 224 ms 79308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 54076 KB Output is correct
2 Correct 151 ms 60272 KB Output is correct
3 Correct 53 ms 42508 KB Output is correct
4 Correct 67 ms 42444 KB Output is correct
5 Correct 425 ms 94736 KB Output is correct
6 Correct 377 ms 96500 KB Output is correct
7 Correct 10 ms 17492 KB Output is correct
8 Correct 276 ms 68104 KB Output is correct
9 Correct 304 ms 77564 KB Output is correct
10 Correct 124 ms 54516 KB Output is correct
11 Correct 141 ms 60224 KB Output is correct
12 Correct 9 ms 17492 KB Output is correct
13 Correct 9 ms 17492 KB Output is correct
14 Correct 10 ms 17452 KB Output is correct
15 Correct 9 ms 17532 KB Output is correct
16 Correct 56 ms 42488 KB Output is correct
17 Correct 49 ms 42436 KB Output is correct
18 Correct 108 ms 54496 KB Output is correct
19 Correct 139 ms 60228 KB Output is correct
20 Correct 120 ms 54400 KB Output is correct
21 Correct 164 ms 58540 KB Output is correct
22 Correct 162 ms 54528 KB Output is correct
23 Correct 160 ms 58504 KB Output is correct
24 Correct 52 ms 42560 KB Output is correct
25 Correct 50 ms 42500 KB Output is correct
26 Correct 101 ms 49064 KB Output is correct
27 Correct 90 ms 48648 KB Output is correct
28 Correct 137 ms 59724 KB Output is correct
29 Correct 135 ms 59616 KB Output is correct
30 Correct 141 ms 59632 KB Output is correct
31 Correct 136 ms 59620 KB Output is correct
32 Correct 9 ms 17492 KB Output is correct
33 Correct 9 ms 17536 KB Output is correct
34 Correct 9 ms 17492 KB Output is correct
35 Correct 11 ms 17492 KB Output is correct
36 Correct 9 ms 17492 KB Output is correct
37 Correct 9 ms 17492 KB Output is correct
38 Correct 9 ms 17464 KB Output is correct
39 Correct 9 ms 17528 KB Output is correct
40 Correct 10 ms 17620 KB Output is correct
41 Correct 11 ms 18004 KB Output is correct
42 Correct 11 ms 17620 KB Output is correct
43 Correct 13 ms 17748 KB Output is correct
44 Correct 10 ms 17528 KB Output is correct
45 Correct 11 ms 17748 KB Output is correct
46 Correct 9 ms 17620 KB Output is correct
47 Correct 13 ms 17876 KB Output is correct
48 Correct 110 ms 26032 KB Output is correct
49 Correct 114 ms 26456 KB Output is correct
50 Correct 95 ms 26336 KB Output is correct
51 Correct 98 ms 26300 KB Output is correct
52 Correct 97 ms 26292 KB Output is correct
53 Correct 201 ms 34636 KB Output is correct
54 Correct 26 ms 19356 KB Output is correct
55 Correct 71 ms 23364 KB Output is correct
56 Correct 10 ms 17748 KB Output is correct
57 Correct 22 ms 19176 KB Output is correct
58 Correct 12 ms 18780 KB Output is correct
59 Correct 525 ms 57424 KB Output is correct
60 Correct 651 ms 72016 KB Output is correct
61 Correct 629 ms 71816 KB Output is correct
62 Correct 611 ms 71832 KB Output is correct
63 Correct 701 ms 73040 KB Output is correct
64 Correct 643 ms 71700 KB Output is correct
65 Correct 604 ms 71676 KB Output is correct
66 Correct 223 ms 39756 KB Output is correct
67 Correct 698 ms 73152 KB Output is correct
68 Correct 140 ms 59572 KB Output is correct
69 Correct 117 ms 48440 KB Output is correct
70 Correct 241 ms 79428 KB Output is correct
71 Correct 9 ms 17528 KB Output is correct
72 Correct 10 ms 17524 KB Output is correct
73 Correct 10 ms 17492 KB Output is correct
74 Correct 9 ms 17524 KB Output is correct
75 Correct 9 ms 17492 KB Output is correct
76 Correct 9 ms 17444 KB Output is correct
77 Correct 60 ms 42480 KB Output is correct
78 Correct 54 ms 42576 KB Output is correct
79 Correct 49 ms 42564 KB Output is correct
80 Correct 49 ms 42560 KB Output is correct
81 Correct 161 ms 60040 KB Output is correct
82 Correct 235 ms 79300 KB Output is correct
83 Correct 224 ms 79308 KB Output is correct
84 Correct 816 ms 92696 KB Output is correct
85 Correct 787 ms 95044 KB Output is correct
86 Correct 421 ms 93032 KB Output is correct
87 Correct 435 ms 96044 KB Output is correct
88 Correct 10 ms 17492 KB Output is correct
89 Correct 446 ms 95988 KB Output is correct
90 Correct 487 ms 96476 KB Output is correct
91 Correct 488 ms 96716 KB Output is correct