답안 #1036731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036731 2024-07-27T16:09:43 Z Misha_Yuzvik Bulldozer (JOI17_bulldozer) C++14
100 / 100
945 ms 66396 KB
# include <bits/stdc++.h>
using namespace std;
# define For(i , l , r) for(long long i = (l); i <= (r); i++)
# define Rep(i , n) For(i , 0 , (n) - 1)
# define size(x) (long long)x.size()
# define MAXN 2000005
# define MAXK 1000005
# define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 9;
const ld eps = 0.000000001;
ll n , m , k , ans = 0 , q;
struct pt {
   ll x , y , val;
   bool operator == (const pt& p) {
       return (p.x == x && p.y == y);
   }
};
struct vc {
    ll x , y;
    ll nom1 , nom2;
};
ll cross_pr(const vc &a , const vc& b) {
  //  cout << a.x << ' ' << a.y << ' ' << b.x << ' ' << b.y << "\n";
    return a.x * b.y - b.x * a.y;
}
struct node {
    ll sum , wyn , mxp , mxs;
};
vector<node>t;
ll sz = 1;
void init(ll n) {
    while (sz < n) sz *= 2;
    t.resize(sz * 3 + 5);
}
node calc(node &left , node &right) {
     node cur = {0 , 0 , 0 , 0};
     cur.sum = left.sum + right.sum;
     cur.mxp = max(left.mxp , left.sum + right.mxp);
     cur.mxs = max(right.mxs , right.sum + left.mxs);
     cur.wyn = max({left.wyn , right.wyn , left.mxs + right.mxp});
     return cur;
}
void upd(ll nom , ll val , ll x , ll lx , ll rx) {
       if (rx - lx == 1) {
            t[x].sum = val;
            t[x].mxp = t[x].mxs = t[x].wyn = max(0LL , val);
            return;
       }
       ll mid = (lx + rx) / 2;
       if (nom < mid) upd(nom , val , (x << 1) , lx , mid);
       else upd(nom , val , (x << 1) + 1 , mid , rx);
       t[x] = calc(t[x << 1] , t[(x << 1) + 1]);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<pt>p(n);
    for (auto &[x , y , val] : p) cin >> x >> y >> val;
    sort(p.begin() , p.end() , 
         [](const auto& l , const auto& r) {
             if (l.x == r.x) return l.y > r.y;
             return l.x < r.x;   
         });
    vector<vc>line;
    Rep (i , n) {
        For (j , i + 1 , n - 1) {
            line.push_back({p[i].x - p[j].x , p[i].y - p[j].y , i , j});  
            if (size(line) > 0 && line.back().x == 0) line.pop_back();
            if (size(line) > 0 && line.back().x < 0) line.back().x *= -1 , line.back().y *= -1;
        }
    }
    sort(all(line) , 
       [&](const vc& l , const vc& r) {
            //  cout << 0 << endl;
              ll f = cross_pr(l , r);
              if (f == 0) {
                  if (l.nom1 == r.nom1) return l.nom2 > r.nom2;
                  else return l.nom1 > r.nom1;
              } 
              return f < 0;
    });
    init(n);
    Rep (i , n) {
        upd(i , p[i].val , 1 , 0 , sz);
    }
    vector<ll>pos(n);
    Rep (i , n) pos[i] = i;
    ans = t[1].wyn;
    if (size(line) == 0) {
        cout << ans;
        return 0;
    }
    ld prev_tg = (ld)line[0].y / (ld)line[0].x;
    Rep (i , size(line)) {
          ll x = line[i].x , y = line[i].y , nom1 = line[i].nom1 , nom2 = line[i].nom2;
          if ((ld)y / (ld)x != prev_tg) {
            ll cur_res = t[1].wyn;
            ans = max(ans , cur_res);
            prev_tg = (ld)y / (ld)x;
          }
          swap(pos[nom1] , pos[nom2]);
          ll pos1 = pos[nom1] , pos2 = pos[nom2];
          upd(pos1 , p[nom1].val , 1 , 0 , sz);
          upd(pos2 , p[nom2].val , 1 , 0 , sz);
          
    }
    ans = max(ans , t[1].wyn);
    cout << ans;
}
/*

*/

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:62:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |     for (auto &[x , y , val] : p) cin >> x >> y >> val;
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 732 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 360 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 812 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 812 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 893 ms 66200 KB Output is correct
34 Correct 945 ms 66196 KB Output is correct
35 Correct 883 ms 66164 KB Output is correct
36 Correct 866 ms 66276 KB Output is correct
37 Correct 853 ms 66300 KB Output is correct
38 Correct 871 ms 66160 KB Output is correct
39 Correct 865 ms 66200 KB Output is correct
40 Correct 866 ms 66196 KB Output is correct
41 Correct 822 ms 66216 KB Output is correct
42 Correct 900 ms 66164 KB Output is correct
43 Correct 837 ms 66164 KB Output is correct
44 Correct 814 ms 66280 KB Output is correct
45 Correct 852 ms 66372 KB Output is correct
46 Correct 916 ms 66160 KB Output is correct
47 Correct 846 ms 66164 KB Output is correct
48 Correct 836 ms 66196 KB Output is correct
49 Correct 848 ms 66352 KB Output is correct
50 Correct 885 ms 66188 KB Output is correct
51 Correct 853 ms 66224 KB Output is correct
52 Correct 872 ms 66164 KB Output is correct
53 Correct 866 ms 66196 KB Output is correct
54 Correct 858 ms 66192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 2 ms 856 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 812 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 893 ms 66200 KB Output is correct
34 Correct 945 ms 66196 KB Output is correct
35 Correct 883 ms 66164 KB Output is correct
36 Correct 866 ms 66276 KB Output is correct
37 Correct 853 ms 66300 KB Output is correct
38 Correct 871 ms 66160 KB Output is correct
39 Correct 865 ms 66200 KB Output is correct
40 Correct 866 ms 66196 KB Output is correct
41 Correct 822 ms 66216 KB Output is correct
42 Correct 900 ms 66164 KB Output is correct
43 Correct 837 ms 66164 KB Output is correct
44 Correct 814 ms 66280 KB Output is correct
45 Correct 852 ms 66372 KB Output is correct
46 Correct 916 ms 66160 KB Output is correct
47 Correct 846 ms 66164 KB Output is correct
48 Correct 836 ms 66196 KB Output is correct
49 Correct 848 ms 66352 KB Output is correct
50 Correct 885 ms 66188 KB Output is correct
51 Correct 853 ms 66224 KB Output is correct
52 Correct 872 ms 66164 KB Output is correct
53 Correct 866 ms 66196 KB Output is correct
54 Correct 858 ms 66192 KB Output is correct
55 Correct 842 ms 66356 KB Output is correct
56 Correct 808 ms 66192 KB Output is correct
57 Correct 810 ms 66368 KB Output is correct
58 Correct 824 ms 66192 KB Output is correct
59 Correct 825 ms 66196 KB Output is correct
60 Correct 811 ms 66256 KB Output is correct
61 Correct 797 ms 66196 KB Output is correct
62 Correct 821 ms 66312 KB Output is correct
63 Correct 852 ms 66220 KB Output is correct
64 Correct 849 ms 66208 KB Output is correct
65 Correct 874 ms 66160 KB Output is correct
66 Correct 879 ms 66244 KB Output is correct
67 Correct 861 ms 66268 KB Output is correct
68 Correct 868 ms 66224 KB Output is correct
69 Correct 880 ms 66248 KB Output is correct
70 Correct 857 ms 66396 KB Output is correct
71 Correct 821 ms 66212 KB Output is correct
72 Correct 831 ms 66140 KB Output is correct
73 Correct 837 ms 66212 KB Output is correct
74 Correct 849 ms 66160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 732 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 360 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 732 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 732 KB Output is correct
21 Correct 2 ms 732 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 732 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 856 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 732 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 812 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 893 ms 66200 KB Output is correct
49 Correct 945 ms 66196 KB Output is correct
50 Correct 883 ms 66164 KB Output is correct
51 Correct 866 ms 66276 KB Output is correct
52 Correct 853 ms 66300 KB Output is correct
53 Correct 871 ms 66160 KB Output is correct
54 Correct 865 ms 66200 KB Output is correct
55 Correct 866 ms 66196 KB Output is correct
56 Correct 822 ms 66216 KB Output is correct
57 Correct 900 ms 66164 KB Output is correct
58 Correct 837 ms 66164 KB Output is correct
59 Correct 814 ms 66280 KB Output is correct
60 Correct 852 ms 66372 KB Output is correct
61 Correct 916 ms 66160 KB Output is correct
62 Correct 846 ms 66164 KB Output is correct
63 Correct 836 ms 66196 KB Output is correct
64 Correct 848 ms 66352 KB Output is correct
65 Correct 885 ms 66188 KB Output is correct
66 Correct 853 ms 66224 KB Output is correct
67 Correct 872 ms 66164 KB Output is correct
68 Correct 866 ms 66196 KB Output is correct
69 Correct 858 ms 66192 KB Output is correct
70 Correct 842 ms 66356 KB Output is correct
71 Correct 808 ms 66192 KB Output is correct
72 Correct 810 ms 66368 KB Output is correct
73 Correct 824 ms 66192 KB Output is correct
74 Correct 825 ms 66196 KB Output is correct
75 Correct 811 ms 66256 KB Output is correct
76 Correct 797 ms 66196 KB Output is correct
77 Correct 821 ms 66312 KB Output is correct
78 Correct 852 ms 66220 KB Output is correct
79 Correct 849 ms 66208 KB Output is correct
80 Correct 874 ms 66160 KB Output is correct
81 Correct 879 ms 66244 KB Output is correct
82 Correct 861 ms 66268 KB Output is correct
83 Correct 868 ms 66224 KB Output is correct
84 Correct 880 ms 66248 KB Output is correct
85 Correct 857 ms 66396 KB Output is correct
86 Correct 821 ms 66212 KB Output is correct
87 Correct 831 ms 66140 KB Output is correct
88 Correct 837 ms 66212 KB Output is correct
89 Correct 849 ms 66160 KB Output is correct
90 Correct 832 ms 66164 KB Output is correct
91 Correct 834 ms 66228 KB Output is correct
92 Correct 864 ms 66164 KB Output is correct
93 Correct 898 ms 66196 KB Output is correct
94 Correct 859 ms 66196 KB Output is correct
95 Correct 875 ms 66272 KB Output is correct
96 Correct 883 ms 66240 KB Output is correct
97 Correct 879 ms 66192 KB Output is correct
98 Correct 835 ms 66224 KB Output is correct
99 Correct 867 ms 66360 KB Output is correct
100 Correct 417 ms 33460 KB Output is correct
101 Correct 410 ms 33468 KB Output is correct
102 Correct 415 ms 33436 KB Output is correct
103 Correct 434 ms 33444 KB Output is correct
104 Correct 410 ms 33460 KB Output is correct
105 Correct 576 ms 66336 KB Output is correct
106 Correct 577 ms 66192 KB Output is correct
107 Correct 576 ms 66260 KB Output is correct
108 Correct 583 ms 66276 KB Output is correct
109 Correct 580 ms 66164 KB Output is correct
110 Correct 804 ms 66164 KB Output is correct
111 Correct 799 ms 66220 KB Output is correct
112 Correct 840 ms 66200 KB Output is correct
113 Correct 790 ms 66164 KB Output is correct
114 Correct 814 ms 66224 KB Output is correct
115 Correct 830 ms 66212 KB Output is correct
116 Correct 840 ms 66196 KB Output is correct
117 Correct 816 ms 66164 KB Output is correct
118 Correct 810 ms 66280 KB Output is correct
119 Correct 773 ms 66264 KB Output is correct
120 Correct 0 ms 348 KB Output is correct
121 Correct 0 ms 348 KB Output is correct
122 Correct 843 ms 66224 KB Output is correct
123 Correct 800 ms 66312 KB Output is correct
124 Correct 784 ms 66164 KB Output is correct
125 Correct 816 ms 66128 KB Output is correct
126 Correct 788 ms 66196 KB Output is correct
127 Correct 811 ms 66164 KB Output is correct
128 Correct 824 ms 66192 KB Output is correct
129 Correct 805 ms 66228 KB Output is correct
130 Correct 783 ms 66196 KB Output is correct
131 Correct 793 ms 66228 KB Output is correct
132 Correct 788 ms 66164 KB Output is correct
133 Correct 797 ms 66392 KB Output is correct