답안 #1036711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036711 2024-07-27T15:50:33 Z Misha_Yuzvik Bulldozer (JOI17_bulldozer) C++14
60 / 100
956 ms 66468 KB
# include <bits/stdc++.h>
using namespace std;
# define For(i , l , r) for(int 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) {
               //   cout << 1 << endl;
                  if (p[l.nom1] == p[r.nom1]) return p[l.nom2].x < p[r.nom2].x;
                  else return p[l.nom1].x < p[r.nom1].x;
              } 
              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 2 ms 732 KB Output is correct
3 Correct 2 ms 860 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 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 1 ms 860 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 856 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 732 KB Output is correct
10 Correct 2 ms 860 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 348 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 0 ms 348 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 984 KB Output is correct
23 Correct 2 ms 732 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 732 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 732 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 860 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 856 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 732 KB Output is correct
10 Correct 2 ms 860 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 348 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 0 ms 348 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 984 KB Output is correct
23 Correct 2 ms 732 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 732 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 732 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 772 ms 66160 KB Output is correct
34 Correct 806 ms 66192 KB Output is correct
35 Correct 787 ms 66228 KB Output is correct
36 Correct 885 ms 66192 KB Output is correct
37 Correct 912 ms 66196 KB Output is correct
38 Correct 933 ms 66192 KB Output is correct
39 Correct 956 ms 66324 KB Output is correct
40 Correct 943 ms 66264 KB Output is correct
41 Correct 884 ms 66160 KB Output is correct
42 Correct 851 ms 66300 KB Output is correct
43 Correct 806 ms 66208 KB Output is correct
44 Correct 842 ms 66192 KB Output is correct
45 Correct 887 ms 66160 KB Output is correct
46 Correct 833 ms 66192 KB Output is correct
47 Correct 845 ms 66216 KB Output is correct
48 Correct 878 ms 66164 KB Output is correct
49 Correct 886 ms 66132 KB Output is correct
50 Correct 830 ms 66160 KB Output is correct
51 Correct 777 ms 66152 KB Output is correct
52 Correct 789 ms 66468 KB Output is correct
53 Correct 804 ms 66200 KB Output is correct
54 Correct 798 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 860 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 712 KB Output is correct
6 Correct 2 ms 856 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 732 KB Output is correct
10 Correct 2 ms 860 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 348 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 0 ms 348 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 984 KB Output is correct
23 Correct 2 ms 732 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 732 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 732 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 772 ms 66160 KB Output is correct
34 Correct 806 ms 66192 KB Output is correct
35 Correct 787 ms 66228 KB Output is correct
36 Correct 885 ms 66192 KB Output is correct
37 Correct 912 ms 66196 KB Output is correct
38 Correct 933 ms 66192 KB Output is correct
39 Correct 956 ms 66324 KB Output is correct
40 Correct 943 ms 66264 KB Output is correct
41 Correct 884 ms 66160 KB Output is correct
42 Correct 851 ms 66300 KB Output is correct
43 Correct 806 ms 66208 KB Output is correct
44 Correct 842 ms 66192 KB Output is correct
45 Correct 887 ms 66160 KB Output is correct
46 Correct 833 ms 66192 KB Output is correct
47 Correct 845 ms 66216 KB Output is correct
48 Correct 878 ms 66164 KB Output is correct
49 Correct 886 ms 66132 KB Output is correct
50 Correct 830 ms 66160 KB Output is correct
51 Correct 777 ms 66152 KB Output is correct
52 Correct 789 ms 66468 KB Output is correct
53 Correct 804 ms 66200 KB Output is correct
54 Correct 798 ms 66192 KB Output is correct
55 Correct 830 ms 66192 KB Output is correct
56 Correct 816 ms 66448 KB Output is correct
57 Correct 850 ms 66188 KB Output is correct
58 Correct 849 ms 66160 KB Output is correct
59 Correct 794 ms 66212 KB Output is correct
60 Correct 868 ms 66196 KB Output is correct
61 Correct 872 ms 66224 KB Output is correct
62 Correct 838 ms 66192 KB Output is correct
63 Correct 876 ms 66324 KB Output is correct
64 Correct 810 ms 66296 KB Output is correct
65 Incorrect 868 ms 66192 KB Output isn't correct
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 2 ms 732 KB Output is correct
3 Correct 2 ms 860 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 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 1 ms 860 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 2 ms 732 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 2 ms 712 KB Output is correct
21 Correct 2 ms 856 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 732 KB Output is correct
25 Correct 2 ms 860 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 348 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 0 ms 348 KB Output is correct
36 Correct 2 ms 736 KB Output is correct
37 Correct 2 ms 984 KB Output is correct
38 Correct 2 ms 732 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 732 KB Output is correct
43 Correct 2 ms 732 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 732 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 772 ms 66160 KB Output is correct
49 Correct 806 ms 66192 KB Output is correct
50 Correct 787 ms 66228 KB Output is correct
51 Correct 885 ms 66192 KB Output is correct
52 Correct 912 ms 66196 KB Output is correct
53 Correct 933 ms 66192 KB Output is correct
54 Correct 956 ms 66324 KB Output is correct
55 Correct 943 ms 66264 KB Output is correct
56 Correct 884 ms 66160 KB Output is correct
57 Correct 851 ms 66300 KB Output is correct
58 Correct 806 ms 66208 KB Output is correct
59 Correct 842 ms 66192 KB Output is correct
60 Correct 887 ms 66160 KB Output is correct
61 Correct 833 ms 66192 KB Output is correct
62 Correct 845 ms 66216 KB Output is correct
63 Correct 878 ms 66164 KB Output is correct
64 Correct 886 ms 66132 KB Output is correct
65 Correct 830 ms 66160 KB Output is correct
66 Correct 777 ms 66152 KB Output is correct
67 Correct 789 ms 66468 KB Output is correct
68 Correct 804 ms 66200 KB Output is correct
69 Correct 798 ms 66192 KB Output is correct
70 Correct 830 ms 66192 KB Output is correct
71 Correct 816 ms 66448 KB Output is correct
72 Correct 850 ms 66188 KB Output is correct
73 Correct 849 ms 66160 KB Output is correct
74 Correct 794 ms 66212 KB Output is correct
75 Correct 868 ms 66196 KB Output is correct
76 Correct 872 ms 66224 KB Output is correct
77 Correct 838 ms 66192 KB Output is correct
78 Correct 876 ms 66324 KB Output is correct
79 Correct 810 ms 66296 KB Output is correct
80 Incorrect 868 ms 66192 KB Output isn't correct
81 Halted 0 ms 0 KB -