QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140745#5159. Justice ServedGamal74#WA 643ms159048kbC++203.6kb2023-08-16 19:12:242023-08-16 19:12:25

Judging History

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

  • [2023-08-16 19:12:25]
  • 评测
  • 测评结果:WA
  • 用时:643ms
  • 内存:159048kb
  • [2023-08-16 19:12:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define fi first
#define se second
#define pp push_back
#define all(x) (x).begin(), (x).end()
#define Ones(n) __builtin_popcount(n)
#define endl '\n'
#define mem(arrr, xx) memset(arrr,xx,sizeof arrr)
#define PI acos(-1)
//#define int long long
#define debug(x) cout << (#x) << " = " << x << endl

void Gamal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef Clion
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}

int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};

const double EPS = 1e-9;
const ll OO = 0X3F3F3F3F3F3F3F3F;
const int N = 2e5 + 5, INF = INT_MAX, MOD = 1e9 + 7, LOG = 20;

struct segTree {
    vector<set<pii>> seg;
    int sz = 1, n;

    segTree(int nn) {
        n = nn;
        while (sz < nn)
            sz *= 2;
        seg.resize(2 * sz);
    }

    void update(int l, int r, int v, int x, int lx, int rx) {
        bool add = false;
        while (true) {
            auto it = seg[x].upper_bound(make_pair(r, INF));
            if (it == seg[x].begin()) {
                add = true;
                break;
            }
            it--;
            if (v >= it->se) {
                add = true;
                seg[x].erase(it);
            } else break;
        }
        if (add) {
            auto it = seg[x].upper_bound(make_pair(r, INF));
            if (it == seg[x].end() || v > it->se)
                seg[x].insert({r, v});
        }
        if (lx == rx)return;
        int mid = (lx + rx) / 2, lf = 2 * x + 1, rt = 2 * x + 2;
        if (l <= mid)
            update(l, r, v, lf, lx, mid);
        else
            update(l, r, v, rt, mid + 1, rx);
    }

    void update(int l, int r, int v) {
        update(l, r, v, 0, 0, n - 1);
    }

    int query(int l, int r, int x, int lx, int rx) {
        if (rx <= l) {
            // answer
            auto it = seg[x].lower_bound(make_pair(r, -1));
            if (it == seg[x].end())return -1;
            return it->se;
        }
        if (lx > l)return -1;
        int mid = (lx + rx) / 2, lf = 2 * x + 1, rt = 2 * x + 2;
        return max(query(l, r, lf, lx, mid), query(l, r, rt, mid + 1, rx));
    }

    int query(int l, int r) {
        return query(l, r, 0, 0, n - 1);
    }
};


void solve() {
    int n;
    cin >> n;
    vector<pair<pii, int>> v(n);
    vector<int> vals;
    for (int i = 0; i < n; ++i) {
        cin >> v[i].fi.fi >> v[i].fi.se;
        v[i].fi.se += v[i].fi.fi;
        v[i].fi.fi--, v[i].fi.se--;
        vals.push_back(v[i].fi.fi);
        vals.push_back(v[i].fi.se);
        v[i].se = i;
    }
    sort(all(vals));
    vals.erase(unique(all(vals)), vals.end());
    for (int i = 0; i < n; ++i) {
        v[i].fi.fi = lower_bound(all(vals), v[i].fi.fi) - vals.begin();
        v[i].fi.se = lower_bound(all(vals), v[i].fi.se) - vals.begin();
    }
    sort(all(v), [&](pair<pii, int> &a, pair<pii, int> &b) {
        return (a.fi.se - a.fi.fi + 1) > (b.fi.se - b.fi.fi + 1);
    });
    vector<int> ans(n);
    segTree s(2 * n);
    for (int i = 0; i < n; ++i) {
        ans[v[i].se] = s.query(v[i].fi.fi, v[i].fi.se) + 1;
        s.update(v[i].fi.fi, v[i].fi.se, ans[v[i].se]);
    }
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << ' ';
    }

}


signed main() {
    Gamal();
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3528kb

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: 1ms
memory: 3472kb

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: 0
Accepted
time: 607ms
memory: 158576kb

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:

51062 25770 5 10 10 12 19010 7 88301 37698 7 21153 55418 12 11 11 10 24874 11 7 8 45763 24219 12 9 55419 8 4 12678 12 65162 11 1 33102 12 20822 81107 8 1958 98787 89734 10 95816 44261 89321 10 7 12 4 8126 16028 8 8 90492 70192 36706 8 10 46831 39832 38636 9 53669 7 12 4 12 12 10 83777 15930 8 4 8 46...

result:

ok single line: '51062 25770 5 10 10 12 19010 7...9 9 12 84254 91909 88054 9 7 7 '

Test #4:

score: -100
Wrong Answer
time: 643ms
memory: 159048kb

input:

200000
22478286 122609694
2666848 102602877
81344953 155917988
11205360 111352349
81248094 156190492
43638920 143549443
68394626 194903725
17861330 117826788
36708079 136815364
4734745 104627925
90398356 128943645
88701937 133897870
44946698 144761374
75120655 174473016
82684791 151861295
65374243 2...

output:

31 12 62136 28 61965 42 36423 28 43 15 79857 76627 42 49806 64760 30370 44 27 36 43 35942 23 43 86537 44 35 56638 82237 14 42 78728 44 88149 83524 27 14 90213 34740 10 12896 24116 31214 95746 31 80678 65090 39591 69575 15 19350 42 41 76197 11144 27 30708 26 58272 85102 8394 42 72511 31 60311 892 600...

result:

wrong answer 1st lines differ - expected: '31 12 62136 28 61965 42 36423 ...1 94480 42 28 94052 42630 32706', found: '31 12 62136 28 61965 42 36423 ... 94480 42 28 94052 42630 32706 '