Submission #1072397

# Submission time Handle Problem Language Result Execution time Memory
1072397 2024-08-23T18:17:42 Z prvocislo Road Construction (JOI21_road_construction) C++17
100 / 100
8526 ms 160116 KB
 #include <bits/stdc++.h>
typedef long long ll;using namespace std; struct bod { ll x, y; };bool cmpy(bod a, bod b) { return a.y < b.y; }struct sgt2d{    int n;    vector<vector<ll> > st, sx;    vector<ll> cs;    void init(vector<bod> v)    {        for (int i = 0; i < v.size(); i++) cs.push_back(v[i].x);        sort(cs.begin(), cs.end()), cs.erase(unique(cs.begin(), cs.end()), cs.end());        n = cs.size();        st.assign(n * 2, {}), sx.assign(n * 2, {});        sort(v.begin(), v.end(), cmpy);        for (bod i : v)        {            int x = lower_bound(cs.begin(), cs.end(), i.x) - cs.begin();            for (x += n; x > 0; x >>= 1) st[x].push_back(i.y), sx[x].push_back(i.x);        }    }    int query(ll lx, ll rx, ll ly, ll ry)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        int ans = 0;        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1) ans += upper_bound(st[lx].begin(), st[lx].end(), ry) - lower_bound(st[lx].begin(), st[lx].end(), ly), lx++;            if (rx & 1) rx--, ans += upper_bound(st[rx].begin(), st[rx].end(), ry) - lower_bound(st[rx].begin(), st[rx].end(), ly);        }        return ans;    }    void query2(ll lx, ll rx, ll ly, ll ry, vector<ll> &ans, bod b, ll lim)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1)            {                int li = lower_bound(st[lx].begin(), st[lx].end(), ly) - st[lx].begin();                int ri = upper_bound(st[lx].begin(), st[lx].end(), ry) - st[lx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[lx][i] - b.y), abs(sx[lx][i] - b.x)));                lx++;            }            if (rx & 1)            {                rx--;                int li = lower_bound(st[rx].begin(), st[rx].end(), ly) - st[rx].begin();                int ri = upper_bound(st[rx].begin(), st[rx].end(), ry) - st[rx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[rx][i] - b.y), abs(sx[rx][i] - b.x)));            }        }    }};sgt2d st;int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int n, k;    cin >> n >> k;    vector<bod> o(n), v(n);    for (int i = 0; i < n; i++)    {          cin >> o[i].x >> o[i].y;        v[i].x = o[i].x + o[i].y;        v[i].y = o[i].x - o[i].y;    }    random_shuffle(v.begin(), v.end());    st.init(v);    ll lo = 1, hi = 1e10;    while (lo < hi)    {        ll mi = (lo + hi) / 2;        ll cnt = 0;        for (int i = 0; i < n; i++)        {            cnt += st.query(v[i].x - mi, v[i].x +mi, v[i].y - mi, v[i].y + mi)-1;            if (cnt >= 2*k) break;        }        if (cnt >= 2*k) hi = mi;        else lo = mi + 1;    }    vector<ll> ans;    for (int i = 0; i < n; i++)    {        st.query2(v[i].x - lo + 1, v[i].x, v[i].y - lo + 1, v[i].y, ans, v[i], lo - 1);        st.query2(v[i].x - lo + 1, v[i].x - 1, v[i].y + 1, v[i].y + lo - 1, ans, v[i], lo - 1);    }    sort(ans.begin(), ans.end(), greater<ll>());    while (ans.size() && ans.back() == 0) ans.pop_back();    reverse(ans.begin(), ans.end());    while (ans.size() > k) ans.pop_back();    while (ans.size() < k) ans.push_back(lo);    for (int i = 0; i < k; i++) cout << ans[i] << "\n";    return 0;}

Compilation message

