QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501314#5159. Justice ServedmmzskmTL 0ms3600kbC++142.7kb2024-08-02 16:39:042024-08-02 16:39:04

Judging History

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

  • [2024-08-02 16:39:04]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3600kb
  • [2024-08-02 16:39:04]
  • 提交

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;
    }
};

bool cmp(node a, node b)
{
    if (a.st != b.st)
    {
        return a.st < b.st;
    }
    return a.cnt > b.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(), cmp);
    for (int i = 0; i < n; i++)
    {
        v[i].idx = i;
    }
    vector<int> ans(n, 0);
    priority_queue<node> q;
    q.push(v[0]);
    while (q.size())
    {
        node cur = q.top();
        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)//无贡献
            {
                q.push(v[i]);
            }
            else
            {
                ans[v[i].id] = max(ans[cur.id] + 1, ans[v[i].id]);//比最高的高1int 
                int now = v[i].st;
                int l = i + 1, r = n - 1;//左端点大于等于
                int left = i + 1, right = n - 1;  
                while (l <= r)
                {
                    int mid = (l + r) >> 1;
                    if (v[l].st < now)
                    {
                        l = mid + 1;
                        left = l;
                    }
                    else
                    {
                        r = mid - 1;
                    }
                }
                now = v[i].st + v[i].cnt;
                while (l <= r)
                {
                    int mid = (l + r) >> 1;
                    if (v[l].st + v[l].cnt < now)
                    {
                        l = mid + 1;
                        right = l;
                    }
                    else
                    {
                        r = mid - 1;
                    }
                }
                if (left <= right)
                {
                    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: 3536kb

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: 3600kb

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: