QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501384#5159. Justice ServedmmzskmTL 0ms3760kbC++143.1kb2024-08-02 17:37:192024-08-02 17:37:19

Judging History

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

  • [2024-08-02 17:37:19]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3760kb
  • [2024-08-02 17:37:19]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<stack>
#include<iomanip>
#include<cmath>
using namespace std;
using ll = long long;
#define int ll
typedef pair<int, int> pii;

struct node
{
    int id, st, cnt, idx;
    bool operator<(const node& a) const 
    {
        if (st != a.st)
        {
            return st < a.st;
        }
        return cnt > a.cnt;
    }
};


void solve()
{
    int n;
    cin >> n;
    vector<node> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].st >> v[i].cnt;
        v[i].id = i;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        v[i].idx = i;
    }
    vector<int> ans(n, 0);
    ////////
    //for (int i = 0; i < n; i++)
    //{
    //    for (int j = i + 1; j < n; j++)
    //    {
    //        if (v[i].st <= v[j].st && v[i].st + v[i].cnt >= v[j].st + v[j].cnt)
    //        {
    //            ans[v[i].id] = max(ans[v[i].id] + 1, ans[v[i].id]);
    //        }
    //    }
    //}
    ///////
    vector<bool> inque(n, false);
    priority_queue<node> q;
    q.push(v[0]);
    inque[v[0].id] = true;
    while (q.size())
    {
        node cur = q.top();
        inque[cur.id] = false;
        q.pop();
        for (int i = cur.idx + 1; i < n; i++)//遍历之后的人
        {
            if (cur.st <= v[i].st && cur.st + cur.cnt >= v[i].st + v[i].cnt)//有贡献
            {
                ans[v[i].id] = max(ans[cur.id] + 1, ans[v[i].id]);
            }
            if (!inque[cur.id])//不在队里且还有贡献
            {
                q.push(v[i]);
                inque[cur.id] = true;
            }
        }
       /* int l = cur.idx + 1, r = n - 1;
        int left = cur.idx + 1, right = n - 1;
        while (l <= r)
        {
            int mid = (l + r) >> 1;
            if (v[l].st > mid)
            {
                l = mid + 1;
                left = l;
            }
            else
            {
                r = mid - 1;
            }
        }*/
        //l = left, r = n - 1;
        //while (l <= r)
        //{
        //    int mid = (l + r) >> 1;
        //    if (v[l].st + v[l].cnt < mid)
        //    {
        //        l = mid + 1;
        //        right = l;
        //    }
        //    else
        //    {
        //        r = mid - 1;
        //    }
        //}
        //for (int i = left; i < n; i++)//遍历之后的人
        //{
        //    if (cur.st <= v[i].st && cur.st + cur.cnt >= v[i].st + v[i].cnt)//有贡献
        //    {
        //        ans[v[i].id] = max(ans[cur.id] + 1, ans[v[i].id]);
        //    }
        //    if (!inque[cur.id])//不在队里且还有贡献
        //    {
        //        q.push(v[i]);
        //    }
        //}
    }
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }
}

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

    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

4
2 8
1 7
4 5
5 2

output:

0 0 1 2 

result:

ok single line: '0 0 1 2 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

5
2 4
3 3
2 2
4 2
4 1

output:

0 1 1 2 3 

result:

ok single line: '0 1 1 2 3 '

Test #3:

score: -100
Time Limit Exceeded

input:

200000
75760147 173015388
62879760 211229046
6728658 106668560
29476341 129401393
30531505 130450085
39792769 139780734
59486082 221617335
12447225 112582555
94207716 117434450
68962063 193352291
13519090 113644734
60611935 218232526
77901558 166662816
40316254 140281744
39094390 138994435
49921965 ...

output:


result: