Language: C++

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <vector>
#include <iterator>

using namespace std;

typedef map<char, set<int> > M;

vector<int> conv_vec(set<int> st) {
    vector<int> vec;
    for(set<int>::iterator it = st.begin(); it != st.end(); ++it) {
        vec.push_back(*it);
    }
    return vec;
}

set<int> conv_set(vector<int> vec) {
    set<int> st;
    for(vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) {
        st.insert(*it);
    }
    return st;
}

void show(vector<int> A, vector<int> B, char order, vector<int> result)
{
    cout << "{ ";
    for (int i = 0; i < A.size(); i += 1) {
        cout << A[i] << " ";
    }
    cout << "} " << order << " { ";
    for (int i = 0; i < B.size(); i += 1) {
        cout << B[i] << " ";
    }
    cout << "} = { ";
    for (int i = 0; i < result.size(); i += 1) {
        cout << result[i] << " ";
    } 
    cout << "}" << endl;
    return;
}

set<int> calc(set<int> st_A, set<int> st_B, char order) {
    vector<int> result;
    vector<int> A = conv_vec(st_A), B = conv_vec(st_B);

    if (order == 'u') {
        set_union(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
    } else if (order == 'i') {
        set_intersection(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
    } else if (order == 'd') {
        set_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
    } else if (order == 's') {
        set_symmetric_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
    } else if (order == 'c') {
        set_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
    }
    //show(A, B, order, result);
    return conv_set(result);
}

int p_skip(string str, int p) {
    int cnt = 1;
    while(p < str.size()) {
        if (str[p] == '(') {
            ++cnt;
        } else if (str[p] == ')') {
            --cnt;
        }
        ++p;
        if (cnt == 0) {
            break;
        }
    }
    return p;
}

set<int> parse(string str, M dataset, int start) {
    int p = start;
    set<int> A, B;
    if (str[p] == '(') {
        p += 1;
        A = parse(str, dataset, p);
        p = p_skip(str, p);
    } else if (str[p] == 'c') {
        p += 1;
        if(str[p] == '(') {
            p += 1;
            A = parse(str, dataset, p);
            p = p_skip(str, p);
        } else {
            A = dataset[str[p]];
            p += 1;
        }
        A = calc(dataset['U'], A, 'c');
    } else {
        A = dataset[str[p]];
        p += 1;
    }

    while(p < str.size()) {
        if (((string)("uids")).find(str[p]) == string::npos) {
            break;
        }

        char order = str[p];
        ++p;

        if (str[p] == '(') {
            p += 1;
            B = parse(str, dataset, p);
            p = p_skip(str, p);
        } else if (str[p] == 'c') {
            p += 1;
            if(str[p] == '(') {
                p += 1;
                B = parse(str, dataset, p);
                p = p_skip(str, p);
            } else {
                B = dataset[str[p]];
                p += 1;
            }
            B = calc(dataset['U'], B, 'c');
        } else {
            B = dataset[str[p]];
            p += 1;
        }

        A = calc(A, B, order);
    }

    return A;
}

void solve(string str, M dataset) {
    set<int> result = parse(str, dataset, 0);
    if (result.empty()) {
        cout << "NULL" << endl;
        return;
    }

    int cnt = 0;
    for (set<int>::iterator it = result.begin(); it != result.end(); ++it) {
        if (cnt == (int)(result.size())-1) {
            cout << *it << endl;
        } else {
            cout << *it << " ";
            cnt += 1;
        }
    }
    return;
}

int main()
{
    char s;
    int t;
    set<int> U;
    string str;
    M dataset;

    while(!cin.eof()) {
        cin >> s >> t;
        if(s == 'R'){
            cin >> str;
            //cout << "str: " << str << endl;
            dataset['U'] = U;
            solve(str, dataset);
            dataset.clear();
            U.clear();
            continue;
        }
        set<int> st;
        int u;
        for (int i = 0; i < t; i += 1) {
            cin >> u;
            st.insert(u);
            U.insert(u);
        }
        dataset[s] = st;
    }

    return 0;
}

Compiler output:
a.cc: In function 'std::set<int> calc(std::set<int>, std::set<int>, char)':
a.cc:52:9: error: 'set_union' was not declared in this scope
   52 |         set_union(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
      |         ^~~~~~~~~
a.cc:54:9: error: 'set_intersection' was not declared in this scope
   54 |         set_intersection(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
      |         ^~~~~~~~~~~~~~~~
a.cc:56:9: error: 'set_difference' was not declared in this scope
   56 |         set_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
      |         ^~~~~~~~~~~~~~
a.cc:58:9: error: 'set_symmetric_difference' was not declared in this scope
   58 |         set_symmetric_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:60:9: error: 'set_difference' was not declared in this scope
   60 |         set_difference(begin(A), end(A), begin(B), end(B), inserter(result, end(result)));
      |         ^~~~~~~~~~~~~~