Submission #60400

# Submission time Handle Problem Language Result Execution time Memory
60400 2018-07-24T05:30:40 Z Benq Bulldozer (JOI17_bulldozer) C++11
100 / 100
1256 ms 37576 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2000;

int ad(int a, int b) { return a+b; }
int sub(int a, int b) { return a-b; }

pi operator+(const pi& l, const pi& r) { return {ad(l.f,r.f),ad(l.s,r.s)}; }
pi operator-(const pi& l, const pi& r) { return {sub(l.f,r.f),sub(l.s,r.s)}; }
pi operator+=(pi& l, const pi& r) { return l = l+r; }
pi operator-=(pi& l, const pi& r) { return l = l-r; }

int N;
pair<pi,int> A[MX];
bool done[MX][MX];
vector<pair<pi,pi>> al;
ll ans = 0;

struct node {
    ll sum,mn,mx,ans;
    node(int w) {
        sum = w;
        mn = min(0,w);
        mx = ans = max(0,w);
    }
    node(): node(0) {}
};

node comb(const node& l, const node& r) {
    node res(0);
    res.ans = max(max(l.ans,r.ans),l.sum+r.mx-l.mn);
    res.mn = min(l.sum+r.mn,l.mn);
    res.mx = max(l.sum+r.mx,l.mx);
    res.sum = l.sum+r.sum;
    return res;
};

struct Seg {
    int ind[2000], rind[2000];
    node seg[4096];
    
    void init() {
        F0R(i,N) {
            rind[i] = ind[i] = i;
            seg[i^(1<<11)] = node(A[i].s);
        }
        FORd(i,1,1<<11) seg[i] = comb(seg[2*i],seg[2*i+1]);
    }
    
    void upd(int ind) {
        ind ^= (1<<11);
        for (ind /= 2; ind; ind /= 2) seg[ind] = comb(seg[2*ind],seg[2*ind+1]);
    }
    
    void flip(pi v) {
        int mn = MOD, mx = -MOD;
        mn = min(mn,ind[v.f]), mx = max(mx,ind[v.f]);
        mn = min(mn,ind[v.s]), mx = max(mx,ind[v.s]);
        // assert(mx-mn+1 == sz(v));
        
        // cout << "OH " << mn << " " << mx << " " << seg[1].ans << "\n";
        for (int i = mn; i < mx+mn-i; ++i) {
            swap(seg[i^(1<<11)],seg[(mx+mn-i)^(1<<11)]);
            swap(rind[i],rind[mx+mn-i]);
            swap(ind[rind[i]],ind[rind[mx+mn-i]]);
            upd(i); upd(mx+mn-i);
        }
    }
};

Seg S;

void ins(vi v) {
    F0R(i,sz(v)) FOR(j,i+1,sz(v)) done[v[i]][v[j]] = done[v[j]][v[i]] = 1;
    al.pb({A[v[1]].f-A[v[0]].f,{v[0],v.back()}});
}

ll cross(pi b, pi c) {
    return (ll)b.f*c.s-(ll)b.s*c.f;
}

ll cross(pi a, pi b, pi c) { return cross(b-a,c-a); }

bool cmp(pi a, pi b) { return cross(a,b) > 0; }

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N) {
        cin >> A[i].f.f >> A[i].f.s >> A[i].s;
        //A[i].f.f = rand()%MOD;
        //A[i].f.s = rand()%MOD;
        //A[i].s = rand()%MOD;
    }
    if (N == 1) {
        cout << max(0,A[0].s);
        exit(0);
    }
    
    sort(A,A+N,[](pair<pi,int> x, pair<pi,int> y) {
        if (x.f.s != y.f.s) return x.f.s < y.f.s;
        return x.f.f < y.f.f;
    });
    S.init();
    
    F0R(i,N) {
        vi v; FOR(j,i+1,N) v.pb(j);
        sort(all(v),[&i](int a, int b) { 
            ll t = cross(A[i].f,A[a].f,A[b].f);
            if (t != 0) return t > 0;
            return a < b;
        });
        for (int ind = 0; ind < sz(v); ) {
            if (done[i][v[ind]]) {
                ind ++;
                continue;
            }
            int IND = ind;
            vi tmp = {i};
            while (ind < sz(v) && cross(A[i].f,A[v[IND]].f,A[v[ind]].f) == 0) tmp.pb(v[ind++]);
            ins(tmp);
        }
    }
    
    sort(all(al), [](const pair<pi,pi>& a, const pair<pi,pi>& b) { return cmp(a.f,b.f); });
    for (int i = 0; i < sz(al); ) {
        int I = i;
        while (i < sz(al) && cross(al[I].f,al[i].f) == 0) S.flip(al[i++].s);
        ans = max(ans,S.seg[1].ans);
    }
    cout << ans;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 428 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 4 ms 940 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 5 ms 868 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 5 ms 944 KB Output is correct
