QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140744#5159. Justice ServedGamal74#WA 727ms164064kbC++203.4kb2023-08-16 19:08:022023-08-16 19:08:03

Judging History

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

  • [2023-08-16 19:08:03]
  • 评测
  • 测评结果:WA
  • 用时:727ms
  • 内存:164064kb
  • [2023-08-16 19:08:02]
  • 提交

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

詳細信息

Test #1:

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

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: 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
Wrong Answer
time: 727ms
memory: 164064kb

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 3 10 10 12 19010 7 88301 37698 6 21153 55418 12 11 11 10 24874 11 6 8 45763 24219 12 7 55419 7 3 12678 12 65162 11 1 33102 12 20822 81107 8 1958 98787 89734 10 95816 44261 89321 10 6 12 3 8126 16028 8 8 90492 70192 36706 7 10 46831 39832 38636 7 53669 6 12 4 12 12 8 83777 15930 8 4 7 464...

result:

wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '51062 25770 3 10 10 12 19010 7...9 7 12 84254 91909 88054 9 7 6 '