Submission #263529

# Submission time Handle Problem Language Result Execution time Memory
263529 2020-08-13T18:45:44 Z fivefourthreeone Bulldozer (JOI17_bulldozer) C++17
100 / 100
1712 ms 50000 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 2048;
int n;
//0 = max_prefix; 1 = max_suffix; 2 = realmax; 3 = sum
array<ll, 4> sgmax[2*mxN];
void upd(int p, ll val) {
    sgmax[p+=mxN] = {val, val, val, val};
    while(p>1) {
      p/=2;
      sgmax[p][0] = max(sgmax[2*p][0], sgmax[2*p][3] + sgmax[2*p+1][0]);
      sgmax[p][1] = max(sgmax[2*p+1][1], sgmax[2*p+1][3] + sgmax[2*p][1]);
      sgmax[p][2] = max({sgmax[2*p][2], sgmax[2*p+1][2], sgmax[2*p][1] + sgmax[2*p+1][0]});
      sgmax[p][3] = sgmax[2*p][3] + sgmax[2*p+1][3];
      //cout<<p<<" "<<sgmax[p][0]<<" "<<sgmax[p][1]<<" "<<sgmax[p][2]<<" "<<sgmax[p][3]<<"\n";
    }
}
/*array<ll, 4> qmax(int l, int r) {
    array<ll, 4> left = {0, 0, 0, 0};
    array<ll, 4> right = {0, 0, 0, 0};
    r++;
    for(l+=n, r+=n; l<r; l>>=1, r>>=1) {
        if(l&1) left = merge(left, sgmax[l++]);
        if(r&1) right = merge(sgmax[--r], right);
    }
    return merge(left, right);
}*/
struct event{
    ll dx;
    ll dy;
    int a, b;
    event(int x1, int y1, int x2, int y2, int aa, int bb) {
        a = aa;
        b = bb;
        int x = x2-x1;
        int y = y2-y1;
        int k = gcd(x, y);
        x/=k;
        y/=k;
        if(x<0||(x==0&&y<0)) {
            x = -x;
            y = -y;
        }
        dx = x;
        dy = y;
        //cout<<x<<" "<<y<<'\n';
    }
    bool operator<(const event &other) const{
        return dx*other.dy > dy*other.dx;
    }
};
vector<event> all;
array<int, 4> arr[mxN];
int ord[mxN];
int lst[mxN];
int dsu[mxN];
int prv[mxN];
int curr;
int find(int a) {
    if(lst[a]!=curr) {
        lst[a] = curr;
        dsu[a] = a;
    }
    return a==dsu[a] ? a : dsu[a] = find(dsu[a]);
}
void merge(int a, int b) {
    dsu[find(a)] = find(b); 
}
bool fix(int a, int b) {
    return ord[a]<ord[b];
}
void swapp(int a, int b) {
    swap(arr[ord[a]], arr[ord[b]]);
    swap(ord[a], ord[b]);
    upd(ord[a], arr[ord[a]][2]);
    upd(ord[b], arr[ord[b]][2]);
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    owo(i, 0, n) {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
        arr[i][3] = i;
    }
    owo(i, 0, n) {
        owo(j, i+1, n) {
            all.senpai(event(arr[i][0], arr[i][1], arr[j][0], arr[j][1], i, j));
            //cout<<arr[i][0]<<" "<<arr[i][1]<<" "<<arr[j][0]<<" "<<arr[j][1]<<" "<<all[all.size()-1].inter<<"\n";
        }
    }
    //ayaya;
    sort(all.begin(), all.end());
    sort(arr, arr+n);
    owo(i, 0, n) {
        upd(i, arr[i][2]);
        ord[arr[i][3]] = i;
    }
    //cout<<qmax(0, n-1)[2]<<"\n";
    ll ans = sgmax[1][2];
    for(int i=0; i<all.size(); ) {
        int j= i+1;
        curr++;
        while(j<all.size()&&all[i].dx==all[j].dx&&all[i].dy==all[j].dy)j++;
        owo(k, i, j) {
            //cout<<all[k].a<<" "<<all[k].b<<endl;
            merge(all[k].a, all[k].b);
        }
        gp_hash_table<int, vector<int>> swp;
        owo(k, i, j) {
            if(prv[all[k].a]!=curr) {
                prv[all[k].a] = curr;
                swp[find(all[k].a)].senpai(all[k].a);
            }
            if(prv[all[k].b]!=curr) {
                prv[all[k].b] = curr;
                swp[find(all[k].b)].senpai(all[k].b);
            }
        }
        for(auto p: swp) {
            sort(p.second.begin(), p.second.end(), fix);
            int left =0;
            int right = p.second.size()-1;
            while(left<right) {
                swapp(p.second[left++], p.second[right--]);
            }
        }
        ans = max(ans, sgmax[1][2]);
        i = j;
    }
    cout<<ans<<"\n";
    return 0;
}

