| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 904874 | KK_1729 | Handcrafted Gift (IOI20_gift) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gift.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}
bool compare(pair<int, int> x, pair<int, int> y){
    if (x.first < y.first) return true;
    if (x.first == y.first){
        if (x.second < y.second) return true;
    }
    return false;
}
bool intersect(pair<int, int> x, pair<int, int> y){
    if (y.first < x.first) swap(x, y);
    if (x.second >= y.first) return true;
    return false;
}
int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) {
    vector<int> ans(n);
    vector<int> component(n);
    
    vector<pair<int, int>> first;
    vector<pair<int, int>> second;
    FOR(i,0,r){
        int l = a[i]; int r = b[i]; int t = x[i];
        if (t == 1){
            first.pb({l, r});
        }else{
            second.pb({l, r});
        }
    }
    FOR(i,0,n) first.pb({i, i});
    sort(all(first));
    vector<pair<int, int>> ranges;
    pair<int, int> current = {0, 0};
    FOR(i,0,first.size()){
        if (i == 0){
            current = first[i];
            continue;
        }
        if (intersect(first[i], current)){
            current.second = max(current.second, first[i].second);
        }else{
            ranges.pb(current);
            current = first[i];
        }
    }
    ranges.pb(current);
    int comp = 0;
    // cout << endl;
    for (auto x: ranges){
        
        FOR(i,x.first,x.second+1){
            component[i] = comp;
            if (comp%2){
                ans[i] = 0;
            }else{
                ans[i] = 1;
            }
        }
        comp++;
    }
    for (auto x: second){
        if (component[x.first] == component[x.second]){
            return 0;
        }
    }
	string answer = "";
    for (auto x: ans){
        if (x) answer+='R';
        else answer+='B';
    }
	// cout << answer << endl;
    craft(answer);
	return 1;
}
