QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136761#238. Distinct Values4k2kok#0 0ms0kbC++201.5kb2023-08-09 10:59:552023-08-09 10:59:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 10:59:58]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-08-09 10:59:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double

const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

int n, m;

struct node {
    int l, r;

    bool operator < (const node &n1) const {
        if (l == n1.l) return r < n1.r;
        return l < n1.l;
    }
};

vector<node> vv;

int ans[maxn];

void solve() {
    vv.clear();
    cin >> n >> m;
    for (int i = 1, l, r; i <= m; i++) {
        cin >> l >> r;
        vv.push_back({l, r});
    }
    sort(vv.begin(), vv.end());
    for (int i = 1; i <= n; i++) ans[i] = 1;
    set<int> s;
    for (int i = 1; i <= n; i++) {
        s.insert(i);
    }
    int lastl = 1, lastr = 0;
    for (int i = 0; i < vv.size(); i++) {
        if (vv[i].l > lastl) {
            for (int j = lastl; j < vv[i].l; j++) {
                s.insert(ans[j]);
            }
            lastl = vv[i].l;
        }
        int nowl = max(lastr + 1, vv[i].l);
        for (int j = nowl; j <= vv[i].r; j++) {
            ans[j] = *s.begin();
            s.erase(ans[j]);
        } 
        lastr = vv[i].r;
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}

signed main(){
    io;
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

11116
10 2
5 5
5 6
10 1
7 10
10 1
2 6
10 1
2 5
10 1
6 7
10 2
8 9
7 10
10 2
1 4
6 10
10 4
8 8
10 10
3 6
1 5
10 3
8 8
10 10
8 10
10 4
6 10
1 5
2 6
1 2
10 3
4 4
4 8
4 8
10 4
1 5
1 2
5 5
2 4
10 4
2 5
9 10
6 7
2 4
10 1
5 6
10 4
10 10
8 10
2 5
10 10
10 1
1 2
10 4
7 8
5 6
7 9
10 10
10 4
3 7
6 6
8 10
3 4
10...

output:

1 1 1 1 1 2 1 1 1 1 
1 1 1 1 1 1 1 2 3 4 
1 1 2 3 4 5 1 1 1 1 
1 1 2 3 4 1 1 1 1 1 
1 1 1 1 1 1 2 1 1 1 
1 1 1 1 1 1 1 2 3 4 
1 2 3 4 1 1 2 3 4 5 
1 2 3 4 5 1 1 1 1 1 
1 1 1 1 1 1 1 1 2 3 
1 2 3 4 5 1 2 3 4 5 
1 1 1 1 2 3 4 5 1 1 
1 2 3 4 1 1 1 1 1 1 
1 1 2 3 4 1 2 1 1 2 
1 1 1 1 1 2 1 1 1 1 
1 1 2 ...

result: