QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#856#568701#9310. Permutation Counting 4KJJDKJJDFailed.2024-09-20 19:03:382024-09-20 19:03:38

Details

Extra Test:

Invalid Input

input:

1

output:


result:

FAIL Unexpected end of file - token expected (stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568701#9310. Permutation Counting 4KJJDAC ✓980ms33536kbC++201.7kb2024-09-16 17:49:442024-09-18 14:59:20

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 7;
#define lc p << 1
#define rc p << 1 | 1
// mt19937_64 rng{chrono::steady_clock::now().time_since_epoch().count()};//随机数
ll a[N], b[N];
void slove()
{
    ll n, m, k;
    cin >> n;
    vector<pii> p(n + 1);
    priority_queue<pii, vector<pii>, greater<pii>> q;
    for (int i = 1; i <= n; i++)
        cin >> p[i].first >> p[i].second, q.push(p[i]);
    // priority_queue<pii,vector<pii>,greater<pii>>q_m;
    vector<pii> ans;
    for (int i = 1; i <= n; i++)
    {
        vector<pii> tmp;
        while (!q.empty() && q.top().first == i)
        {
            auto now = q.top();
            q.pop();
            tmp.push_back(now);
        }
        for (int j = tmp.size() - 1; j > 0; j--)
        {
            auto [x, y] = tmp[j];
            auto [x1, y1] = tmp[j - 1];
            // if (tmp[j] == tmp[j - 1])
            // {
                // cout << "0\n";
                // return;
            // }
            if(y1+1<=y)
            q.push(make_pair(y1 + 1, y));
        }
        if (tmp.size() > 0)
            ans.push_back(tmp[0]);
    }
    if (ans.size() < n)
        cout << 0 << '\n';
    else
    {
        for (int i = 1; i <= n; i++)
        {
            if (ans[i - 1].first != i)
            {
                cout << 0 << '\n';
                return;
            }
        }
        cout << 1 << '\n';
    }
}
int main()
{

    // cout << fixed << setprecision(10);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
        slove();
}