Submission #64282

# Submission time Handle Problem Language Result Execution time Memory
64282 2018-08-03T22:27:17 Z FLDutchman Bulldozer (JOI17_bulldozer) C++14
100 / 100
1149 ms 132288 KB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

struct point{
    int x, y, w, i; 
    const bool operator< (const point &p){
        return mp(x, y) < mp(p.x, p.y);
    }
};

int N;
vector<point> pts;
vi position;

struct event{
    int i, j;
    int x1, y1, x2, y2;
    int dx, dy;
    event(int a, int b) : i(a), j(b) {
        if(pts[j].x < pts[i].x) swap(i, j);
        x1 = pts[i].x, y1 = pts[i].y;
        x2 = pts[j].x, y2 = pts[j].y;
        dx = x2 - x1;
        dy = y2 - y1;
    }

    event(){}

    friend bool operator< ( const event &e1, const event &e2){
        int s = e1.dy * e2.dx - e2.dy * e1.dx;
        if(s != 0) return s < 0;
        return e1.dx * (e1.y1 - e2.y1) + e1.dy * (e2.x1 - e1.x1) < 0;
    }
};

bool par(const event &e1, const event &e2){
    return  e1.dy * e2.dx == e2.dy * e1.dx;
}

bool col(const event &e1, const event &e2){
    return !(e1 < e2) and !(e2 < e1);
}

vi tsum, tmin, tmax, tbest;

void update(int n){
    int l = n<<1, r = l|1;
    tsum[n] = tsum[l] + tsum[r];
    tmin[n] = min(tmin[l], tsum[l] + tmin[r]);
    tmax[n] = max(tmax[l], tsum[l] + tmax[r]);
    tbest[n] = max(tsum[l] + tmax[r] - tmin[l], max(tbest[l], tbest[r]));
}

void buildtree(int lb, int rb, int n = 1){
    if(lb+1 == rb) {
        int w = pts[lb].w;
        tsum[n] = w;
        tmin[n] = min(0LL, w);
        tbest[n] = tmax[n] = max(0LL, w);
    } else {
        int mb = (lb+rb)/2;
        buildtree(lb, mb, n<<1);
        buildtree(mb, rb, n<<1|1);
        update(n);
    }
}

void modify(int i, int w, int lb, int rb, int n = 1){
    if(lb+1 == rb){
        tsum[n] = w;
        tmin[n] = min(0LL, w);
        tbest[n] = tmax[n] = max(0LL, w);
    } else {
        int mb = (lb+rb)/2;
        if(i < mb) modify(i, w, lb, mb, n<<1);
        else modify(i, w, mb, rb, n<<1|1);
        update(n);
    }
}

int getbest(){
    return tbest[1];
}
/*
int ms(){
    using namespace std::chrono;
    int m = duration_cast< milliseconds >(
        system_clock::now().time_since_epoch()
    ).count();
    return m;
}*/

vector<event> events;

