Submission #1036725

# Submission time Handle Problem Language Result Execution time Memory
1036725 2024-07-27T16:04:02 Z Misha_Yuzvik Bulldozer (JOI17_bulldozer) C++14
75 / 100
1034 ms 66344 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) {
               //   cout << 1 << endl;
                  if (p[l.nom1].y == p[r.nom1].y) return p[l.nom2].y > p[r.nom2].y;
                  else return p[l.nom1].y > p[r.nom1].y;
              } 
              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;
      |                ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 2 ms 732 KB Output is correct
9 Correct 2 ms 732 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 708 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 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 2 ms 732 KB Output is correct
9 Correct 2 ms 732 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 708 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 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 849 ms 66336 KB Output is correct
34 Correct 834 ms 66196 KB Output is correct
35 Correct 845 ms 66156 KB Output is correct
36 Correct 834 ms 66164 KB Output is correct
37 Correct 911 ms 66196 KB Output is correct
38 Correct 848 ms 66188 KB Output is correct
39 Correct 870 ms 66164 KB Output is correct
40 Correct 833 ms 66192 KB Output is correct
41 Correct 860 ms 66208 KB Output is correct
42 Correct 845 ms 66160 KB Output is correct
43 Correct 874 ms 66336 KB Output is correct
44 Correct 833 ms 66228 KB Output is correct
45 Correct 816 ms 66196 KB Output is correct
46 Correct 846 ms 66212 KB Output is correct
47 Correct 881 ms 66228 KB Output is correct
48 Correct 896 ms 66196 KB Output is correct
49 Correct 911 ms 66160 KB Output is correct
50 Correct 944 ms 66196 KB Output is correct
51 Correct 871 ms 66300 KB Output is correct
52 Correct 1034 ms 66212 KB Output is correct
53 Correct 904 ms 66164 KB Output is correct
54 Correct 887 ms 66208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 732 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 2 ms 732 KB Output is correct
9 Correct 2 ms 732 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 708 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 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 849 ms 66336 KB Output is correct
34 Correct 834 ms 66196 KB Output is correct
35 Correct 845 ms 66156 KB Output is correct
36 Correct 834 ms 66164 KB Output is correct
37 Correct 911 ms 66196 KB Output is correct
38 Correct 848 ms 66188 KB Output is correct
39 Correct 870 ms 66164 KB Output is correct
40 Correct 833 ms 66192 KB Output is correct
41 Correct 860 ms 66208 KB Output is correct
42 Correct 845 ms 66160 KB Output is correct
43 Correct 874 ms 66336 KB Output is correct
44 Correct 833 ms 66228 KB Output is correct
45 Correct 816 ms 66196 KB Output is correct
46 Correct 846 ms 66212 KB Output is correct
47 Correct 881 ms 66228 KB Output is correct
48 Correct 896 ms 66196 KB Output is correct
49 Correct 911 ms 66160 KB Output is correct
50 Correct 944 ms 66196 KB Output is correct
51 Correct 871 ms 66300 KB Output is correct
52 Correct 1034 ms 66212 KB Output is correct
53 Correct 904 ms 66164 KB Output is correct
54 Correct 887 ms 66208 KB Output is correct
55 Correct 878 ms 66192 KB Output is correct
56 Correct 900 ms 66168 KB Output is correct
57 Correct 927 ms 66312 KB Output is correct
58 Correct 930 ms 66140 KB Output is correct
59 Correct 889 ms 66220 KB Output is correct
60 Correct 884 ms 66192 KB Output is correct
61 Correct 886 ms 66164 KB Output is correct
62 Correct 875 ms 66228 KB Output is correct
63 Correct 845 ms 66152 KB Output is correct
64 Correct 853 ms 66228 KB Output is correct
65 Correct 839 ms 66328 KB Output is correct
66 Correct 829 ms 66340 KB Output is correct
67 Correct 872 ms 66168 KB Output is correct
68 Correct 850 ms 66160 KB Output is correct
69 Correct 804 ms 66192 KB Output is correct
70 Correct 812 ms 66192 KB Output is correct
71 Correct 823 ms 66344 KB Output is correct
72 Correct 796 ms 66164 KB Output is correct
73 Correct 785 ms 66196 KB Output is correct
74 Correct 794 ms 66324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 732 KB Output isn't correct
2 Halted 0 ms 0 KB -