답안 #948747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948747 2024-03-18T12:58:26 Z shenfe1 Bulldozer (JOI17_bulldozer) C++17
100 / 100
1084 ms 74584 KB
#include <bits/stdc++.h>

#pragma optimize("Ofast,unroll-loops")
#pragma target("avx2")

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll

const int MAX=2000+1;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const int inf=2e9;  
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int x[MAX],y[MAX],a[MAX];
vector<pair<ld,pii>> slope;
vector<pair<pii,int>> vec;
int pos[MAX],rev[MAX];
int f[MAX];
int p[MAX],mn[MAX],mx[MAX];

struct segtree{
  struct node{
    ll pref,suf,sum,ans;
    node(){
      pref=suf=sum=ans=0;
    }
  }t[4*MAX];

  node mrg(node a,node b){
    node res;
    res.sum=a.sum+b.sum;
    res.ans=max({a.ans,b.ans,a.suf+b.pref});
    res.suf=max(b.suf,b.sum+a.suf);
    res.pref=max(a.pref,a.sum+b.pref);
    return res;
  } 

  void update(int v,int tl,int tr,int pos,int x){
    if(tl==tr){
      t[v].pref=max(0,x);
      t[v].suf=max(0,x);
      t[v].ans=max(0,x);
      t[v].sum=x;
      return;
    }
    int tm=(tl+tr)/2;
    if(pos<=tm)update(2*v,tl,tm,pos,x);
    else update(2*v+1,tm+1,tr,pos,x);
    t[v]=mrg(t[2*v],t[2*v+1]);
  }
}t;

vector<int> vv[MAX];
vector<int> can;

void solve(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x[i]>>y[i]>>a[i];
    vec.pb({{x[i],-y[i]},i});
  }
  sort(all(vec));
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      if(x[vec[i-1].S]!=x[vec[j-1].S]){
        ld k=(0.0+y[vec[i-1].S]-y[vec[j-1].S])/(x[vec[i-1].S]-x[vec[j-1].S]);
        slope.pb({k,{vec[i-1].S,vec[j-1].S}});
      }
      else{
        slope.pb({-inf,{vec[i-1].S,vec[j-1].S}});
      }
    }
  }
  for(int i=0;i<n;i++){
    f[i+1]=a[vec[i].S];
    t.update(1,1,n,i+1,f[i+1]);
    pos[vec[i].S]=i+1;
    rev[i+1]=vec[i].S;
  }
  sort(all(slope));
  ll ans=t.t[1].ans;
  for(int k=0;k<sz(slope);k++){
    int i=slope[k].S.F,j=slope[k].S.S;
    i=pos[i];
    j=pos[j];
    if(i>j)swap(i,j);
    vv[i].pb(j);
    can.pb(i);
    if(k==sz(slope)-1||slope[k].F!=slope[k+1].F){
      int r=-1;
      int lef=0;
      sort(all(can));
      for(int l:can){
        if(l<=r){
          while(!vv[l].empty()){
            r=max(r,vv[l].back());
            vv[l].ppb();
          }
        }
        else{
          if(lef<=r){
            reverse(f+lef,f+r+1);
            reverse(rev+lef,rev+r+1);
            // cout<<lef<<" "<<r<<"\n";
            for(int d=lef;d<=r;d++){
              pos[rev[d]]=d;
              t.update(1,1,n,d,f[d]);
            }
          }
          lef=l;
          r=-1;
          while(!vv[l].empty()){
            r=max(r,vv[l].back());
            vv[l].ppb();
          }
        }
      }
      if(lef<=r){
        reverse(f+lef,f+r+1);
        reverse(rev+lef,rev+r+1);
        for(int d=lef;d<=r;d++){
          pos[rev[d]]=d;
          t.update(1,1,n,d,f[d]);
        }
      }
      can.clear();
      ans=max(ans,t.t[1].ans);
    }
  }
  cout<<ans<<"\n";
}

