Submission #213174

# Submission time Handle Problem Language Result Execution time Memory
213174 2020-03-25T06:43:49 Z HNO2 Bulldozer (JOI17_bulldozer) C++17
100 / 100
882 ms 66604 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=2020;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;

struct segtree
{
    int sum[maxn*4],lmax[maxn*4],rmax[maxn*4],maxx[maxn*4];

    void pull(int now)
    {
        sum[now]=sum[now*2]+sum[now*2+1];
        lmax[now]=max(lmax[now*2],sum[now*2]+lmax[now*2+1]);
        rmax[now]=max(rmax[now*2+1],sum[now*2+1]+rmax[now*2]);
        maxx[now]=max({maxx[now*2],maxx[now*2+1],rmax[now*2]+lmax[now*2+1]});
    }

    void modify(int now,int l,int r,int x,int v)
    {
        if (l==r)
        {
            sum[now]=lmax[now]=rmax[now]=maxx[now]=v;
            return;
        }
        int m=(l+r)>>1;
        if (x<=m) modify(now*2,l,m,x,v);
        else modify(now*2+1,m+1,r,x,v);
        pull(now);
    }

    int query()
    {
        return maxx[1];
    }
}tree;

struct frac
{
    int x,y;
    frac(int _x,int _y)
    {
        if (_x<0) _x=(-_x),_y=(-_y);
        x=_x,y=_y;
    }

    bool operator<(const frac &rhs)const
    {
        return y*rhs.x<x*rhs.y;
    }

    bool operator==(const frac &rhs)const
    {
        return y*rhs.x==x*rhs.y;
    }
};

int X[maxn],Y[maxn],C[maxn];
int p[maxn],att[maxn],c[maxn];

void Swap(int x,int y)
{
    swap(att[p[x]],att[p[y]]);
    swap(c[x],c[y]);
    swap(p[x],p[y]);
    tree.modify(1,1,n,x,c[x]);
    tree.modify(1,1,n,y,c[y]);
}

void rev(int l,int r)
{
    for (int i=l;i<=(l+r-1)/2;i++) Swap(i,l+r-i);
}

int32_t main()
{
    IOS
    vector<int> tmp;
    vector<pair<frac,pii> > v;

    cin>>n;
    for (int i=1;i<=n;i++)
    {
        tmp.pb(i);
        cin>>X[i]>>Y[i]>>C[i];
    }
    sort(all(tmp),[&](int i,int j)
         {
             if (X[i]!=X[j]) return X[i]<X[j];
             else return Y[i]<Y[j];
         });

    for (int i=0;i<n;i++)
    {
        p[i+1]=tmp[i];
        att[p[i+1]]=i+1;
        c[i+1]=C[p[i+1]];
        tree.modify(1,1,n,i+1,C[p[i+1]]);
    }

    for (int i=1;i<=n;i++)
        for (int j=i+1;j<=n;j++)
            if (X[i]!=X[j]) v.pb(mkp(frac(X[j]-X[i],Y[j]-Y[i]),mkp(i,j)));

    sort(all(v));
    reverse(all(v));

    int ans=max(0ll,tree.query());

    while (!v.empty())
    {
        frac last=v.back().F;
        vector<pii> ttmp;

        while (!v.empty()&&v.back().F==last)
            ttmp.pb(mkp(min(att[v.back().S.F],att[v.back().S.S]),max(att[v.back().S.F],att[v.back().S.S])))
                ,v.pop_back();
        sort(all(ttmp));
        reverse(all(ttmp));
        while (!ttmp.empty())
        {
            int tmpl=ttmp.back().F,tmpr=ttmp.back().F;
            while (!ttmp.empty()&&ttmp.back().F==tmpl)
            {
                tmpr++;
                ttmp.pop_back();
            }
            while (!ttmp.empty()&&ttmp.back().S<=tmpr) ttmp.pop_back();
            rev(tmpl,tmpr);
        }

        ans=max(ans,tree.query());
    }

    cout<<ans<<endl;
}


