Submission #64274

# Submission time Handle Problem Language Result Execution time Memory
64274 2018-08-03T21:48:48 Z FLDutchman Bulldozer (JOI17_bulldozer) C++14
100 / 100
1685 ms 267008 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 dx, dy;
    event(int a, int b) : i(a), j(b) {
        if(pts[j].x < pts[i].x) swap(i, j);
        dx = pts[j].x - pts[i].x;
        dy = pts[j].y - pts[i].y;
    }

    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 * (pts[position[e1.i]].y - pts[position[e2.i]].y) + e1.dy * (pts[position[e2.i]].x - pts[position[e1.i]].x) < 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);
        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];
}

vector<event> events;

signed main(){
    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});
    }
    sort(pts.begin(), pts.end());
    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());
    // each block contains parallel events

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

    vector<vector<vector<event>>> blocks;
    FOR(i, 0, events.size()){
        if(i == 0 || !par(events[i], events[i-1])) blocks.pb(  vector<vector<event>>(0));
        if(i == 0 || !col(events[i], events[i-1])) blocks.back().pb(vector<event>(0));
        blocks.back().back().pb(events[i]);
    }

    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());
    }
    cout << best << endl;
}

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:131:5: note: in expansion of macro 'FOR'
     FOR(i, 0, events.size()){
     ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 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 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 1072 KB Output is correct
5 Correct 5 ms 1028 KB Output is correct
6 Correct 5 ms 1076 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 5 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 2 ms 356 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 1028 KB Output is correct
22 Correct 5 ms 1028 KB Output is correct
23 Correct 5 ms 1028 KB Output is correct
24 Correct 5 ms 1028 KB Output is correct
25 Correct 5 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 5 ms 1028 KB Output is correct
29 Correct 5 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 5 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 1072 KB Output is correct
5 Correct 5 ms 1028 KB Output is correct
6 Correct 5 ms 1076 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 5 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 2 ms 356 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 1028 KB Output is correct
22 Correct 5 ms 1028 KB Output is correct
23 Correct 5 ms 1028 KB Output is correct
24 Correct 5 ms 1028 KB Output is correct
25 Correct 5 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 5 ms 1028 KB Output is correct
29 Correct 5 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 5 ms 1028 KB Output is correct
33 Correct 1572 ms 266800 KB Output is correct
34 Correct 1523 ms 266784 KB Output is correct
35 Correct 1520 ms 266824 KB Output is correct
36 Correct 1520 ms 266824 KB Output is correct
37 Correct 1508 ms 266740 KB Output is correct
38 Correct 1535 ms 266908 KB Output is correct
39 Correct 1533 ms 266840 KB Output is correct
40 Correct 1527 ms 266748 KB Output is correct
41 Correct 1656 ms 266892 KB Output is correct
42 Correct 1574 ms 266916 KB Output is correct
43 Correct 1539 ms 266800 KB Output is correct
44 Correct 1529 ms 266804 KB Output is correct
45 Correct 1514 ms 266932 KB Output is correct
46 Correct 1587 ms 266696 KB Output is correct
47 Correct 1561 ms 266768 KB Output is correct
48 Correct 1512 ms 266664 KB Output is correct
49 Correct 1513 ms 266820 KB Output is correct
50 Correct 1510 ms 266768 KB Output is correct
51 Correct 1551 ms 266920 KB Output is correct
52 Correct 1590 ms 266920 KB Output is correct
53 Correct 1584 ms 266792 KB Output is correct
54 Correct 1591 ms 266664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 1072 KB Output is correct
5 Correct 5 ms 1028 KB Output is correct
6 Correct 5 ms 1076 KB Output is correct
7 Correct 4 ms 1028 KB Output is correct
8 Correct 5 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 2 ms 356 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 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 1028 KB Output is correct
22 Correct 5 ms 1028 KB Output is correct
23 Correct 5 ms 1028 KB Output is correct
24 Correct 5 ms 1028 KB Output is correct
25 Correct 5 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 5 ms 1028 KB Output is correct
29 Correct 5 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 5 ms 1028 KB Output is correct
33 Correct 1572 ms 266800 KB Output is correct
34 Correct 1523 ms 266784 KB Output is correct
35 Correct 1520 ms 266824 KB Output is correct
36 Correct 1520 ms 266824 KB Output is correct
37 Correct 1508 ms 266740 KB Output is correct
38 Correct 1535 ms 266908 KB Output is correct
39 Correct 1533 ms 266840 KB Output is correct
40 Correct 1527 ms 266748 KB Output is correct
41 Correct 1656 ms 266892 KB Output is correct
42 Correct 1574 ms 266916 KB Output is correct
43 Correct 1539 ms 266800 KB Output is correct
44 Correct 1529 ms 266804 KB Output is correct
45 Correct 1514 ms 266932 KB Output is correct
46 Correct 1587 ms 266696 KB Output is correct
47 Correct 1561 ms 266768 KB Output is correct
48 Correct 1512 ms 266664 KB Output is correct
49 Correct 1513 ms 266820 KB Output is correct
50 Correct 1510 ms 266768 KB Output is correct
51 Correct 1551 ms 266920 KB Output is correct
52 Correct 1590 ms 266920 KB Output is correct
53 Correct 1584 ms 266792 KB Output is correct
54 Correct 1591 ms 266664 KB Output is correct
55 Correct 1562 ms 266756 KB Output is correct
56 Correct 1548 ms 266752 KB Output is correct
57 Correct 1594 ms 266780 KB Output is correct
58 Correct 1561 ms 266780 KB Output is correct
59 Correct 1583 ms 266876 KB Output is correct
60 Correct 1583 ms 266676 KB Output is correct
61 Correct 1565 ms 266888 KB Output is correct
62 Correct 1579 ms 266816 KB Output is correct
63 Correct 1680 ms 266808 KB Output is correct
64 Correct 1569 ms 266780 KB Output is correct
65 Correct 1533 ms 266792 KB Output is correct
66 Correct 1547 ms 266668 KB Output is correct
67 Correct 1543 ms 267008 KB Output is correct
68 Correct 1543 ms 266796 KB Output is correct
69 Correct 1505 ms 266784 KB Output is correct
70 Correct 1520 ms 266992 KB Output is correct
71 Correct 1509 ms 266788 KB Output is correct
72 Correct 1529 ms 266816 KB Output is correct
73 Correct 1548 ms 267008 KB Output is correct
74 Correct 1587 ms 266756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 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 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 5 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 1072 KB Output is correct
20 Correct 5 ms 1028 KB Output is correct
21 Correct 5 ms 1076 KB Output is correct
22 Correct 4 ms 1028 KB Output is correct
23 Correct 5 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 2 ms 356 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 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 5 ms 1028 KB Output is correct
37 Correct 5 ms 1028 KB Output is correct
38 Correct 5 ms 1028 KB Output is correct
39 Correct 5 ms 1028 KB Output is correct
40 Correct 5 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 5 ms 1028 KB Output is correct
44 Correct 5 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 5 ms 1028 KB Output is correct
48 Correct 1572 ms 266800 KB Output is correct
49 Correct 1523 ms 266784 KB Output is correct
50 Correct 1520 ms 266824 KB Output is correct
51 Correct 1520 ms 266824 KB Output is correct
52 Correct 1508 ms 266740 KB Output is correct
53 Correct 1535 ms 266908 KB Output is correct
54 Correct 1533 ms 266840 KB Output is correct
55 Correct 1527 ms 266748 KB Output is correct
56 Correct 1656 ms 266892 KB Output is correct
57 Correct 1574 ms 266916 KB Output is correct
58 Correct 1539 ms 266800 KB Output is correct
59 Correct 1529 ms 266804 KB Output is correct
60 Correct 1514 ms 266932 KB Output is correct
61 Correct 1587 ms 266696 KB Output is correct
62 Correct 1561 ms 266768 KB Output is correct
63 Correct 1512 ms 266664 KB Output is correct
64 Correct 1513 ms 266820 KB Output is correct
65 Correct 1510 ms 266768 KB Output is correct
66 Correct 1551 ms 266920 KB Output is correct
67 Correct 1590 ms 266920 KB Output is correct
68 Correct 1584 ms 266792 KB Output is correct
69 Correct 1591 ms 266664 KB Output is correct
70 Correct 1562 ms 266756 KB Output is correct
71 Correct 1548 ms 266752 KB Output is correct
72 Correct 1594 ms 266780 KB Output is correct
73 Correct 1561 ms 266780 KB Output is correct
74 Correct 1583 ms 266876 KB Output is correct
75 Correct 1583 ms 266676 KB Output is correct
76 Correct 1565 ms 266888 KB Output is correct
77 Correct 1579 ms 266816 KB Output is correct
78 Correct 1680 ms 266808 KB Output is correct
79 Correct 1569 ms 266780 KB Output is correct
80 Correct 1533 ms 266792 KB Output is correct
81 Correct 1547 ms 266668 KB Output is correct
82 Correct 1543 ms 267008 KB Output is correct
83 Correct 1543 ms 266796 KB Output is correct
84 Correct 1505 ms 266784 KB Output is correct
85 Correct 1520 ms 266992 KB Output is correct
86 Correct 1509 ms 266788 KB Output is correct
87 Correct 1529 ms 266816 KB Output is correct
88 Correct 1548 ms 267008 KB Output is correct
89 Correct 1587 ms 266756 KB Output is correct
90 Correct 1595 ms 266812 KB Output is correct
91 Correct 1531 ms 266768 KB Output is correct
92 Correct 1569 ms 266776 KB Output is correct
93 Correct 1553 ms 266736 KB Output is correct
94 Correct 1532 ms 266756 KB Output is correct
95 Correct 1590 ms 266864 KB Output is correct
96 Correct 1577 ms 266792 KB Output is correct
97 Correct 1570 ms 266896 KB Output is correct
98 Correct 1573 ms 266752 KB Output is correct
99 Correct 1685 ms 266800 KB Output is correct
100 Correct 1002 ms 244092 KB Output is correct
101 Correct 954 ms 244692 KB Output is correct
102 Correct 994 ms 246712 KB Output is correct
103 Correct 999 ms 244228 KB Output is correct
104 Correct 953 ms 244280 KB Output is correct
105 Correct 1147 ms 250224 KB Output is correct
106 Correct 1167 ms 250864 KB Output is correct
107 Correct 1145 ms 251192 KB Output is correct
108 Correct 1138 ms 250724 KB Output is correct
109 Correct 1149 ms 249920 KB Output is correct
110 Correct 1127 ms 214092 KB Output is correct
111 Correct 1115 ms 214208 KB Output is correct
112 Correct 1149 ms 214116 KB Output is correct
113 Correct 1103 ms 214140 KB Output is correct
114 Correct 1122 ms 214096 KB Output is correct
115 Correct 1162 ms 214104 KB Output is correct
116 Correct 1098 ms 213908 KB Output is correct
117 Correct 1115 ms 214088 KB Output is correct
118 Correct 1122 ms 214124 KB Output is correct
119 Correct 1140 ms 214116 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 1592 ms 259408 KB Output is correct
123 Correct 1578 ms 259268 KB Output is correct
124 Correct 1649 ms 259356 KB Output is correct
125 Correct 1551 ms 262160 KB Output is correct
126 Correct 1544 ms 262236 KB Output is correct
127 Correct 1562 ms 262256 KB Output is correct
128 Correct 1531 ms 262300 KB Output is correct
129 Correct 1566 ms 262288 KB Output is correct
130 Correct 1601 ms 262204 KB Output is correct
131 Correct 1524 ms 265940 KB Output is correct
132 Correct 1525 ms 266004 KB Output is correct
133 Correct 1513 ms 266076 KB Output is correct