signed main(){
  // freopen("triangles.in","r",stdin);
  // freopen("triangles.out","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // prec();
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Compilation message

bulldozer.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast,unroll-loops")
      | 
bulldozer.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 854 ms 66492 KB Output is correct
34 Correct 824 ms 67264 KB Output is correct
35 Correct 829 ms 68556 KB Output is correct
36 Correct 832 ms 67012 KB Output is correct
37 Correct 826 ms 67772 KB Output is correct
38 Correct 818 ms 68284 KB Output is correct
39 Correct 828 ms 68260 KB Output is correct
40 Correct 842 ms 68044 KB Output is correct
41 Correct 836 ms 67536 KB Output is correct
42 Correct 846 ms 67520 KB Output is correct
43 Correct 831 ms 68048 KB Output is correct
44 Correct 832 ms 68440 KB Output is correct
45 Correct 830 ms 67520 KB Output is correct
46 Correct 832 ms 67696 KB Output is correct
47 Correct 851 ms 68288 KB Output is correct
48 Correct 824 ms 67528 KB Output is correct
49 Correct 829 ms 67404 KB Output is correct
50 Correct 830 ms 66980 KB Output is correct
51 Correct 836 ms 67644 KB Output is correct
52 Correct 812 ms 68548 KB Output is correct
53 Correct 833 ms 66736 KB Output is correct
54 Correct 816 ms 67536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 854 ms 66492 KB Output is correct
34 Correct 824 ms 67264 KB Output is correct
35 Correct 829 ms 68556 KB Output is correct
36 Correct 832 ms 67012 KB Output is correct
37 Correct 826 ms 67772 KB Output is correct
38 Correct 818 ms 68284 KB Output is correct
39 Correct 828 ms 68260 KB Output is correct
40 Correct 842 ms 68044 KB Output is correct
41 Correct 836 ms 67536 KB Output is correct
42 Correct 846 ms 67520 KB Output is correct
43 Correct 831 ms 68048 KB Output is correct
44 Correct 832 ms 68440 KB Output is correct
45 Correct 830 ms 67520 KB Output is correct
46 Correct 832 ms 67696 KB Output is correct
47 Correct 851 ms 68288 KB Output is correct
48 Correct 824 ms 67528 KB Output is correct
49 Correct 829 ms 67404 KB Output is correct
50 Correct 830 ms 66980 KB Output is correct
51 Correct 836 ms 67644 KB Output is correct
52 Correct 812 ms 68548 KB Output is correct
53 Correct 833 ms 66736 KB Output is correct
54 Correct 816 ms 67536 KB Output is correct
55 Correct 859 ms 66996 KB Output is correct
56 Correct 858 ms 68556 KB Output is correct
57 Correct 867 ms 66744 KB Output is correct
58 Correct 830 ms 68044 KB Output is correct
59 Correct 824 ms 66512 KB Output is correct
60 Correct 837 ms 67208 KB Output is correct
61 Correct 822 ms 67268 KB Output is correct
62 Correct 837 ms 68044 KB Output is correct
63 Correct 861 ms 68280 KB Output is correct
64 Correct 835 ms 68280 KB Output is correct
65 Correct 824 ms 68044 KB Output is correct
66 Correct 832 ms 67024 KB Output is correct
67 Correct 866 ms 68032 KB Output is correct
68 Correct 851 ms 67264 KB Output is correct
69 Correct 831 ms 66740 KB Output is correct
70 Correct 852 ms 67212 KB Output is correct
71 Correct 847 ms 68544 KB Output is correct
72 Correct 845 ms 66996 KB Output is correct
73 Correct 822 ms 67888 KB Output is correct
74 Correct 828 ms 66752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 2 ms 1116 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 3 ms 1116 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 600 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 0 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 2 ms 1116 KB Output is correct
39 Correct 2 ms 1116 KB Output is correct
40 Correct 2 ms 1116 KB Output is correct
41 Correct 2 ms 1116 KB Output is correct
42 Correct 2 ms 1116 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 2 ms 1116 KB Output is correct
45 Correct 2 ms 1116 KB Output is correct
46 Correct 2 ms 1116 KB Output is correct
47 Correct 2 ms 1116 KB Output is correct
48 Correct 854 ms 66492 KB Output is correct
49 Correct 824 ms 67264 KB Output is correct
50 Correct 829 ms 68556 KB Output is correct
51 Correct 832 ms 67012 KB Output is correct
52 Correct 826 ms 67772 KB Output is correct
53 Correct 818 ms 68284 KB Output is correct
54 Correct 828 ms 68260 KB Output is correct
55 Correct 842 ms 68044 KB Output is correct
56 Correct 836 ms 67536 KB Output is correct
57 Correct 846 ms 67520 KB Output is correct
58 Correct 831 ms 68048 KB Output is correct
59 Correct 832 ms 68440 KB Output is correct
60 Correct 830 ms 67520 KB Output is correct
61 Correct 832 ms 67696 KB Output is correct
62 Correct 851 ms 68288 KB Output is correct
63 Correct 824 ms 67528 KB Output is correct
64 Correct 829 ms 67404 KB Output is correct
65 Correct 830 ms 66980 KB Output is correct
66 Correct 836 ms 67644 KB Output is correct
67 Correct 812 ms 68548 KB Output is correct
68 Correct 833 ms 66736 KB Output is correct
69 Correct 816 ms 67536 KB Output is correct
70 Correct 859 ms 66996 KB Output is correct
71 Correct 858 ms 68556 KB Output is correct
72 Correct 867 ms 66744 KB Output is correct
73 Correct 830 ms 68044 KB Output is correct
74 Correct 824 ms 66512 KB Output is correct
75 Correct 837 ms 67208 KB Output is correct
76 Correct 822 ms 67268 KB Output is correct
77 Correct 837 ms 68044 KB Output is correct
78 Correct 861 ms 68280 KB Output is correct
79 Correct 835 ms 68280 KB Output is correct
80 Correct 824 ms 68044 KB Output is correct
81 Correct 832 ms 67024 KB Output is correct
82 Correct 866 ms 68032 KB Output is correct
83 Correct 851 ms 67264 KB Output is correct
84 Correct 831 ms 66740 KB Output is correct
85 Correct 852 ms 67212 KB Output is correct
86 Correct 847 ms 68544 KB Output is correct
87 Correct 845 ms 66996 KB Output is correct
88 Correct 822 ms 67888 KB Output is correct
89 Correct 828 ms 66752 KB Output is correct
90 Correct 836 ms 67280 KB Output is correct
91 Correct 818 ms 66512 KB Output is correct
92 Correct 835 ms 66768 KB Output is correct
93 Correct 822 ms 67876 KB Output is correct
94 Correct 852 ms 68040 KB Output is correct
95 Correct 863 ms 66668 KB Output is correct
96 Correct 831 ms 68040 KB Output is correct
97 Correct 831 ms 67020 KB Output is correct
98 Correct 828 ms 68032 KB Output is correct
99 Correct 850 ms 68288 KB Output is correct
100 Correct 556 ms 73124 KB Output is correct
101 Correct 576 ms 74412 KB Output is correct
102 Correct 566 ms 73128 KB Output is correct
103 Correct 564 ms 74584 KB Output is correct
104 Correct 563 ms 73652 KB Output is correct
105 Correct 627 ms 72104 KB Output is correct
106 Correct 628 ms 72948 KB Output is correct
107 Correct 639 ms 72224 KB Output is correct
108 Correct 639 ms 72696 KB Output is correct
109 Correct 638 ms 73896 KB Output is correct
110 Correct 721 ms 68024 KB Output is correct
111 Correct 710 ms 66896 KB Output is correct
112 Correct 701 ms 67004 KB Output is correct
113 Correct 715 ms 67536 KB Output is correct
114 Correct 692 ms 67792 KB Output is correct
115 Correct 707 ms 68036 KB Output is correct
116 Correct 704 ms 67792 KB Output is correct
117 Correct 705 ms 67768 KB Output is correct
118 Correct 689 ms 67840 KB Output is correct
119 Correct 701 ms 68272 KB Output is correct
120 Correct 1 ms 604 KB Output is correct
121 Correct 0 ms 604 KB Output is correct
122 Correct 864 ms 68040 KB Output is correct
123 Correct 1084 ms 66984 KB Output is correct
124 Correct 1062 ms 68544 KB Output is correct
125 Correct 876 ms 68020 KB Output is correct
126 Correct 901 ms 66624 KB Output is correct
127 Correct 907 ms 66740 KB Output is correct
128 Correct 854 ms 68020 KB Output is correct
129 Correct 858 ms 68296 KB Output is correct
130 Correct 855 ms 68548 KB Output is correct
131 Correct 842 ms 67404 KB Output is correct
132 Correct 816 ms 66744 KB Output is correct
133 Correct 833 ms 67396 KB Output is correct