road_construction.cpp: In member function 'void sgt2d::init(std::vector<bod>)':
road_construction.cpp:2:243: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bod>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | typedef long long ll;using namespace std; struct bod { ll x, y; };bool cmpy(bod a, bod b) { return a.y < b.y; }struct sgt2d{    int n;    vector<vector<ll> > st, sx;    vector<ll> cs;    void init(vector<bod> v)    {        for (int i = 0; i < v.size(); i++) cs.push_back(v[i].x);        sort(cs.begin(), cs.end()), cs.erase(unique(cs.begin(), cs.end()), cs.end());        n = cs.size();        st.assign(n * 2, {}), sx.assign(n * 2, {});        sort(v.begin(), v.end(), cmpy);        for (bod i : v)        {            int x = lower_bound(cs.begin(), cs.end(), i.x) - cs.begin();            for (x += n; x > 0; x >>= 1) st[x].push_back(i.y), sx[x].push_back(i.x);        }    }    int query(ll lx, ll rx, ll ly, ll ry)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        int ans = 0;        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1) ans += upper_bound(st[lx].begin(), st[lx].end(), ry) - lower_bound(st[lx].begin(), st[lx].end(), ly), lx++;            if (rx & 1) rx--, ans += upper_bound(st[rx].begin(), st[rx].end(), ry) - lower_bound(st[rx].begin(), st[rx].end(), ly);        }        return ans;    }    void query2(ll lx, ll rx, ll ly, ll ry, vector<ll> &ans, bod b, ll lim)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1)            {                int li = lower_bound(st[lx].begin(), st[lx].end(), ly) - st[lx].begin();                int ri = upper_bound(st[lx].begin(), st[lx].end(), ry) - st[lx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[lx][i] - b.y), abs(sx[lx][i] - b.x)));                lx++;            }            if (rx & 1)            {                rx--;                int li = lower_bound(st[rx].begin(), st[rx].end(), ly) - st[rx].begin();                int ri = upper_bound(st[rx].begin(), st[rx].end(), ry) - st[rx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[rx][i] - b.y), abs(sx[rx][i] - b.x)));            }        }    }};sgt2d st;int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int n, k;    cin >> n >> k;    vector<bod> o(n), v(n);    for (int i = 0; i < n; i++)    {          cin >> o[i].x >> o[i].y;        v[i].x = o[i].x + o[i].y;        v[i].y = o[i].x - o[i].y;    }    random_shuffle(v.begin(), v.end());    st.init(v);    ll lo = 1, hi = 1e10;    while (lo < hi)    {        ll mi = (lo + hi) / 2;        ll cnt = 0;        for (int i = 0; i < n; i++)        {            cnt += st.query(v[i].x - mi, v[i].x +mi, v[i].y - mi, v[i].y + mi)-1;            if (cnt >= 2*k) break;        }        if (cnt >= 2*k) hi = mi;        else lo = mi + 1;    }    vector<ll> ans;    for (int i = 0; i < n; i++)    {        st.query2(v[i].x - lo + 1, v[i].x, v[i].y - lo + 1, v[i].y, ans, v[i], lo - 1);        st.query2(v[i].x - lo + 1, v[i].x - 1, v[i].y + 1, v[i].y + lo - 1, ans, v[i], lo - 1);    }    sort(ans.begin(), ans.end(), greater<ll>());    while (ans.size() && ans.back() == 0) ans.pop_back();    reverse(ans.begin(), ans.end());    while (ans.size() > k) ans.pop_back();    while (ans.size() < k) ans.push_back(lo);    for (int i = 0; i < k; i++) cout << ans[i] << "\n";    return 0;}
      |                                                                                                                                                                                                                                                 ~~^~~~~~~~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:2:3292: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    2 | typedef long long ll;using namespace std; struct bod { ll x, y; };bool cmpy(bod a, bod b) { return a.y < b.y; }struct sgt2d{    int n;    vector<vector<ll> > st, sx;    vector<ll> cs;    void init(vector<bod> v)    {        for (int i = 0; i < v.size(); i++) cs.push_back(v[i].x);        sort(cs.begin(), cs.end()), cs.erase(unique(cs.begin(), cs.end()), cs.end());        n = cs.size();        st.assign(n * 2, {}), sx.assign(n * 2, {});        sort(v.begin(), v.end(), cmpy);        for (bod i : v)        {            int x = lower_bound(cs.begin(), cs.end(), i.x) - cs.begin();            for (x += n; x > 0; x >>= 1) st[x].push_back(i.y), sx[x].push_back(i.x);        }    }    int query(ll lx, ll rx, ll ly, ll ry)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        int ans = 0;        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1) ans += upper_bound(st[lx].begin(), st[lx].end(), ry) - lower_bound(st[lx].begin(), st[lx].end(), ly), lx++;            if (rx & 1) rx--, ans += upper_bound(st[rx].begin(), st[rx].end(), ry) - lower_bound(st[rx].begin(), st[rx].end(), ly);        }        return ans;    }    void query2(ll lx, ll rx, ll ly, ll ry, vector<ll> &ans, bod b, ll lim)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1)            {                int li = lower_bound(st[lx].begin(), st[lx].end(), ly) - st[lx].begin();                int ri = upper_bound(st[lx].begin(), st[lx].end(), ry) - st[lx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[lx][i] - b.y), abs(sx[lx][i] - b.x)));                lx++;            }            if (rx & 1)            {                rx--;                int li = lower_bound(st[rx].begin(), st[rx].end(), ly) - st[rx].begin();                int ri = upper_bound(st[rx].begin(), st[rx].end(), ry) - st[rx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[rx][i] - b.y), abs(sx[rx][i] - b.x)));            }        }    }};sgt2d st;int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int n, k;    cin >> n >> k;    vector<bod> o(n), v(n);    for (int i = 0; i < n; i++)    {          cin >> o[i].x >> o[i].y;        v[i].x = o[i].x + o[i].y;        v[i].y = o[i].x - o[i].y;    }    random_shuffle(v.begin(), v.end());    st.init(v);    ll lo = 1, hi = 1e10;    while (lo < hi)    {        ll mi = (lo + hi) / 2;        ll cnt = 0;        for (int i = 0; i < n; i++)        {            cnt += st.query(v[i].x - mi, v[i].x +mi, v[i].y - mi, v[i].y + mi)-1;            if (cnt >= 2*k) break;        }        if (cnt >= 2*k) hi = mi;        else lo = mi + 1;    }    vector<ll> ans;    for (int i = 0; i < n; i++)    {        st.query2(v[i].x - lo + 1, v[i].x, v[i].y - lo + 1, v[i].y, ans, v[i], lo - 1);        st.query2(v[i].x - lo + 1, v[i].x - 1, v[i].y + 1, v[i].y + lo - 1, ans, v[i], lo - 1);    }    sort(ans.begin(), ans.end(), greater<ll>());    while (ans.size() && ans.back() == 0) ans.pop_back();    reverse(ans.begin(), ans.end());    while (ans.size() > k) ans.pop_back();    while (ans.size() < k) ans.push_back(lo);    for (int i = 0; i < k; i++) cout << ans[i] << "\n";    return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ~~~~~~~~~~~^~~
