Submission #684920

# Submission time Handle Problem Language Result Execution time Memory
684920 2023-01-22T20:42:17 Z KiriLL1ca Segments (IZhO18_segments) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define pb push_back
#define fr first
#define sc second
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;

#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;

template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 100;
const int buben = 1000;
const int nb = N / buben + 2;

struct segment {
    int l, r;
    segment (int l = 0, int r = 0) : l(l), r(r) {}
    inline int len () { return r - l + 1; }

    inline bool operator < (segment &x) {
        if (len() != x.len()) return len() < x.len();
        return make_pair(l, r) < make_pair(x.l, x.r);
    }
};

inline int inter (const segment &a, const segment &b) {
    return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
}

struct sex {
    vector <segment> buf;
    vector <segment> ful;
    vector <int> lb[nb], rb[nb];

    inline void add (int l, int r) {
        segment seg (l, r); buf.pb(seg);

        if (sz(buf) == buben) {
            sort(all(buf));

            vector <segment> mt; mt.reserve(sz(ful) + sz(buf));
            int uk1 = 0, uk2 = 0;
            while (uk1 < sz(ful) || uk2 < sz(buf)) {
                if (uk1 == sz(ful)) mt.pb(buf[uk2++]);
                else if (uk2 == sz(buf)) mt.pb(ful[uk1++]);
                else if (ful[uk1] < buf[uk2]) mt.pb(ful[uk1++]);
                else mt.pb(buf[uk2++]);
            }
            ful.swap(mt); buf.clear();

            for (int i = 0; i < nb; ++i) lb[i].clear(), rb[i].clear();
            for (int i = 0; i < sz(ful); ++i) {
                lb[i / buben].pb(ful[i].l);
                rb[i / buben].pb(ful[i].r);
            }
            for (int i = 0; i < nb; ++i) {
                sort(all(lb[i]));
                sort(all(rb[i]));
            }
        }
    }

    inline int get (int l, int r, int k) {
        int res = 0;
        segment seg (l, r);

        for (segment x : buf) res += inter(x, seg) >= k;

        for (int L = 0, i = 0; L < sz(ful); L += buben, ++i) {
            int R = min(sz(ful), L + buben) - 1;
            if (ful[R].len() < k) continue;
            else if (ful[L].len() <= k && k <= ful[R].len()) {
                for (int j = L; j <= R; ++j) res += inter(ful[j], seg);
            }
            else {
                res += R - L + 1;
                res -= sz(lb[i]) - (lower_bound(all(lb[i]), r - k + 2) - lb[i].begin());
                res -= upper_bound(all(rb[i]), l + k - 2) - rb[i].begin();
            }
        }

        return res;
    }
};

inline void solve () {
    int q, T; cin >> q >> T;
    vector <pii> seg (q); int uk = 0;
    int lst = 0;
    sex in, out;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int l, r; cin >> l >> r;
            l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
            seg[uk++] = {l, r};
            in.add(l, r);
        }
        if (t == 2) {
            int id; cin >> id; --id;
            auto [l, r] = seg[id];
            out.add(l, r);
        }
        if (t == 3) {
            int l, r, k; cin >> l >> r >> k;
            l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
            lst = in.get(l, r, k) - out.get(l, r, k);
            cout << lst << endl;
        }
    }
}

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    int t = 1; // cin >> t;
    while (t--) solve();
    return 0;
}

Compilation message

segments.cpp: In function 'long long int inter(const segment&, const segment&)':
segments.cpp:44:52: error: no matching function for call to 'max(int, long long int)'
   44 |     return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
      |                                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
segments.cpp:44:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   44 |     return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
      |                                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
segments.cpp:44:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   44 |     return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
      |                                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
segments.cpp:44:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   44 |     return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
      |                                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
segments.cpp:44:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   44 |     return max(0, min(a.r, b.r) - max(a.l, b.l) + 1);
      |                                                    ^
At global scope:
cc1plus: error: '::main' must return 'int'