Compilation message

bulldozer.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
bulldozer.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:129:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |     for(int i=0; i<all.size(); ) {
      |                  ~^~~~~~~~~~~
bulldozer.cpp:132:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |         while(j<all.size()&&all[i].dx==all[j].dx&&all[i].dy==all[j].dy)j++;
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 704 KB Output is correct
2 Correct 1 ms 704 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 832 KB Output is correct
5 Correct 1 ms 704 KB Output is correct
6 Correct 1 ms 704 KB Output is correct
7 Correct 1 ms 704 KB Output is correct
8 Correct 1 ms 704 KB Output is correct
9 Correct 1 ms 704 KB Output is correct
10 Correct 1 ms 704 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 704 KB Output is correct
2 Correct 5 ms 704 KB Output is correct
3 Correct 5 ms 704 KB Output is correct
4 Correct 5 ms 704 KB Output is correct
5 Correct 5 ms 704 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 704 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 704 KB Output is correct
10 Correct 5 ms 704 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 704 KB Output is correct
22 Correct 4 ms 704 KB Output is correct
23 Correct 4 ms 704 KB Output is correct
24 Correct 4 ms 704 KB Output is correct
25 Correct 4 ms 704 KB Output is correct
26 Correct 4 ms 704 KB Output is correct
27 Correct 5 ms 704 KB Output is correct
28 Correct 4 ms 704 KB Output is correct
29 Correct 4 ms 704 KB Output is correct
30 Correct 4 ms 704 KB Output is correct
31 Correct 4 ms 704 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 704 KB Output is correct
2 Correct 5 ms 704 KB Output is correct
3 Correct 5 ms 704 KB Output is correct
4 Correct 5 ms 704 KB Output is correct
5 Correct 5 ms 704 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 704 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 704 KB Output is correct
10 Correct 5 ms 704 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 704 KB Output is correct
22 Correct 4 ms 704 KB Output is correct
23 Correct 4 ms 704 KB Output is correct
24 Correct 4 ms 704 KB Output is correct
25 Correct 4 ms 704 KB Output is correct
26 Correct 4 ms 704 KB Output is correct
27 Correct 5 ms 704 KB Output is correct
28 Correct 4 ms 704 KB Output is correct
29 Correct 4 ms 704 KB Output is correct
30 Correct 4 ms 704 KB Output is correct
31 Correct 4 ms 704 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 1664 ms 49836 KB Output is correct
34 Correct 1682 ms 49780 KB Output is correct
35 Correct 1674 ms 49708 KB Output is correct
36 Correct 1659 ms 49760 KB Output is correct
37 Correct 1620 ms 49800 KB Output is correct
38 Correct 1605 ms 49784 KB Output is correct
39 Correct 1614 ms 49708 KB Output is correct
40 Correct 1605 ms 49708 KB Output is correct
41 Correct 1612 ms 49708 KB Output is correct
42 Correct 1619 ms 49708 KB Output is correct
43 Correct 1566 ms 49708 KB Output is correct
44 Correct 1600 ms 49708 KB Output is correct
45 Correct 1585 ms 49708 KB Output is correct
46 Correct 1590 ms 49784 KB Output is correct
47 Correct 1602 ms 49708 KB Output is correct
48 Correct 1565 ms 49700 KB Output is correct
49 Correct 1558 ms 49708 KB Output is correct
50 Correct 1555 ms 49720 KB Output is correct
51 Correct 1577 ms 49708 KB Output is correct
52 Correct 1658 ms 49760 KB Output is correct
53 Correct 1619 ms 49708 KB Output is correct
54 Correct 1572 ms 49964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 704 KB Output is correct
2 Correct 5 ms 704 KB Output is correct
3 Correct 5 ms 704 KB Output is correct
4 Correct 5 ms 704 KB Output is correct
5 Correct 5 ms 704 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 704 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 704 KB Output is correct
10 Correct 5 ms 704 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 704 KB Output is correct
22 Correct 4 ms 704 KB Output is correct
23 Correct 4 ms 704 KB Output is correct
24 Correct 4 ms 704 KB Output is correct
25 Correct 4 ms 704 KB Output is correct
26 Correct 4 ms 704 KB Output is correct
27 Correct 5 ms 704 KB Output is correct
28 Correct 4 ms 704 KB Output is correct
29 Correct 4 ms 704 KB Output is correct
30 Correct 4 ms 704 KB Output is correct
31 Correct 4 ms 704 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 1664 ms 49836 KB Output is correct
34 Correct 1682 ms 49780 KB Output is correct
35 Correct 1674 ms 49708 KB Output is correct
36 Correct 1659 ms 49760 KB Output is correct
37 Correct 1620 ms 49800 KB Output is correct
38 Correct 1605 ms 49784 KB Output is correct
39 Correct 1614 ms 49708 KB Output is correct
40 Correct 1605 ms 49708 KB Output is correct
41 Correct 1612 ms 49708 KB Output is correct
42 Correct 1619 ms 49708 KB Output is correct
43 Correct 1566 ms 49708 KB Output is correct
44 Correct 1600 ms 49708 KB Output is correct
45 Correct 1585 ms 49708 KB Output is correct
46 Correct 1590 ms 49784 KB Output is correct
47 Correct 1602 ms 49708 KB Output is correct
48 Correct 1565 ms 49700 KB Output is correct
49 Correct 1558 ms 49708 KB Output is correct
50 Correct 1555 ms 49720 KB Output is correct
51 Correct 1577 ms 49708 KB Output is correct
52 Correct 1658 ms 49760 KB Output is correct
53 Correct 1619 ms 49708 KB Output is correct
54 Correct 1572 ms 49964 KB Output is correct
55 Correct 1642 ms 49708 KB Output is correct
56 Correct 1643 ms 49836 KB Output is correct
57 Correct 1707 ms 49708 KB Output is correct
58 Correct 1671 ms 49708 KB Output is correct
59 Correct 1600 ms 49708 KB Output is correct
60 Correct 1612 ms 49708 KB Output is correct
61 Correct 1610 ms 49708 KB Output is correct
62 Correct 1689 ms 49904 KB Output is correct
63 Correct 1604 ms 49756 KB Output is correct
64 Correct 1607 ms 49708 KB Output is correct
65 Correct 1632 ms 49712 KB Output is correct
66 Correct 1634 ms 49856 KB Output is correct
67 Correct 1712 ms 49708 KB Output is correct
68 Correct 1619 ms 49708 KB Output is correct
69 Correct 1618 ms 49708 KB Output is correct
70 Correct 1605 ms 49708 KB Output is correct
71 Correct 1606 ms 49708 KB Output is correct
72 Correct 1642 ms 49708 KB Output is correct
73 Correct 1613 ms 49708 KB Output is correct
74 Correct 1614 ms 49708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 704 KB Output is correct
2 Correct 1 ms 704 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 832 KB Output is correct
5 Correct 1 ms 704 KB Output is correct
6 Correct 1 ms 704 KB Output is correct
7 Correct 1 ms 704 KB Output is correct
8 Correct 1 ms 704 KB Output is correct
9 Correct 1 ms 704 KB Output is correct
10 Correct 1 ms 704 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 704 KB Output is correct
17 Correct 5 ms 704 KB Output is correct
18 Correct 5 ms 704 KB Output is correct
19 Correct 5 ms 704 KB Output is correct
20 Correct 5 ms 704 KB Output is correct
21 Correct 4 ms 704 KB Output is correct
22 Correct 4 ms 704 KB Output is correct
23 Correct 4 ms 704 KB Output is correct
24 Correct 4 ms 704 KB Output is correct
25 Correct 5 ms 704 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 4 ms 704 KB Output is correct
37 Correct 4 ms 704 KB Output is correct
38 Correct 4 ms 704 KB Output is correct
39 Correct 4 ms 704 KB Output is correct
40 Correct 4 ms 704 KB Output is correct
41 Correct 4 ms 704 KB Output is correct
42 Correct 5 ms 704 KB Output is correct
43 Correct 4 ms 704 KB Output is correct
44 Correct 4 ms 704 KB Output is correct
45 Correct 4 ms 704 KB Output is correct
46 Correct 4 ms 704 KB Output is correct
47 Correct 4 ms 640 KB Output is correct
48 Correct 1664 ms 49836 KB Output is correct
49 Correct 1682 ms 49780 KB Output is correct
50 Correct 1674 ms 49708 KB Output is correct
51 Correct 1659 ms 49760 KB Output is correct
52 Correct 1620 ms 49800 KB Output is correct
53 Correct 1605 ms 49784 KB Output is correct
54 Correct 1614 ms 49708 KB Output is correct
55 Correct 1605 ms 49708 KB Output is correct
56 Correct 1612 ms 49708 KB Output is correct
57 Correct 1619 ms 49708 KB Output is correct
58 Correct 1566 ms 49708 KB Output is correct
59 Correct 1600 ms 49708 KB Output is correct
60 Correct 1585 ms 49708 KB Output is correct
61 Correct 1590 ms 49784 KB Output is correct
62 Correct 1602 ms 49708 KB Output is correct
63 Correct 1565 ms 49700 KB Output is correct
64 Correct 1558 ms 49708 KB Output is correct
65 Correct 1555 ms 49720 KB Output is correct
66 Correct 1577 ms 49708 KB Output is correct
67 Correct 1658 ms 49760 KB Output is correct
68 Correct 1619 ms 49708 KB Output is correct
69 Correct 1572 ms 49964 KB Output is correct
70 Correct 1642 ms 49708 KB Output is correct
71 Correct 1643 ms 49836 KB Output is correct
72 Correct 1707 ms 49708 KB Output is correct
73 Correct 1671 ms 49708 KB Output is correct
74 Correct 1600 ms 49708 KB Output is correct
75 Correct 1612 ms 49708 KB Output is correct
76 Correct 1610 ms 49708 KB Output is correct
77 Correct 1689 ms 49904 KB Output is correct
78 Correct 1604 ms 49756 KB Output is correct
79 Correct 1607 ms 49708 KB Output is correct
80 Correct 1632 ms 49712 KB Output is correct
81 Correct 1634 ms 49856 KB Output is correct
82 Correct 1712 ms 49708 KB Output is correct
83 Correct 1619 ms 49708 KB Output is correct
84 Correct 1618 ms 49708 KB Output is correct
85 Correct 1605 ms 49708 KB Output is correct
86 Correct 1606 ms 49708 KB Output is correct
87 Correct 1642 ms 49708 KB Output is correct
88 Correct 1613 ms 49708 KB Output is correct
89 Correct 1614 ms 49708 KB Output is correct
90 Correct 1660 ms 49720 KB Output is correct
91 Correct 1630 ms 49708 KB Output is correct
92 Correct 1605 ms 49776 KB Output is correct
93 Correct 1634 ms 49836 KB Output is correct
94 Correct 1634 ms 49932 KB Output is correct
95 Correct 1611 ms 49764 KB Output is correct
96 Correct 1606 ms 49708 KB Output is correct
97 Correct 1604 ms 49708 KB Output is correct
98 Correct 1594 ms 49792 KB Output is correct
99 Correct 1654 ms 49708 KB Output is correct
100 Correct 845 ms 49708 KB Output is correct
101 Correct 824 ms 49708 KB Output is correct
102 Correct 819 ms 49788 KB Output is correct
103 Correct 819 ms 49708 KB Output is correct
104 Correct 845 ms 49712 KB Output is correct
105 Correct 1059 ms 49708 KB Output is correct
106 Correct 1041 ms 49848 KB Output is correct
107 Correct 1040 ms 49708 KB Output is correct
108 Correct 1063 ms 49708 KB Output is correct
109 Correct 1037 ms 49708 KB Output is correct
110 Correct 1029 ms 49708 KB Output is correct
111 Correct 1030 ms 49740 KB Output is correct
112 Correct 1036 ms 49836 KB Output is correct
113 Correct 1030 ms 50000 KB Output is correct
114 Correct 1053 ms 49832 KB Output is correct
115 Correct 1037 ms 49848 KB Output is correct
116 Correct 1042 ms 49708 KB Output is correct
117 Correct 1037 ms 49716 KB Output is correct
118 Correct 1044 ms 49708 KB Output is correct
119 Correct 1028 ms 49708 KB Output is correct
120 Correct 0 ms 384 KB Output is correct
121 Correct 1 ms 384 KB Output is correct
122 Correct 1452 ms 49708 KB Output is correct
123 Correct 1470 ms 49740 KB Output is correct
124 Correct 1443 ms 49708 KB Output is correct
125 Correct 1469 ms 49836 KB Output is correct
126 Correct 1465 ms 49840 KB Output is correct
127 Correct 1449 ms 49756 KB Output is correct
128 Correct 1449 ms 49708 KB Output is correct
129 Correct 1466 ms 49708 KB Output is correct
130 Correct 1541 ms 49708 KB Output is correct
131 Correct 1489 ms 49836 KB Output is correct
132 Correct 1484 ms 49712 KB Output is correct
133 Correct 1540 ms 49700 KB Output is correct