road_construction.cpp:2:3334: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    2 | typedef long long ll;using namespace std; struct bod { ll x, y; };bool cmpy(bod a, bod b) { return a.y < b.y; }struct sgt2d{    int n;    vector<vector<ll> > st, sx;    vector<ll> cs;    void init(vector<bod> v)    {        for (int i = 0; i < v.size(); i++) cs.push_back(v[i].x);        sort(cs.begin(), cs.end()), cs.erase(unique(cs.begin(), cs.end()), cs.end());        n = cs.size();        st.assign(n * 2, {}), sx.assign(n * 2, {});        sort(v.begin(), v.end(), cmpy);        for (bod i : v)        {            int x = lower_bound(cs.begin(), cs.end(), i.x) - cs.begin();            for (x += n; x > 0; x >>= 1) st[x].push_back(i.y), sx[x].push_back(i.x);        }    }    int query(ll lx, ll rx, ll ly, ll ry)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        int ans = 0;        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1) ans += upper_bound(st[lx].begin(), st[lx].end(), ry) - lower_bound(st[lx].begin(), st[lx].end(), ly), lx++;            if (rx & 1) rx--, ans += upper_bound(st[rx].begin(), st[rx].end(), ry) - lower_bound(st[rx].begin(), st[rx].end(), ly);        }        return ans;    }    void query2(ll lx, ll rx, ll ly, ll ry, vector<ll> &ans, bod b, ll lim)    {        lx = lower_bound(cs.begin(), cs.end(), lx) - cs.begin();        rx = upper_bound(cs.begin(), cs.end(), rx) - cs.begin();        for (lx += n, rx += n; lx < rx; lx >>= 1, rx >>= 1)        {            if (lx & 1)            {                int li = lower_bound(st[lx].begin(), st[lx].end(), ly) - st[lx].begin();                int ri = upper_bound(st[lx].begin(), st[lx].end(), ry) - st[lx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[lx][i] - b.y), abs(sx[lx][i] - b.x)));                lx++;            }            if (rx & 1)            {                rx--;                int li = lower_bound(st[rx].begin(), st[rx].end(), ly) - st[rx].begin();                int ri = upper_bound(st[rx].begin(), st[rx].end(), ry) - st[rx].begin();                for (int i = li; i < ri; i++) ans.push_back(max(abs(st[rx][i] - b.y), abs(sx[rx][i] - b.x)));            }        }    }};sgt2d st;int main(){    ios::sync_with_stdio(false);    cin.tie(0);    int n, k;    cin >> n >> k;    vector<bod> o(n), v(n);    for (int i = 0; i < n; i++)    {          cin >> o[i].x >> o[i].y;        v[i].x = o[i].x + o[i].y;        v[i].y = o[i].x - o[i].y;    }    random_shuffle(v.begin(), v.end());    st.init(v);    ll lo = 1, hi = 1e10;    while (lo < hi)    {        ll mi = (lo + hi) / 2;        ll cnt = 0;        for (int i = 0; i < n; i++)        {            cnt += st.query(v[i].x - mi, v[i].x +mi, v[i].y - mi, v[i].y + mi)-1;            if (cnt >= 2*k) break;        }        if (cnt >= 2*k) hi = mi;        else lo = mi + 1;    }    vector<ll> ans;    for (int i = 0; i < n; i++)    {        st.query2(v[i].x - lo + 1, v[i].x, v[i].y - lo + 1, v[i].y, ans, v[i], lo - 1);        st.query2(v[i].x - lo + 1, v[i].x - 1, v[i].y + 1, v[i].y + lo - 1, ans, v[i], lo - 1);    }    sort(ans.begin(), ans.end(), greater<ll>());    while (ans.size() && ans.back() == 0) ans.pop_back();    reverse(ans.begin(), ans.end());    while (ans.size() > k) ans.pop_back();    while (ans.size() < k) ans.push_back(lo);    for (int i = 0; i < k; i++) cout << ans[i] << "\n";    return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5336 KB Output is correct
2 Correct 44 ms 5340 KB Output is correct
3 Correct 34 ms 5328 KB Output is correct
4 Correct 46 ms 5324 KB Output is correct
5 Correct 32 ms 4308 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1572 ms 139912 KB Output is correct
2 Correct 1632 ms 139644 KB Output is correct
3 Correct 32 ms 5324 KB Output is correct
4 Correct 1332 ms 139608 KB Output is correct
5 Correct 1348 ms 139648 KB Output is correct
6 Correct 1336 ms 139780 KB Output is correct
7 Correct 976 ms 139160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1331 ms 143052 KB Output is correct
2 Correct 1744 ms 142152 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 752 ms 134344 KB Output is correct
5 Correct 902 ms 73676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1331 ms 143052 KB Output is correct
2 Correct 1744 ms 142152 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 752 ms 134344 KB Output is correct
5 Correct 902 ms 73676 KB Output is correct
6 Correct 2219 ms 142028 KB Output is correct
7 Correct 2137 ms 142288 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1884 ms 160116 KB Output is correct
11 Correct 770 ms 134524 KB Output is correct
12 Correct 919 ms 73804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5336 KB Output is correct
2 Correct 44 ms 5340 KB Output is correct
3 Correct 34 ms 5328 KB Output is correct
4 Correct 46 ms 5324 KB Output is correct
5 Correct 32 ms 4308 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2809 ms 59160 KB Output is correct
8 Correct 2831 ms 58368 KB Output is correct
9 Correct 33 ms 5324 KB Output is correct
10 Correct 1436 ms 64752 KB Output is correct
11 Correct 551 ms 63828 KB Output is correct
12 Correct 455 ms 32692 KB Output is correct
13 Correct 463 ms 36188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5336 KB Output is correct
2 Correct 44 ms 5340 KB Output is correct
3 Correct 34 ms 5328 KB Output is correct
4 Correct 46 ms 5324 KB Output is correct
5 Correct 32 ms 4308 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1572 ms 139912 KB Output is correct
8 Correct 1632 ms 139644 KB Output is correct
9 Correct 32 ms 5324 KB Output is correct
10 Correct 1332 ms 139608 KB Output is correct
11 Correct 1348 ms 139648 KB Output is correct
12 Correct 1336 ms 139780 KB Output is correct
13 Correct 976 ms 139160 KB Output is correct
14 Correct 1331 ms 143052 KB Output is correct
15 Correct 1744 ms 142152 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 752 ms 134344 KB Output is correct
18 Correct 902 ms 73676 KB Output is correct
19 Correct 2219 ms 142028 KB Output is correct
20 Correct 2137 ms 142288 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1884 ms 160116 KB Output is correct
24 Correct 770 ms 134524 KB Output is correct
25 Correct 919 ms 73804 KB Output is correct
26 Correct 2809 ms 59160 KB Output is correct
27 Correct 2831 ms 58368 KB Output is correct
28 Correct 33 ms 5324 KB Output is correct
29 Correct 1436 ms 64752 KB Output is correct
30 Correct 551 ms 63828 KB Output is correct
31 Correct 455 ms 32692 KB Output is correct
32 Correct 463 ms 36188 KB Output is correct
33 Correct 8526 ms 147368 KB Output is correct
34 Correct 8360 ms 145744 KB Output is correct
35 Correct 4379 ms 149888 KB Output is correct
36 Correct 971 ms 62544 KB Output is correct
37 Correct 958 ms 62408 KB Output is correct
38 Correct 1073 ms 78980 KB Output is correct