Submission #8362891


Source Code Expand

Copy
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


const ll INF = 1e16;
struct SegmentTree {
    SegmentTree(ll n) : n(n), t(n * 2, {-INF, -1}) {}
    SegmentTree(vl x) : n(x.size()), t(n * 2, mp(-INF, -1)) {
        for (int i = 0; i < n; ++i) {
            t[i + n] = {x[i], i};
        }
        build();
    }

    pll combine(pll a, pll b) { return max(a, b); }

    void build() {  // build the tree
        for (ll i = n - 1; i > 0; --i) t[i] = combine(t[i << 1], t[(i << 1) | 1]);
    }

    void modify(ll p, ll value) {  // set value at position p
        pll x = {value, p};
        for (t[p += n] = x; p > 1; p >>= 1) t[p >> 1] = combine(t[p], t[p ^ 1]);
    }

    pll query(ll l, ll r) {  // [l, r)
        pll res = {-INF, -1};
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = combine(res, t[l++]);
            if (r & 1) res = combine(res, t[--r]);
        }
        return res;
    }

    ll get(ll i) { return t[n + i].fi; }


    ll n;
    vpll t;
};

void update(ll& x, ll y) { x = min(x, y); }
void no() { cout << -1 << endl; exit(0); }

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);


    ll n, k;
    cin >> n >> k;
    vvl ans;

    vl ab(2 * n);
    for (ll i = 0; i < 2 * n; ++i) {
        ab[i] = k + i;
    }
    SegmentTree st(ab);

    ll j = 2 * n - 1;

    for (ll i = n - 1; i >= 0; --i) {
        ll c = k + 2 * n + i;
        ll b = st.get(j);
        ll ar = c - b;
        if (ar < k) no();
        pll q = st.query(0, ar - k);
        if (q.se < 0) no();
        ans.pb({st.get(q.fi), b, c});
        st.modify(j, -INF);
        st.modify(q.se, -INF);

        while (st.get(j) < 0) {
            if (j > 0) { --j; }
            else { if (i) no(); }
        }
    }

    for (auto a : ans) {
        cout << a[0] << " " << a[1] << " " << a[2] << "\n";
    }


    print_time();
    return 0;
}

Submission Info

Submission Time
Task E - Non-triangular Triplets
User VadymKa
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3831 Byte
Status RE
Exec Time 122 ms
Memory 14088 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 1
WA × 1
AC × 5
WA × 3
RE × 30
Set Name Test Cases
Sample sample01.txt, sample02.txt
All sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt RE 119 ms 12728 KB
in02.txt RE 122 ms 13184 KB
in03.txt RE 113 ms 11284 KB
in04.txt RE 117 ms 13176 KB
in05.txt RE 115 ms 12516 KB
in06.txt RE 114 ms 10492 KB
in07.txt RE 114 ms 11180 KB
in08.txt RE 120 ms 12740 KB
in09.txt RE 116 ms 12528 KB
in10.txt RE 118 ms 13928 KB
in11.txt RE 112 ms 10108 KB
in12.txt RE 111 ms 10344 KB
in13.txt RE 111 ms 10996 KB
in14.txt RE 110 ms 10012 KB
in15.txt RE 110 ms 10116 KB
in16.txt RE 110 ms 10656 KB
in17.txt RE 112 ms 10760 KB
in18.txt RE 109 ms 9240 KB
in19.txt RE 110 ms 10012 KB
in20.txt RE 112 ms 10884 KB
in21.txt RE 111 ms 10764 KB
in22.txt RE 109 ms 9348 KB
in23.txt RE 116 ms 14088 KB
in24.txt AC 5 ms 9088 KB
in25.txt RE 109 ms 7584 KB
in26.txt RE 108 ms 6904 KB
in27.txt RE 105 ms 3692 KB
in28.txt RE 104 ms 4896 KB
in29.txt AC 6 ms 9600 KB
in30.txt RE 113 ms 11108 KB
in31.txt RE 113 ms 10980 KB
in32.txt RE 112 ms 10980 KB
in33.txt WA 1 ms 256 KB
in34.txt AC 1 ms 256 KB
sample01.txt WA 1 ms 256 KB
sample02.txt AC 1 ms 256 KB