Submission #777307

# Submission time Handle Problem Language Result Execution time Memory
777307 2023-07-09T03:37:28 Z bachhoangxuan Bulldozer (JOI17_bulldozer) C++17
100 / 100
669 ms 63280 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=1e9+7;
const int maxn=2005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=250000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;
struct point{
    int x,y,w;
    bool operator<(point o){
        if(x!=o.x) return x<o.x;
        else return y<o.y;
    }
}p[maxn];
struct line{
    int x,y,u,v;
    bool operator<(line o){
        if(y*o.x!=x*o.y) return y*o.x<x*o.y;
        else return mpp(u,v)<mpp(o.u,o.v);
    }
}l[maxn*maxn/2];
struct node{
    int pre,suf,maxsum,sum;
};
namespace Segtree{
    node st[4*maxn];
    node change(node x,node y){
        node res;res.sum=x.sum+y.sum;
        res.pre=max(x.pre,x.sum+y.pre);
        res.suf=max(y.suf,y.sum+x.suf);
        res.maxsum=max(max(x.maxsum,y.maxsum),x.suf+y.pre);
        return res;
    }
    void update(int l,int r,int id,int pos,int x){
        if(l==r){
            st[id].pre=st[id].suf=st[id].maxsum=st[id].sum=x;
            return;
        }
        int mid=(l+r)/2;
        if(pos<=mid) update(l,mid,id*2,pos,x);
        else update(mid+1,r,id*2+1,pos,x);
        st[id]=change(st[id*2],st[id*2+1]);
    }
    void build(int l,int r,int id){
        if(l==r){
            st[id].pre=st[id].suf=st[id].maxsum=st[id].sum=p[l].w;
            return;
        }
        int mid=(l+r)/2;
        build(l,mid,id*2);build(mid+1,r,id*2+1);
        st[id]=change(st[id*2],st[id*2+1]);
    }
}
int cur[maxn];
void solve(){
    int n;cin >> n;
    for(int i=1;i<=n;i++) cin >> p[i].x >> p[i].y >> p[i].w,cur[i]=i;
    sort(p+1,p+n+1);
    int cnt=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++) l[cnt++]={p[i].x-p[j].x,p[i].y-p[j].y,i,j};
    }
    sort(l,l+cnt);
    Segtree::build(1,n,1);
    int ans=max(0LL,Segtree::st[1].maxsum);
    for(int i=0;i<cnt;i++){
        int u=l[i].u,v=l[i].v;
        Segtree::update(1,n,1,cur[u],p[v].w);
        Segtree::update(1,n,1,cur[v],p[u].w);
        swap(cur[u],cur[v]);
        if(i==cnt-1 || l[i].x*l[i+1].y!=l[i+1].x*l[i].y) ans=max(ans,Segtree::st[1].maxsum);
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 608 ms 63164 KB Output is correct
34 Correct 607 ms 63180 KB Output is correct
35 Correct 614 ms 63064 KB Output is correct
36 Correct 614 ms 63228 KB Output is correct
37 Correct 623 ms 63164 KB Output is correct
38 Correct 608 ms 63164 KB Output is correct
39 Correct 605 ms 63136 KB Output is correct
40 Correct 628 ms 63164 KB Output is correct
41 Correct 615 ms 63172 KB Output is correct
42 Correct 609 ms 63168 KB Output is correct
43 Correct 609 ms 63080 KB Output is correct
44 Correct 609 ms 63156 KB Output is correct
45 Correct 599 ms 63160 KB Output is correct
46 Correct 615 ms 63052 KB Output is correct
47 Correct 603 ms 63164 KB Output is correct
48 Correct 614 ms 63180 KB Output is correct
49 Correct 607 ms 63160 KB Output is correct
50 Correct 609 ms 63164 KB Output is correct
51 Correct 633 ms 63280 KB Output is correct
52 Correct 623 ms 63164 KB Output is correct
53 Correct 606 ms 63164 KB Output is correct
54 Correct 609 ms 63060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 608 ms 63164 KB Output is correct
34 Correct 607 ms 63180 KB Output is correct
35 Correct 614 ms 63064 KB Output is correct
36 Correct 614 ms 63228 KB Output is correct
37 Correct 623 ms 63164 KB Output is correct
38 Correct 608 ms 63164 KB Output is correct
39 Correct 605 ms 63136 KB Output is correct
40 Correct 628 ms 63164 KB Output is correct
41 Correct 615 ms 63172 KB Output is correct
42 Correct 609 ms 63168 KB Output is correct
43 Correct 609 ms 63080 KB Output is correct
44 Correct 609 ms 63156 KB Output is correct
45 Correct 599 ms 63160 KB Output is correct
46 Correct 615 ms 63052 KB Output is correct
47 Correct 603 ms 63164 KB Output is correct
48 Correct 614 ms 63180 KB Output is correct
49 Correct 607 ms 63160 KB Output is correct
50 Correct 609 ms 63164 KB Output is correct
51 Correct 633 ms 63280 KB Output is correct
52 Correct 623 ms 63164 KB Output is correct
53 Correct 606 ms 63164 KB Output is correct
54 Correct 609 ms 63060 KB Output is correct
55 Correct 613 ms 63180 KB Output is correct
56 Correct 607 ms 63052 KB Output is correct
57 Correct 610 ms 63164 KB Output is correct
58 Correct 633 ms 63160 KB Output is correct
59 Correct 607 ms 63156 KB Output is correct
60 Correct 615 ms 63052 KB Output is correct
61 Correct 612 ms 63180 KB Output is correct
62 Correct 609 ms 63164 KB Output is correct
63 Correct 612 ms 63052 KB Output is correct
64 Correct 605 ms 63160 KB Output is correct
65 Correct 611 ms 63144 KB Output is correct
66 Correct 616 ms 63164 KB Output is correct
67 Correct 619 ms 63180 KB Output is correct
68 Correct 621 ms 63168 KB Output is correct
69 Correct 614 ms 63160 KB Output is correct
70 Correct 614 ms 63164 KB Output is correct
71 Correct 613 ms 63052 KB Output is correct
72 Correct 613 ms 63160 KB Output is correct
73 Correct 610 ms 63160 KB Output is correct
74 Correct 615 ms 63160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 336 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 608 ms 63164 KB Output is correct
49 Correct 607 ms 63180 KB Output is correct
50 Correct 614 ms 63064 KB Output is correct
51 Correct 614 ms 63228 KB Output is correct
52 Correct 623 ms 63164 KB Output is correct
53 Correct 608 ms 63164 KB Output is correct
54 Correct 605 ms 63136 KB Output is correct
55 Correct 628 ms 63164 KB Output is correct
56 Correct 615 ms 63172 KB Output is correct
57 Correct 609 ms 63168 KB Output is correct
58 Correct 609 ms 63080 KB Output is correct
59 Correct 609 ms 63156 KB Output is correct
60 Correct 599 ms 63160 KB Output is correct
61 Correct 615 ms 63052 KB Output is correct
62 Correct 603 ms 63164 KB Output is correct
63 Correct 614 ms 63180 KB Output is correct
64 Correct 607 ms 63160 KB Output is correct
65 Correct 609 ms 63164 KB Output is correct
66 Correct 633 ms 63280 KB Output is correct
67 Correct 623 ms 63164 KB Output is correct
68 Correct 606 ms 63164 KB Output is correct
69 Correct 609 ms 63060 KB Output is correct
70 Correct 613 ms 63180 KB Output is correct
71 Correct 607 ms 63052 KB Output is correct
72 Correct 610 ms 63164 KB Output is correct
73 Correct 633 ms 63160 KB Output is correct
74 Correct 607 ms 63156 KB Output is correct
75 Correct 615 ms 63052 KB Output is correct
76 Correct 612 ms 63180 KB Output is correct
77 Correct 609 ms 63164 KB Output is correct
78 Correct 612 ms 63052 KB Output is correct
79 Correct 605 ms 63160 KB Output is correct
80 Correct 611 ms 63144 KB Output is correct
81 Correct 616 ms 63164 KB Output is correct
82 Correct 619 ms 63180 KB Output is correct
83 Correct 621 ms 63168 KB Output is correct
84 Correct 614 ms 63160 KB Output is correct
85 Correct 614 ms 63164 KB Output is correct
86 Correct 613 ms 63052 KB Output is correct
87 Correct 613 ms 63160 KB Output is correct
88 Correct 610 ms 63160 KB Output is correct
89 Correct 615 ms 63160 KB Output is correct
90 Correct 619 ms 63228 KB Output is correct
91 Correct 617 ms 63180 KB Output is correct
92 Correct 609 ms 63164 KB Output is correct
93 Correct 612 ms 63168 KB Output is correct
94 Correct 618 ms 63160 KB Output is correct
95 Correct 611 ms 63180 KB Output is correct
96 Correct 607 ms 63164 KB Output is correct
97 Correct 623 ms 63140 KB Output is correct
98 Correct 608 ms 63164 KB Output is correct
99 Correct 614 ms 63160 KB Output is correct
100 Correct 504 ms 63148 KB Output is correct
101 Correct 515 ms 63032 KB Output is correct
102 Correct 514 ms 63028 KB Output is correct
103 Correct 503 ms 63148 KB Output is correct
104 Correct 495 ms 63144 KB Output is correct
105 Correct 523 ms 63052 KB Output is correct
106 Correct 525 ms 63148 KB Output is correct
107 Correct 528 ms 63152 KB Output is correct
108 Correct 533 ms 63148 KB Output is correct
109 Correct 523 ms 63052 KB Output is correct
110 Correct 575 ms 63140 KB Output is correct
111 Correct 574 ms 63140 KB Output is correct
112 Correct 578 ms 63136 KB Output is correct
113 Correct 577 ms 63052 KB Output is correct
114 Correct 576 ms 63052 KB Output is correct
115 Correct 577 ms 63140 KB Output is correct
116 Correct 580 ms 63048 KB Output is correct
117 Correct 579 ms 63180 KB Output is correct
118 Correct 573 ms 63140 KB Output is correct
119 Correct 578 ms 63140 KB Output is correct
120 Correct 0 ms 340 KB Output is correct
121 Correct 0 ms 340 KB Output is correct
122 Correct 636 ms 63168 KB Output is correct
123 Correct 612 ms 63164 KB Output is correct
124 Correct 620 ms 63052 KB Output is correct
125 Correct 621 ms 63160 KB Output is correct
126 Correct 611 ms 63164 KB Output is correct
127 Correct 626 ms 63160 KB Output is correct
128 Correct 608 ms 63052 KB Output is correct
129 Correct 669 ms 63156 KB Output is correct
130 Correct 620 ms 63164 KB Output is correct
131 Correct 626 ms 63160 KB Output is correct
132 Correct 626 ms 63160 KB Output is correct
133 Correct 615 ms 63164 KB Output is correct