24 Correct 5 ms 940 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 868 KB Output is correct
31 Correct 5 ms 896 KB Output is correct
32 Correct 5 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 4 ms 940 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 5 ms 868 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 5 ms 944 KB Output is correct
24 Correct 5 ms 940 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 868 KB Output is correct
31 Correct 5 ms 896 KB Output is correct
32 Correct 5 ms 940 KB Output is correct
33 Correct 1156 ms 37364 KB Output is correct
34 Correct 1178 ms 37392 KB Output is correct
35 Correct 1226 ms 37408 KB Output is correct
36 Correct 1140 ms 37540 KB Output is correct
37 Correct 1127 ms 37444 KB Output is correct
38 Correct 1143 ms 37408 KB Output is correct
39 Correct 1177 ms 37452 KB Output is correct
40 Correct 1162 ms 37336 KB Output is correct
41 Correct 1151 ms 37400 KB Output is correct
42 Correct 1162 ms 37328 KB Output is correct
43 Correct 1183 ms 37408 KB Output is correct
44 Correct 1167 ms 37444 KB Output is correct
45 Correct 1184 ms 37576 KB Output is correct
46 Correct 1168 ms 37440 KB Output is correct
47 Correct 1203 ms 37440 KB Output is correct
48 Correct 1178 ms 37532 KB Output is correct
49 Correct 1168 ms 37392 KB Output is correct
50 Correct 1172 ms 37536 KB Output is correct
51 Correct 1219 ms 37424 KB Output is correct
52 Correct 1185 ms 37364 KB Output is correct
53 Correct 1196 ms 37400 KB Output is correct
54 Correct 1151 ms 37540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 4 ms 896 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 4 ms 940 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 484 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 5 ms 868 KB Output is correct
22 Correct 4 ms 896 KB Output is correct
23 Correct 5 ms 944 KB Output is correct
24 Correct 5 ms 940 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 4 ms 896 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 4 ms 896 KB Output is correct
30 Correct 4 ms 868 KB Output is correct
31 Correct 5 ms 896 KB Output is correct
32 Correct 5 ms 940 KB Output is correct
33 Correct 1156 ms 37364 KB Output is correct
34 Correct 1178 ms 37392 KB Output is correct
35 Correct 1226 ms 37408 KB Output is correct
36 Correct 1140 ms 37540 KB Output is correct
37 Correct 1127 ms 37444 KB Output is correct
38 Correct 1143 ms 37408 KB Output is correct
39 Correct 1177 ms 37452 KB Output is correct
40 Correct 1162 ms 37336 KB Output is correct
41 Correct 1151 ms 37400 KB Output is correct
42 Correct 1162 ms 37328 KB Output is correct
43 Correct 1183 ms 37408 KB Output is correct
44 Correct 1167 ms 37444 KB Output is correct
45 Correct 1184 ms 37576 KB Output is correct
46 Correct 1168 ms 37440 KB Output is correct
47 Correct 1203 ms 37440 KB Output is correct
48 Correct 1178 ms 37532 KB Output is correct
49 Correct 1168 ms 37392 KB Output is correct
50 Correct 1172 ms 37536 KB Output is correct
51 Correct 1219 ms 37424 KB Output is correct
52 Correct 1185 ms 37364 KB Output is correct
53 Correct 1196 ms 37400 KB Output is correct
54 Correct 1151 ms 37540 KB Output is correct
55 Correct 1135 ms 37364 KB Output is correct
56 Correct 1160 ms 37348 KB Output is correct
57 Correct 1179 ms 37420 KB Output is correct
58 Correct 1165 ms 37480 KB Output is correct
59 Correct 1153 ms 37460 KB Output is correct
60 Correct 1171 ms 37356 KB Output is correct
61 Correct 1144 ms 37468 KB Output is correct
62 Correct 1149 ms 37496 KB Output is correct
63 Correct 1140 ms 37436 KB Output is correct
64 Correct 1147 ms 37432 KB Output is correct
65 Correct 1129 ms 37520 KB Output is correct
66 Correct 1127 ms 37440 KB Output is correct
67 Correct 1173 ms 37440 KB Output is correct
68 Correct 1200 ms 37372 KB Output is correct
69 Correct 1178 ms 37352 KB Output is correct
70 Correct 1200 ms 37424 KB Output is correct
71 Correct 1194 ms 37408 KB Output is correct
72 Correct 1181 ms 37416 KB Output is correct
73 Correct 1200 ms 37396 KB Output is correct
74 Correct 1181 ms 37376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 428 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 4 ms 868 KB Output is correct
18 Correct 5 ms 896 KB Output is correct
19 Correct 4 ms 896 KB Output is correct
20 Correct 4 ms 896 KB Output is correct
21 Correct 5 ms 896 KB Output is correct
22 Correct 5 ms 896 KB Output is correct
23 Correct 4 ms 940 KB Output is correct
24 Correct 5 ms 896 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 2 ms 484 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 484 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 5 ms 868 KB Output is correct
37 Correct 4 ms 896 KB Output is correct
38 Correct 5 ms 944 KB Output is correct
39 Correct 5 ms 940 KB Output is correct
40 Correct 4 ms 896 KB Output is correct
41 Correct 4 ms 896 KB Output is correct
42 Correct 4 ms 896 KB Output is correct
43 Correct 5 ms 896 KB Output is correct
44 Correct 4 ms 896 KB Output is correct
45 Correct 4 ms 868 KB Output is correct
46 Correct 5 ms 896 KB Output is correct
47 Correct 5 ms 940 KB Output is correct
48 Correct 1156 ms 37364 KB Output is correct
49 Correct 1178 ms 37392 KB Output is correct
50 Correct 1226 ms 37408 KB Output is correct
51 Correct 1140 ms 37540 KB Output is correct
52 Correct 1127 ms 37444 KB Output is correct
53 Correct 1143 ms 37408 KB Output is correct
54 Correct 1177 ms 37452 KB Output is correct
55 Correct 1162 ms 37336 KB Output is correct
56 Correct 1151 ms 37400 KB Output is correct
57 Correct 1162 ms 37328 KB Output is correct
58 Correct 1183 ms 37408 KB Output is correct
59 Correct 1167 ms 37444 KB Output is correct
60 Correct 1184 ms 37576 KB Output is correct
61 Correct 1168 ms 37440 KB Output is correct
62 Correct 1203 ms 37440 KB Output is correct
63 Correct 1178 ms 37532 KB Output is correct
64 Correct 1168 ms 37392 KB Output is correct
65 Correct 1172 ms 37536 KB Output is correct
66 Correct 1219 ms 37424 KB Output is correct
67 Correct 1185 ms 37364 KB Output is correct
68 Correct 1196 ms 37400 KB Output is correct
69 Correct 1151 ms 37540 KB Output is correct
70 Correct 1135 ms 37364 KB Output is correct
71 Correct 1160 ms 37348 KB Output is correct
72 Correct 1179 ms 37420 KB Output is correct
73 Correct 1165 ms 37480 KB Output is correct
74 Correct 1153 ms 37460 KB Output is correct
75 Correct 1171 ms 37356 KB Output is correct
76 Correct 1144 ms 37468 KB Output is correct
77 Correct 1149 ms 37496 KB Output is correct
78 Correct 1140 ms 37436 KB Output is correct
79 Correct 1147 ms 37432 KB Output is correct
80 Correct 1129 ms 37520 KB Output is correct
81 Correct 1127 ms 37440 KB Output is correct
82 Correct 1173 ms 37440 KB Output is correct
83 Correct 1200 ms 37372 KB Output is correct
84 Correct 1178 ms 37352 KB Output is correct
85 Correct 1200 ms 37424 KB Output is correct
86 Correct 1194 ms 37408 KB Output is correct
87 Correct 1181 ms 37416 KB Output is correct
88 Correct 1200 ms 37396 KB Output is correct
89 Correct 1181 ms 37376 KB Output is correct
90 Correct 1173 ms 37460 KB Output is correct
91 Correct 1139 ms 37380 KB Output is correct
92 Correct 1133 ms 37412 KB Output is correct
93 Correct 1143 ms 37452 KB Output is correct
94 Correct 1175 ms 37404 KB Output is correct
95 Correct 1176 ms 37432 KB Output is correct
96 Correct 1151 ms 37448 KB Output is correct
97 Correct 1200 ms 37448 KB Output is correct
98 Correct 1256 ms 37428 KB Output is correct
99 Correct 1168 ms 37432 KB Output is correct
100 Correct 645 ms 20960 KB Output is correct
101 Correct 649 ms 20936 KB Output is correct
102 Correct 643 ms 21080 KB Output is correct
103 Correct 658 ms 21020 KB Output is correct
104 Correct 678 ms 20920 KB Output is correct
105 Correct 833 ms 37344 KB Output is correct
106 Correct 839 ms 37432 KB Output is correct
107 Correct 841 ms 37436 KB Output is correct
108 Correct 869 ms 37388 KB Output is correct
109 Correct 850 ms 37416 KB Output is correct
110 Correct 869 ms 37540 KB Output is correct
111 Correct 845 ms 37444 KB Output is correct
112 Correct 833 ms 37412 KB Output is correct
113 Correct 818 ms 37336 KB Output is correct
114 Correct 819 ms 37440 KB Output is correct
115 Correct 817 ms 37380 KB Output is correct
116 Correct 830 ms 37344 KB Output is correct
117 Correct 830 ms 37384 KB Output is correct
118 Correct 890 ms 37456 KB Output is correct
119 Correct 819 ms 37312 KB Output is correct
120 Correct 2 ms 512 KB Output is correct
121 Correct 2 ms 512 KB Output is correct
122 Correct 1150 ms 37416 KB Output is correct
123 Correct 1142 ms 37404 KB Output is correct
124 Correct 1168 ms 37436 KB Output is correct
125 Correct 1187 ms 37336 KB Output is correct
126 Correct 1196 ms 37316 KB Output is correct
127 Correct 1147 ms 37452 KB Output is correct
128 Correct 1132 ms 37440 KB Output is correct
129 Correct 1146 ms 37440 KB Output is correct
130 Correct 1127 ms 37336 KB Output is correct
131 Correct 1133 ms 37392 KB Output is correct
132 Correct 1159 ms 37344 KB Output is correct
133 Correct 1125 ms 37360 KB Output is correct