//int t0;
signed main(){
    //t0 = ms();
    fast_io();
    cin >> N;
    tmin.assign(4*N, 0);
    tmax.assign(4*N, 0);
    tsum.assign(4*N, 0);
    tbest.assign(4*N, 0);
    position.assign(N, 0);
    FOR(i, 0, N){
        int x,y,w;
        cin >> x >> y >> w;
        pts.pb({x, y, w, y});
    }
    /*int t = ms();
    cout << "Reading " << t - t0 << endl;
    t0 = t;*/
    sort(pts.begin(), pts.end());
    /*t = ms();
    cout << "Sorting points " << t - t0 << endl;
    t0 = t;*/
    FOR(i, 0, N) pts[i].i = i;
    FOR(i, 0, N) position[pts[i].i] = i;
    buildtree(0, N);
    FOR(i, 0, N) FOR(j, i+1, N) events.pb(event(i, j));
    sort(events.begin(), events.end());
    /*t = ms();
    cout << "Sorting events " << t - t0 << endl;
    t0 = t;
    */
    // each block contains parallel events

    //cout << "Sorted events" << endl;

    int l = N, r = 0;
    int best = getbest();
    FOR(i, 0, events.size()){
        if(i == events.size() || !col(events[i], events[i-1])) {
            for(int i = l, j = r; i < j; i++, j--){
                // positions in 
                int p1 = pts[i].i, p2 = pts[j].i;
                swap(position[p1], position[p2]);
                int w1 = pts[i].w, w2 = pts[j].w;
                modify(i, w2, 0, N);
                modify(j, w1, 0, N);
                swap(pts[i], pts[j]);
            }
            l = N, r= 0;
        } 
        if(i == events.size() || !par(events[i], events[i-1])) {
            best = max(best, getbest());
        }   
        auto &e = events[i];
        l = min(l, position[e.i]), l = min(l, position[e.j]), r = max(r, position[e.i]), r = max(r, position[e.j]);
    }
    /*
    t = ms();
    cout << "Preparing events " << t - t0 << endl;
    t0 = t;
    */
    /*
    int best = getbest();
    for( auto &pars : blocks) {
       // cout << "pars size " << pars.size() << endl; 
        for(auto &cols : pars){
            //cout << "cols size " << cols.size() << endl;
            int l = N, r = 0;
            for(event *e : cols) l = min(l, position[e->i]), l = min(l, position[e->j]), r = max(r, position[e->i]), r = max(r, position[e->j]);
            // swap [l, r]
            //cout << "swapping " << l << " " << r << endl;
            for(int i = l, j = r; i < j; i++, j--){
                // positions in 
                int p1 = pts[i].i, p2 = pts[j].i;
                swap(position[p1], position[p2]);
                int w1 = pts[i].w, w2 = pts[j].w;
                modify(i, w2, 0, N);
                modify(j, w1, 0, N);
                swap(pts[i], pts[j]);
            }
        }
        best = max(best, getbest());
    }
    */
    /*
    t = ms();
    cout << "Swapping " << t - t0 << endl;
    t0 = t;*/
    cout << best << endl;
}


/*
5
-5 5 -2
2 5 10
1 4 -2
4 -5 4
-2 2 7



*/

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:10:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, l, r) for(int i = (l); i < (r); i++)
                                         ^
