QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#825#569913#9310. Permutation Counting 4qwqqwqqwqqwqssssqwqqwqqwqqwqssssSuccess!2024-09-17 12:14:212024-09-17 12:14:21

详细

Extra Test:

Time Limit Exceeded

input:

1
1000000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60...

output:


result:


ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569913#9310. Permutation Counting 4qwqqwqqwqqwqssssTL 322ms58684kbC++141.4kb2024-09-17 12:09:402024-09-17 12:22:34

answer

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
void eachT();
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
	int T;cin>>T;
	while(T--)eachT();
return 0;}
/*
*/
void eachT() {
    int n;
    cin >> n;

    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 cnt=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) {
            if (v[l][j - 1] == v[l][j]) {
                ok = 0;
                break;
            }
            int r = v[l][j];
            v[r + 1].push_back(big);
            // cnt++;
        }

        if (ok == 0) break;
    }

    cout << ok << '\n';
    // cerr<<cnt<<endl;
}