# Verdict Execution time Memory Grader output
1 Correct 6 ms 644 KB Output is correct
2 Correct 6 ms 644 KB Output is correct
3 Correct 6 ms 772 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 6 ms 772 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 6 ms 772 KB Output is correct
8 Correct 6 ms 772 KB Output is correct
9 Correct 6 ms 772 KB Output is correct
10 Correct 6 ms 772 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 772 KB Output is correct
2 Correct 6 ms 772 KB Output is correct
3 Correct 6 ms 772 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 6 ms 772 KB Output is correct
8 Correct 6 ms 772 KB Output is correct
9 Correct 6 ms 772 KB Output is correct
10 Correct 6 ms 772 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 772 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 772 KB Output is correct
24 Correct 6 ms 772 KB Output is correct
25 Correct 6 ms 772 KB Output is correct
26 Correct 6 ms 772 KB Output is correct
27 Correct 6 ms 772 KB Output is correct
28 Correct 6 ms 772 KB Output is correct
29 Correct 6 ms 772 KB Output is correct
30 Correct 6 ms 772 KB Output is correct
31 Correct 6 ms 772 KB Output is correct
32 Correct 6 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 772 KB Output is correct
2 Correct 6 ms 772 KB Output is correct
3 Correct 6 ms 772 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 6 ms 772 KB Output is correct
8 Correct 6 ms 772 KB Output is correct
9 Correct 6 ms 772 KB Output is correct
10 Correct 6 ms 772 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 772 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 772 KB Output is correct
24 Correct 6 ms 772 KB Output is correct
25 Correct 6 ms 772 KB Output is correct
26 Correct 6 ms 772 KB Output is correct
27 Correct 6 ms 772 KB Output is correct
28 Correct 6 ms 772 KB Output is correct
29 Correct 6 ms 772 KB Output is correct
30 Correct 6 ms 772 KB Output is correct
31 Correct 6 ms 772 KB Output is correct
32 Correct 6 ms 772 KB Output is correct
33 Correct 852 ms 66508 KB Output is correct
34 Correct 862 ms 66476 KB Output is correct
35 Correct 853 ms 66508 KB Output is correct
36 Correct 858 ms 66480 KB Output is correct
37 Correct 860 ms 66508 KB Output is correct
38 Correct 861 ms 66508 KB Output is correct
39 Correct 864 ms 66508 KB Output is correct
40 Correct 860 ms 66508 KB Output is correct
41 Correct 859 ms 66476 KB Output is correct
42 Correct 849 ms 66508 KB Output is correct
43 Correct 848 ms 66508 KB Output is correct
44 Correct 846 ms 66540 KB Output is correct
45 Correct 842 ms 66508 KB Output is correct
46 Correct 836 ms 66508 KB Output is correct
47 Correct 843 ms 66508 KB Output is correct
48 Correct 840 ms 66476 KB Output is correct
49 Correct 841 ms 66476 KB Output is correct
50 Correct 839 ms 66476 KB Output is correct
51 Correct 850 ms 66604 KB Output is correct
52 Correct 840 ms 66476 KB Output is correct
53 Correct 843 ms 66508 KB Output is correct
54 Correct 845 ms 66476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 772 KB Output is correct
2 Correct 6 ms 772 KB Output is correct
3 Correct 6 ms 772 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 6 ms 772 KB Output is correct
8 Correct 6 ms 772 KB Output is correct
9 Correct 6 ms 772 KB Output is correct
10 Correct 6 ms 772 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 772 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 7 ms 772 KB Output is correct
24 Correct 6 ms 772 KB Output is correct
25 Correct 6 ms 772 KB Output is correct
26 Correct 6 ms 772 KB Output is correct
27 Correct 6 ms 772 KB Output is correct
28 Correct 6 ms 772 KB Output is correct
29 Correct 6 ms 772 KB Output is correct
30 Correct 6 ms 772 KB Output is correct
31 Correct 6 ms 772 KB Output is correct
32 Correct 6 ms 772 KB Output is correct
33 Correct 852 ms 66508 KB Output is correct
34 Correct 862 ms 66476 KB Output is correct
35 Correct 853 ms 66508 KB Output is correct
36 Correct 858 ms 66480 KB Output is correct
37 Correct 860 ms 66508 KB Output is correct
38 Correct 861 ms 66508 KB Output is correct
39 Correct 864 ms 66508 KB Output is correct
40 Correct 860 ms 66508 KB Output is correct
41 Correct 859 ms 66476 KB Output is correct
42 Correct 849 ms 66508 KB Output is correct
43 Correct 848 ms 66508 KB Output is correct
44 Correct 846 ms 66540 KB Output is correct
45 Correct 842 ms 66508 KB Output is correct
46 Correct 836 ms 66508 KB Output is correct
47 Correct 843 ms 66508 KB Output is correct
48 Correct 840 ms 66476 KB Output is correct
49 Correct 841 ms 66476 KB Output is correct
50 Correct 839 ms 66476 KB Output is correct
51 Correct 850 ms 66604 KB Output is correct
52 Correct 840 ms 66476 KB Output is correct
53 Correct 843 ms 66508 KB Output is correct
54 Correct 845 ms 66476 KB Output is correct
55 Correct 857 ms 66476 KB Output is correct
56 Correct 856 ms 66476 KB Output is correct
57 Correct 851 ms 66508 KB Output is correct
58 Correct 853 ms 66476 KB Output is correct
59 Correct 869 ms 66476 KB Output is correct
60 Correct 859 ms 66476 KB Output is correct
61 Correct 867 ms 66520 KB Output is correct
62 Correct 862 ms 66484 KB Output is correct
63 Correct 859 ms 66476 KB Output is correct
64 Correct 855 ms 66476 KB Output is correct
65 Correct 872 ms 66480 KB Output is correct
66 Correct 853 ms 66472 KB Output is correct
67 Correct 867 ms 66508 KB Output is correct
68 Correct 856 ms 66476 KB Output is correct
69 Correct 872 ms 66508 KB Output is correct
70 Correct 861 ms 66480 KB Output is correct
71 Correct 863 ms 66348 KB Output is correct
72 Correct 853 ms 66480 KB Output is correct
73 Correct 857 ms 66476 KB Output is correct
74 Correct 859 ms 66480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 644 KB Output is correct
2 Correct 6 ms 644 KB Output is correct
3 Correct 6 ms 772 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 6 ms 772 KB Output is correct
6 Correct 6 ms 772 KB Output is correct
7 Correct 6 ms 772 KB Output is correct
8 Correct 6 ms 772 KB Output is correct
9 Correct 6 ms 772 KB Output is correct
10 Correct 6 ms 772 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 6 ms 772 KB Output is correct
17 Correct 6 ms 772 KB Output is correct
18 Correct 6 ms 772 KB Output is correct
19 Correct 6 ms 772 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 6 ms 772 KB Output is correct
22 Correct 6 ms 772 KB Output is correct
23 Correct 6 ms 772 KB Output is correct
24 Correct 6 ms 772 KB Output is correct
25 Correct 6 ms 772 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 772 KB Output is correct
37 Correct 6 ms 768 KB Output is correct
38 Correct 7 ms 772 KB Output is correct
39 Correct 6 ms 772 KB Output is correct
40 Correct 6 ms 772 KB Output is correct
41 Correct 6 ms 772 KB Output is correct
42 Correct 6 ms 772 KB Output is correct
43 Correct 6 ms 772 KB Output is correct
44 Correct 6 ms 772 KB Output is correct
45 Correct 6 ms 772 KB Output is correct
46 Correct 6 ms 772 KB Output is correct
47 Correct 6 ms 772 KB Output is correct
48 Correct 852 ms 66508 KB Output is correct
49 Correct 862 ms 66476 KB Output is correct
50 Correct 853 ms 66508 KB Output is correct
51 Correct 858 ms 66480 KB Output is correct
52 Correct 860 ms 66508 KB Output is correct
53 Correct 861 ms 66508 KB Output is correct
54 Correct 864 ms 66508 KB Output is correct
55 Correct 860 ms 66508 KB Output is correct
56 Correct 859 ms 66476 KB Output is correct
57 Correct 849 ms 66508 KB Output is correct
58 Correct 848 ms 66508 KB Output is correct
59 Correct 846 ms 66540 KB Output is correct
60 Correct 842 ms 66508 KB Output is correct
61 Correct 836 ms 66508 KB Output is correct
62 Correct 843 ms 66508 KB Output is correct
63 Correct 840 ms 66476 KB Output is correct
64 Correct 841 ms 66476 KB Output is correct
65 Correct 839 ms 66476 KB Output is correct
66 Correct 850 ms 66604 KB Output is correct
67 Correct 840 ms 66476 KB Output is correct
68 Correct 843 ms 66508 KB Output is correct
69 Correct 845 ms 66476 KB Output is correct
70 Correct 857 ms 66476 KB Output is correct
71 Correct 856 ms 66476 KB Output is correct
72 Correct 851 ms 66508 KB Output is correct
73 Correct 853 ms 66476 KB Output is correct
74 Correct 869 ms 66476 KB Output is correct
75 Correct 859 ms 66476 KB Output is correct
76 Correct 867 ms 66520 KB Output is correct
77 Correct 862 ms 66484 KB Output is correct
78 Correct 859 ms 66476 KB Output is correct
79 Correct 855 ms 66476 KB Output is correct
80 Correct 872 ms 66480 KB Output is correct
81 Correct 853 ms 66472 KB Output is correct
82 Correct 867 ms 66508 KB Output is correct
83 Correct 856 ms 66476 KB Output is correct
84 Correct 872 ms 66508 KB Output is correct
85 Correct 861 ms 66480 KB Output is correct
86 Correct 863 ms 66348 KB Output is correct
87 Correct 853 ms 66480 KB Output is correct
88 Correct 857 ms 66476 KB Output is correct
89 Correct 859 ms 66480 KB Output is correct
90 Correct 857 ms 66476 KB Output is correct
91 Correct 866 ms 66512 KB Output is correct
92 Correct 858 ms 66476 KB Output is correct
93 Correct 857 ms 66508 KB Output is correct
94 Correct 855 ms 66508 KB Output is correct
95 Correct 850 ms 66512 KB Output is correct
96 Correct 853 ms 66508 KB Output is correct
97 Correct 867 ms 66476 KB Output is correct
98 Correct 851 ms 66508 KB Output is correct
99 Correct 862 ms 66508 KB Output is correct
100 Correct 416 ms 33648 KB Output is correct
101 Correct 419 ms 33656 KB Output is correct
102 Correct 415 ms 33648 KB Output is correct
103 Correct 426 ms 33648 KB Output is correct
104 Correct 427 ms 33648 KB Output is correct
105 Correct 578 ms 66476 KB Output is correct
106 Correct 588 ms 66476 KB Output is correct
107 Correct 574 ms 66480 KB Output is correct
108 Correct 576 ms 66476 KB Output is correct
109 Correct 582 ms 66476 KB Output is correct
110 Correct 705 ms 66476 KB Output is correct
111 Correct 706 ms 66508 KB Output is correct
112 Correct 702 ms 66508 KB Output is correct
113 Correct 708 ms 66476 KB Output is correct
114 Correct 702 ms 66476 KB Output is correct
115 Correct 698 ms 66476 KB Output is correct
116 Correct 706 ms 66476 KB Output is correct
117 Correct 703 ms 66476 KB Output is correct
118 Correct 718 ms 66476 KB Output is correct
119 Correct 702 ms 66472 KB Output is correct
120 Correct 5 ms 384 KB Output is correct
121 Correct 5 ms 384 KB Output is correct
122 Correct 882 ms 66508 KB Output is correct
123 Correct 878 ms 66512 KB Output is correct
124 Correct 879 ms 66504 KB Output is correct
125 Correct 862 ms 66508 KB Output is correct
126 Correct 877 ms 66476 KB Output is correct
127 Correct 871 ms 66508 KB Output is correct
128 Correct 869 ms 66476 KB Output is correct
129 Correct 867 ms 66508 KB Output is correct
130 Correct 872 ms 66476 KB Output is correct
131 Correct 858 ms 66476 KB Output is correct
132 Correct 853 ms 66512 KB Output is correct
133 Correct 870 ms 66508 KB Output is correct