bulldozer.cpp:155:5: note: in expansion of macro 'FOR'
     FOR(i, 0, events.size()){
     ^~~
bulldozer.cpp:156:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i == events.size() || !col(events[i], events[i-1])) {
            ~~^~~~~~~~~~~~~~~~
bulldozer.cpp:168:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i == events.size() || !par(events[i], events[i-1])) {
            ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1028 KB Output is correct
2 Correct 3 ms 1028 KB Output is correct
3 Correct 3 ms 1028 KB Output is correct
4 Correct 2 ms 1028 KB Output is correct
5 Correct 3 ms 1028 KB Output is correct
6 Correct 3 ms 1028 KB Output is correct
7 Correct 3 ms 1028 KB Output is correct
8 Correct 2 ms 1028 KB Output is correct
9 Correct 3 ms 1028 KB Output is correct
10 Correct 3 ms 1028 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1028 KB Output is correct
2 Correct 4 ms 1028 KB Output is correct
3 Correct 4 ms 1028 KB Output is correct
4 Correct 4 ms 1028 KB Output is correct
5 Correct 4 ms 1028 KB Output is correct
6 Correct 4 ms 1028 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 4 ms 1028 KB Output is correct
10 Correct 4 ms 1028 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 1028 KB Output is correct
22 Correct 4 ms 1028 KB Output is correct
23 Correct 4 ms 1028 KB Output is correct
24 Correct 4 ms 1028 KB Output is correct
25 Correct 4 ms 1028 KB Output is correct
26 Correct 4 ms 1028 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 1028 KB Output is correct
29 Correct 4 ms 1028 KB Output is correct
30 Correct 4 ms 1028 KB Output is correct
31 Correct 4 ms 1028 KB Output is correct
32 Correct 4 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1028 KB Output is correct
2 Correct 4 ms 1028 KB Output is correct
3 Correct 4 ms 1028 KB Output is correct
4 Correct 4 ms 1028 KB Output is correct
5 Correct 4 ms 1028 KB Output is correct
6 Correct 4 ms 1028 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 4 ms 1028 KB Output is correct
10 Correct 4 ms 1028 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 1028 KB Output is correct
22 Correct 4 ms 1028 KB Output is correct
23 Correct 4 ms 1028 KB Output is correct
24 Correct 4 ms 1028 KB Output is correct
25 Correct 4 ms 1028 KB Output is correct
26 Correct 4 ms 1028 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 1028 KB Output is correct
29 Correct 4 ms 1028 KB Output is correct
30 Correct 4 ms 1028 KB Output is correct
31 Correct 4 ms 1028 KB Output is correct
32 Correct 4 ms 1028 KB Output is correct
33 Correct 1149 ms 132080 KB Output is correct
34 Correct 1066 ms 132172 KB Output is correct
35 Correct 1093 ms 132072 KB Output is correct
36 Correct 1064 ms 132180 KB Output is correct
37 Correct 1063 ms 132272 KB Output is correct
38 Correct 1067 ms 132180 KB Output is correct
39 Correct 1087 ms 132152 KB Output is correct
40 Correct 1125 ms 132116 KB Output is correct
41 Correct 1102 ms 132188 KB Output is correct
42 Correct 1082 ms 132180 KB Output is correct
43 Correct 1093 ms 132180 KB Output is correct
44 Correct 1079 ms 132180 KB Output is correct
45 Correct 1058 ms 132180 KB Output is correct
46 Correct 1089 ms 132180 KB Output is correct
47 Correct 1119 ms 132184 KB Output is correct
48 Correct 1090 ms 132180 KB Output is correct
49 Correct 1065 ms 132156 KB Output is correct
50 Correct 1096 ms 132180 KB Output is correct
51 Correct 1076 ms 132096 KB Output is correct
52 Correct 1116 ms 132288 KB Output is correct
53 Correct 1066 ms 132176 KB Output is correct
54 Correct 1090 ms 132188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1028 KB Output is correct
2 Correct 4 ms 1028 KB Output is correct
3 Correct 4 ms 1028 KB Output is correct
4 Correct 4 ms 1028 KB Output is correct
5 Correct 4 ms 1028 KB Output is correct
6 Correct 4 ms 1028 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 4 ms 1028 KB Output is correct
10 Correct 4 ms 1028 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 1028 KB Output is correct
22 Correct 4 ms 1028 KB Output is correct
23 Correct 4 ms 1028 KB Output is correct
24 Correct 4 ms 1028 KB Output is correct
25 Correct 4 ms 1028 KB Output is correct
26 Correct 4 ms 1028 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 1028 KB Output is correct
29 Correct 4 ms 1028 KB Output is correct
30 Correct 4 ms 1028 KB Output is correct
31 Correct 4 ms 1028 KB Output is correct
32 Correct 4 ms 1028 KB Output is correct
33 Correct 1149 ms 132080 KB Output is correct
34 Correct 1066 ms 132172 KB Output is correct
35 Correct 1093 ms 132072 KB Output is correct
36 Correct 1064 ms 132180 KB Output is correct
37 Correct 1063 ms 132272 KB Output is correct
38 Correct 1067 ms 132180 KB Output is correct
39 Correct 1087 ms 132152 KB Output is correct
40 Correct 1125 ms 132116 KB Output is correct
41 Correct 1102 ms 132188 KB Output is correct
42 Correct 1082 ms 132180 KB Output is correct
43 Correct 1093 ms 132180 KB Output is correct
44 Correct 1079 ms 132180 KB Output is correct
45 Correct 1058 ms 132180 KB Output is correct
46 Correct 1089 ms 132180 KB Output is correct
47 Correct 1119 ms 132184 KB Output is correct
48 Correct 1090 ms 132180 KB Output is correct
49 Correct 1065 ms 132156 KB Output is correct
50 Correct 1096 ms 132180 KB Output is correct
51 Correct 1076 ms 132096 KB Output is correct
52 Correct 1116 ms 132288 KB Output is correct
53 Correct 1066 ms 132176 KB Output is correct
54 Correct 1090 ms 132188 KB Output is correct
55 Correct 1067 ms 132164 KB Output is correct
56 Correct 1062 ms 132180 KB Output is correct
57 Correct 1114 ms 132168 KB Output is correct
58 Correct 1080 ms 132224 KB Output is correct
59 Correct 1111 ms 132180 KB Output is correct
60 Correct 1118 ms 132180 KB Output is correct
61 Correct 1100 ms 132180 KB Output is correct
62 Correct 1104 ms 132180 KB Output is correct
63 Correct 1094 ms 132180 KB Output is correct
64 Correct 1084 ms 132120 KB Output is correct
65 Correct 1094 ms 132180 KB Output is correct
66 Correct 1087 ms 132184 KB Output is correct
67 Correct 1125 ms 132172 KB Output is correct
68 Correct 1071 ms 132180 KB Output is correct
69 Correct 1055 ms 132224 KB Output is correct
70 Correct 1121 ms 132092 KB Output is correct
71 Correct 1073 ms 132180 KB Output is correct
72 Correct 1077 ms 132180 KB Output is correct
73 Correct 1098 ms 132108 KB Output is correct
74 Correct 1119 ms 132180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1028 KB Output is correct
2 Correct 3 ms 1028 KB Output is correct
3 Correct 3 ms 1028 KB Output is correct
4 Correct 2 ms 1028 KB Output is correct
5 Correct 3 ms 1028 KB Output is correct
6 Correct 3 ms 1028 KB Output is correct
7 Correct 3 ms 1028 KB Output is correct
8 Correct 2 ms 1028 KB Output is correct
9 Correct 3 ms 1028 KB Output is correct
10 Correct 3 ms 1028 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 4 ms 1028 KB Output is correct
17 Correct 4 ms 1028 KB Output is correct
18 Correct 4 ms 1028 KB Output is correct
19 Correct 4 ms 1028 KB Output is correct
20 Correct 4 ms 1028 KB Output is correct
21 Correct 4 ms 1028 KB Output is correct
22 Correct 4 ms 1028 KB Output is correct
23 Correct 4 ms 1028 KB Output is correct
24 Correct 4 ms 1028 KB Output is correct
25 Correct 4 ms 1028 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 4 ms 1028 KB Output is correct
37 Correct 4 ms 1028 KB Output is correct
38 Correct 4 ms 1028 KB Output is correct
39 Correct 4 ms 1028 KB Output is correct
40 Correct 4 ms 1028 KB Output is correct
41 Correct 4 ms 1028 KB Output is correct
42 Correct 4 ms 1028 KB Output is correct
43 Correct 4 ms 1028 KB Output is correct
44 Correct 4 ms 1028 KB Output is correct
45 Correct 4 ms 1028 KB Output is correct
46 Correct 4 ms 1028 KB Output is correct
47 Correct 4 ms 1028 KB Output is correct
48 Correct 1149 ms 132080 KB Output is correct
49 Correct 1066 ms 132172 KB Output is correct
50 Correct 1093 ms 132072 KB Output is correct
51 Correct 1064 ms 132180 KB Output is correct
52 Correct 1063 ms 132272 KB Output is correct
53 Correct 1067 ms 132180 KB Output is correct
54 Correct 1087 ms 132152 KB Output is correct
55 Correct 1125 ms 132116 KB Output is correct
56 Correct 1102 ms 132188 KB Output is correct
57 Correct 1082 ms 132180 KB Output is correct
58 Correct 1093 ms 132180 KB Output is correct
59 Correct 1079 ms 132180 KB Output is correct
60 Correct 1058 ms 132180 KB Output is correct
61 Correct 1089 ms 132180 KB Output is correct
62 Correct 1119 ms 132184 KB Output is correct
63 Correct 1090 ms 132180 KB Output is correct
64 Correct 1065 ms 132156 KB Output is correct
65 Correct 1096 ms 132180 KB Output is correct
66 Correct 1076 ms 132096 KB Output is correct
67 Correct 1116 ms 132288 KB Output is correct
68 Correct 1066 ms 132176 KB Output is correct
69 Correct 1090 ms 132188 KB Output is correct
70 Correct 1067 ms 132164 KB Output is correct
71 Correct 1062 ms 132180 KB Output is correct
72 Correct 1114 ms 132168 KB Output is correct
73 Correct 1080 ms 132224 KB Output is correct
74 Correct 1111 ms 132180 KB Output is correct
75 Correct 1118 ms 132180 KB Output is correct
76 Correct 1100 ms 132180 KB Output is correct
77 Correct 1104 ms 132180 KB Output is correct
78 Correct 1094 ms 132180 KB Output is correct
79 Correct 1084 ms 132120 KB Output is correct
80 Correct 1094 ms 132180 KB Output is correct
81 Correct 1087 ms 132184 KB Output is correct
82 Correct 1125 ms 132172 KB Output is correct
83 Correct 1071 ms 132180 KB Output is correct
84 Correct 1055 ms 132224 KB Output is correct
85 Correct 1121 ms 132092 KB Output is correct
86 Correct 1073 ms 132180 KB Output is correct
87 Correct 1077 ms 132180 KB Output is correct
88 Correct 1098 ms 132108 KB Output is correct
89 Correct 1119 ms 132180 KB Output is correct
90 Correct 1133 ms 132140 KB Output is correct
91 Correct 1077 ms 132128 KB Output is correct
92 Correct 1110 ms 132140 KB Output is correct
93 Correct 1093 ms 132092 KB Output is correct
94 Correct 1088 ms 132128 KB Output is correct
95 Correct 1108 ms 132176 KB Output is correct
96 Correct 1110 ms 132280 KB Output is correct
97 Correct 1132 ms 132180 KB Output is correct
98 Correct 1099 ms 132096 KB Output is correct
99 Correct 1084 ms 132096 KB Output is correct
100 Correct 722 ms 132124 KB Output is correct
101 Correct 742 ms 132232 KB Output is correct
102 Correct 734 ms 132180 KB Output is correct
103 Correct 723 ms 132180 KB Output is correct
104 Correct 739 ms 132160 KB Output is correct
105 Correct 853 ms 132168 KB Output is correct
106 Correct 856 ms 132180 KB Output is correct
107 Correct 872 ms 132152 KB Output is correct
108 Correct 879 ms 132152 KB Output is correct
109 Correct 896 ms 132180 KB Output is correct
110 Correct 892 ms 132180 KB Output is correct
111 Correct 933 ms 132184 KB Output is correct
112 Correct 896 ms 132144 KB Output is correct
113 Correct 896 ms 132136 KB Output is correct
114 Correct 897 ms 132180 KB Output is correct
115 Correct 898 ms 132108 KB Output is correct
116 Correct 979 ms 132172 KB Output is correct
117 Correct 891 ms 132180 KB Output is correct
118 Correct 880 ms 132180 KB Output is correct
119 Correct 867 ms 132180 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1115 ms 132156 KB Output is correct
123 Correct 1105 ms 132104 KB Output is correct
124 Correct 1144 ms 132180 KB Output is correct
125 Correct 1116 ms 132180 KB Output is correct
126 Correct 1067 ms 132180 KB Output is correct
127 Correct 1100 ms 132180 KB Output is correct
128 Correct 1090 ms 132180 KB Output is correct
129 Correct 1090 ms 132160 KB Output is correct
130 Correct 1065 ms 132176 KB Output is correct
131 Correct 1086 ms 132180 KB Output is correct
132 Correct 1116 ms 132180 KB Output is correct
133 Correct 1105 ms 132180 KB Output is correct