QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#565191#9315. Rainbow Bracket SequenceKobicGendWA 1ms3560kbC++209.4kb2024-09-15 20:33:012024-09-15 20:33:04

Judging History

你现在查看的是最新测评结果

  • [2024-09-15 20:33:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3560kb
  • [2024-09-15 20:33:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
template<class T> void chmax(T& a, T b) { if (a < b) a = b; } 
template<class T> void chmin(T& a, T b) { if (a > b) a = b; } 
template<class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

constexpr int mod = 998244353;
ll qpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct DSU {
    vector<int> p, siz;

    DSU() {}
    DSU(int n) {
        init(n);
    }

    void init(int n) {
        p.resize(n + 1);
        iota(p.begin(), p.end(), 0);
        siz.assign(n + 1, 1);
    }

    int find(int x) {
        while (x != p[x]) x = p[x] = p[p[x]];
        return x;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    bool uno(int x, int y) {
        x = find(x), y = find(y);
        if (same(x, y)) return 0;
        siz[x] += siz[y];
        p[y] = x;
        return 1;
    }

    int size(int x) {
        return siz[find(x)];
    }
};

const int N = 2008;
int t[N];

int read() {
    char u, v;
    cin >> u >> v;
    return (u-48) * 50 + v-48;    
}

void eachT() {
    int n, l, q;
    cin >> n >> l >> q;


    vector<vector<pair<int, int>>> E(l + 1);
    for (int i = 1; i <= l; ++i) {
        unordered_map<int, int> mp;
        for (int j = 1; j <= n; ++j) {
            t[j] = read();
            mp[t[j]] += 1;
           // cerr << t[j] << ' ';
        }
        int siz = mp.size();
        if (siz < n - 1) continue;
        else if (siz == n) {
            for (int j = 1; j <= n; ++j) {
                E[i].emplace_back(j, t[j]);
            }
        }
        else if (siz == n - 1) {
            int zero = -1;
            for (int j = 1; j <= n; ++j) {
                if (mp[j] == 0) zero = j;
            }
            for (int j = 1; j <= n; ++j) {
                if (mp[j] == 2) {
                    E[i].emplace_back(j, zero);
                }
            }
        }
       // cerr << '\n';
    }

    vector<vector<tuple<int, int, int>>> que(l + 1);
    for (int i = 0; i < q; ++i) {
        int a = read(), b = read(), c = read();
        que[c].emplace_back(a, b, i);
       // cerr << a << ' ' << b << ' ' << c << '\n';
    }


    DSU dsu(2 * n);
    for (int c = 1; c <= n; ++c) {
        dsu.uno(c, c + n);
    }

    vector<int> ans(q);
    for (int c = 0; c <= l; ++c) {
       // cerr << "c=" << c << '\n';
        for (auto& [u, v] : E[c]) {
           // cerr << "uno" << u<<' ' << v<<'\n';
            dsu.uno(u, v + n);
        }
        for (auto& [a, b, id] : que[c]){
            //cerr << "before";
            //cerr << a << ' ' << b + n << '\n'; 
            if (dsu.same(a, b + n)) ans[id] = 1;
            //cerr << "afte";
        }
    }

    for (int i = 0; i < q; ++i) {
        cout << ans[i];
    }
    cout << '\n';
}

// void eachT() {
//     int n;
//     cin >> n;

//     // vector<pair<int, int>> a(n);
//     // for (auto& [l, r] : a) {
//     //     cin >> l >> r;
//     // }

//     // sort(a.begin(), a.end(), 
//     //     [&](const auto&a, const auto&b) {
//     //         return a.first == b.first ? a.second > b.second : a.first < b.first;
//     //     });


//     vector<vector<int>> v(n + 2);
//     for (int i = 0; i < n; ++i) {
//         int l, r;
//         cin >> l >> r;

//         v[l].push_back(r);
//     }

//     bool ok = 1;

//     //int cntt = 0;
//     for (int l = 1; l <= n; ++l) {
//         if (v[l].empty()) {
//             ok = 0;
//             break;
//         }

//         sort(v[l].begin(), v[l].end(), greater<>());
//         int big = v[l][0];

//         for (int j = 1; j < v[l].size(); ++j) {
//             //++cntt;
//             if (v[l][j-1] == v[l][j]) {
//                 ok = 0;
//                 break;
//             }
//             int r = v[l][j];
//             v[r + 1].push_back(big);
//         }

//         if (ok == 0) break;
//     }
        
//     cout << ok << '\n';
//     //cerr << cntt << '\n';
// }


// const int N = 2008;
// int arr[N], sa[N];
// int b[N][N], sb[N][N];

// void eachT() {
//     int n;
//     cin >> n;

//     for (int i = 1; i <= n; ++i) {
//         cin >> arr[i];
//     }
    
//     auto check = [&](int x) {
//        // cerr << "\n\ncheck " << x << '\n';
//         sa[0] = 0;
//         for (int i = 1; i <= n; ++i) {
//             int a = arr[i] <= x ? 1 : -1;
//             sa[i] = sa[i - 1] + a;
//             //cerr << "a[" << i << "]=" << a << '\n';
//             //cerr << "sa[" << i << "]=" << sa[i] << '\n';
//         }

//         // return sa[n] < 0;
 
//         for (int i = 1; i <= n; ++i) {
//             for (int j = i; j <= n; ++j) {
//                 b[i][j] = sa[j] - sa[i - 1] >= 0 ? 1 : -1;
//                 //cerr << "b[" << i << "][" << j << "]=" << b[i][j] << '\n';
//                 // cerr << "b[" << i << "][" << j << "]="
//                 //   << sa[j] << '-' << sa[i-1] << "=" << b[i][j] << '\n'; 
//             }
//         }
//         for (int i = 1; i <= n; ++i) {
//             for (int j = 1; j <= n; ++j) {
//                 sb[i][j] = sb[i - 1][j] + sb[i][j - 1] - sb[i - 1][j - 1] + b[i][j];
//             }
//         }
   
//         int sum = 0;
//         for (int i = 1; i <= n; ++i) {
//             for (int j = i; j <= n; ++j) { 
//                 int c = sb[j][j] - sb[i - 1][j] - sb[j][i - 1] + sb[i - 1][i - 1] >= 0 ? 1 : -1;
//                 sum += c;
//                 //cerr << "c[" << i << "][" << j << "]=" << c << '\n';
//             }
//         }
//         return sum >= 0;
//     };

//     int l = 0, r = 1e9 + 1;
//     while (l <= r) {
//         int mid = l + r >> 1;
//         if (check(mid)) r = mid - 1;
//         else l = mid + 1;
//     }
//     cout << l << '\n';
// }

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    cin >> T;

    while (T--) {
        eachT();
    }

    return 0;
}

// void eachT() {
//     int n;
//     cin >> n;

//     vector<int> a(n);
//     vector<int> alls;
//     for (int i = 0; i < n; ++i) {
//         cin >> a[i];
//         alls.push_back(a[i]);
//     }

//     vector<vector<int>> vec(n);

//     sort(alls.begin(), alls.end());
//     unique(alls.begin(), alls.end());
//     for (int i = 0; i < n; ++i) {
//         a[i] = lower_bound(alls.begin(), alls.end(), a[i]) - alls.begin();
//         //cerr << a[i] << ' ';
//         vec[a[i]].push_back(i);
//     }    

//     vector<int> lst(n), nxt(n);

//     vector<int> stk;
//     for (int i = 0; i < n; ++i) {
//         while (!stk.empty() && a[i] >= a[stk.back()]) {
//             stk.pop_back();
//         }
//         lst[i] = stk.empty() ? -1 : stk.back();
//         stk.push_back(i);
//     }

//     stk.clear();
//     for (int i = n - 1; i >= 0; --i) {
//         while (!stk.empty() && a[i] >= a[stk.back()]) {
//             stk.pop_back();
//         }
//         nxt[i] = stk.empty() ? -1 : stk.back();
//         stk.push_back(i);
//     }  

//     // for (int i = 0; i < n; ++i) {
//     //     cerr << "i=" << i << ' ' << lst[i] << ' ' << nxt[i] << '\n';
//     // }
//     // cerr << '\n';


//     vector<int> ans(n);
//     for (int j = n - 1; j >= 0; --j) {
//         for (auto& i : vec[j]) {
//             // cerr << "id = " << i << '\n';
//             int fa;
//             if (nxt[i] == -1 && lst[i] == -1) continue;
//             if (nxt[i] == -1) {
//                 fa = lst[i];
//             }
//             else if (lst[i] == -1) {
//                 fa = nxt[i];
//             }
//             else if (a[nxt[i]] > a[lst[i]]) {
//                 fa = lst[i];
//             }
//             else {
//                 fa = nxt[i];
//             }
//             // cerr << "fa " << i << " = " << fa << '\n';
//             // cerr << ans[fa] << '\n';
//             ans[i] = ans[fa] + 1;
//             // cerr << ans[i] << '\n';
//         }
//     }

//     ll anss = 0;
//     for (int i = 0; i < n; ++i) {
//         anss += ans[i];
//         // cerr << ans[i] << ' ';
//     }
//     // cerr << "\n\n";
//     cout << anss << '\n'; 
// }




// void eachT() {
//     int me;
//     cin >> me;

//     int rk = 1;
//     for (int i = 1; i < 32; ++i) {
//         int x;
//         cin >> x;

//         if (x > me) ++rk;
//     }

//     //cerr << rk;

//     int ans;
//     if (rk == 1) ans = 1;
//     else if (rk <= 5) ans = 2;
//     else if (rk <= 19) ans = 4;
//     else if (rk <= 26) ans = 8;
//     else if (rk <= 30) ans = 16;
//     else ans = 32;

//     cout << ans << '\n';
// }

// void eachT() {
//     int n;
//     cin >> n;

//     map<string, vector<string>> a;
//     while (n--) {
//         string name, id, op;
//         cin >> name >> id >> op;

//         if (op[0] == 'a') {
//             a[id].push_back(name);
//         }
//     }

//     string mx = "";
//     for (auto& [k, vec] : a) {
//         sort(vec.begin(), vec.end());
//         vec.erase(unique(vec.begin(), vec.end()), vec.end());
        
//         if (a[mx].size() < a[k].size()) {
//             mx = k;
//         }
//     }

//     cout << mx << '\n';
// }

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3560kb

input:

2
3 2
1 2
1 2 2 2 1 2
3 1 4 2 2 1
3 2
2 2
1 2 2 2 1 2
3 1 4 2 2 1

output:

0
00

result:

wrong answer 1st numbers differ - expected: '9', found: '0'