QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140742#5159. Justice ServedAnwar_Gehad_Maghraby#WA 127ms12224kbC++232.1kb2023-08-16 19:00:312023-08-16 19:00:32

Judging History

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

  • [2023-08-16 19:00:32]
  • 评测
  • 测评结果:WA
  • 用时:127ms
  • 内存:12224kb
  • [2023-08-16 19:00:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;


const int N = 2e5 + 4;

int T[1 << 20] ;

int sz ;

void update(int x , int mx , int id = 0 , int tl = 0 ,int tr = sz-1)
{
    if(tl == tr)
    {
        T[id] = max(T[id] , mx) ;

        return;
    }

    int md = (tl + tr ) /2 ;

    if(x <= md) update(x , mx , 2*id + 1 ,tl , md) ;
    else update(x, mx ,2*id + 2, md+1 ,tr ) ;

    T[id] = max(T[2*id + 1] , T[2*id + 2]) ;
}

int get(int l , int r , int id =0 , int tl =0 , int tr = sz-1)
{
    if(l > tr || tl > r )return -1 ;
    if(l <= tl && tr <= r) return T[id] ;

    int md = (tl + tr)  / 2;
    return max(get(l ,r, 2*id +1 ,tl, md) , get(l ,r, 2*id + 2, md+1 ,tr ) ) ;
}

bool ch(pair< pair<int  , int> , int > & a , pair< pair<int  , int> , int > & b)
{
    if(a.first.first != b.first.first) return a.first.first < b.first.first ;

    return a.first.second > b.first.second ;
}

int ans[N] ;

int main() {
    cin.tie(0);cin.sync_with_stdio(0);
    cout.tie(0);cout.sync_with_stdio(0);

    memset(T , -1 ,sizeof T) ;

    int n;
    cin >> n;

    vector< pair< pair<int  , int> , int > > v(n) ;

    vector<int> all ;

    for (int i = 0; i < n; ++i) {
        cin >> v[i].first.first >> v[i].first.second ;
        v[i].second = i;

        all.push_back(v[i].first.first + v[i].first.second - 1) ;
        all.push_back(v[i].first.first) ;
    }

    sort(all.begin() , all.end() ) ;

    all.erase(unique(all.begin() , all.end()) , all.end()) ;

    for (int i = 0; i < n; ++i) {
        v[i].first.first = lower_bound(all.begin() , all.end() , v[i].first.first) - all.begin() ;
        v[i].first.second = lower_bound(all.begin() , all.end() , v[i].first.second + v[i].first.first - 1) - all.begin() ;
    }

    sz = (int)all.size() + 4;

    sort(v.begin() , v.end() , ch) ;

    for (int i = 0; i < n; ++i) {
        ans[ v[i].second ] = 1 + get( v[i].first.second , sz-1) ;
        update(v[i].first.second , ans[v[i].second]) ;
    }

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << " " ;
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7632kb

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

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: 127ms
memory: 12224kb

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:

51067 25775 13 27 12 14 19015 10 88306 37703 10 21158 55423 15 13 19 14 24879 15 9 10 45768 24224 14 14 55424 10 19 12683 19 65167 14 1 33107 29 20827 81112 11 1963 98792 89739 13 95821 44266 89326 17 9 16 4 8131 16033 9 12 90497 70197 36711 17 35 46836 39837 38641 14 53674 9 19 5 19 20 14 83782 159...

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: '51067 25775 13 27 12 14 19015 ... 16 84259 91914 88059 20 12 15 '