QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201416#5159. Justice ServedDelay_for_five_minutes#WA 367ms41724kbC++201.3kb2023-10-05 14:12:062023-10-05 14:12:06

Judging History

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

  • [2023-10-05 14:12:06]
  • 评测
  • 测评结果:WA
  • 用时:367ms
  • 内存:41724kb
  • [2023-10-05 14:12:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
typedef pair<int,int> pii;
map<int,int> mp;
int l[200005] , r[200005];
int ans[200005];
vector<pii> v[400005];
struct fenweick {
    int c[400005];
    fenweick() {
        memset(c,-1,sizeof(c)) ;
    }
    #define lowbit(x) (x&(-x)) ;
    void add(int u,int v) {
        while(u <= n) {
            c[u] = max(c[u] , v) ;
            u += lowbit(u) ;
        }
    }
    int qry(int u) {
        int ans = -1;
        while(u) {
            ans = max(ans , c[u]) ;
            u -= lowbit(u) ;
        }
        return ans;
    }
}fen;
int main()
{
   // freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    cin >> n;
    for(int i = 1;i <= n;i++) {
        int a , t;cin >> a >> t;
        l[i] = a;
        r[i] = a+t;
        mp[a] = 1;mp[a + t] = 1;
    }
    int cnt = 0;
    for(auto &[u,v] : mp) v = ++cnt ;
    for(int i = 1;i <= n;i++) {
        l[i] = mp[l[i]] ;
        r[i] = mp[r[i]] ;
        v[r[i]].push_back({l[i] , i}) ;
    }
    for(int i = cnt ; i >= 1;i--) {
        sort(v[i].begin() , v[i].end()) ;
        for(auto &[l , id] : v[i]) {
            ans[id] = fen.qry(l) + 1;
            fen.add(l , ans[id]) ;
        }
    }
    for(int i = 1;i <= n;i++) cout << ans[i] <<' ' ;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 14956kb

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: 4ms
memory: 15812kb

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: 356ms
memory: 41720kb

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: 0
Accepted
time: 334ms
memory: 41660kb

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:

ok single line: '31 12 62136 28 61965 42 36423 ... 94480 42 28 94052 42630 32706 '

Test #5:

score: 0
Accepted
time: 367ms
memory: 41632kb

input:

200000
3485676 104322522
12830401 115693032
98166050 105206658
50264341 240551623
71635236 180559506
95728650 112122220
23688070 128687885
32526891 139494567
96454278 110061574
98003056 105657846
89652765 129442912
60691912 211220216
79007635 159715353
48164848 246458583
23777776 128837054
80295466 ...

output:

0 0 106298 10083 52636 101374 3 3 102852 105976 89048 30813 67512 5860 3 70053 75079 109116 3 3 3 12746 3 0 3 92826 3 0 0 109335 3 80646 62565 31151 5822 41848 3 29476 0 61200 67480 3 19030 3 0 0 3 0 101282 3 83480 32423 24496 0 9267 90946 47903 3 0 43431 0 2 3 3 0 69688 66155 21401 93179 92527 2967...

result:

ok single line: '0 0 106298 10083 52636 101374 ...2 33293 104473 23128 58257 1 0 '

Test #6:

score: 0
Accepted
time: 343ms
memory: 41724kb

input:

200000
2756775 105169200
62793487 194297574
27888859 152074746
51428236 223127722
36803305 260374362
6127328 111403994
89868556 125636149
4255333 108066624
38444250 256256014
72572904 169620169
86479380 134193427
52543632 220364713
86863477 133213952
64982506 188781981
61978182 196375720
22437971 14...

output:

0 55710 1 32910 3614 0 109807 0 6829 75093 103116 35114 103903 59992 54100 1 16381 92663 111425 2 123134 48157 78425 57257 32682 2 124941 85426 2 2 117043 2 41299 1 12703 1 126791 1 117820 2 73067 109430 0 53341 74893 63219 107840 13687 46471 19083 2 1 13113 107128 4338 100834 6036 0 1 2 75368 0 152...

result:

ok single line: '0 55710 1 32910 3614 0 109807 ...3 32123 37590 14126 107753 1 1 '

Test #7:

score: 0
Accepted
time: 314ms
memory: 41720kb

input:

200000
38721520 120614174
74264049 199951267
8490351 104615052
4412367 102379828
6503466 103469400
57360315 130697733
9525340 105152734
61995492 133160702
8263377 104490093
48862476 126144960
34296652 118335310
27937237 115021595
66447810 229649744
87901810 147007961
19471440 110653662
80164404 1769...

output:

3 18079 1 1 1 3 1 3 1 3 2 2 2587 45543 0 30099 3 27110 2 7906 3 1 27614 2 37320 3 1 0 0 0 3 0 2 0 3 523 3 18677 22098 3 3 0 3 1 21172 1 0 2 0 3 1 3 0 0 7842 3 44246 51176 48207 62295 6414 0 60285 1 3 32700 24531 0 15930 1 63548 3 0 53004 1 42806 11838 3706 59843 3 2 3 0 2 0 3 3 3 3 1 0 3 3 3 2 2 3 0...

result:

ok single line: '3 18079 1 1 1 3 1 3 1 3 2 2 25...24 1 0 2 37127 3 1 19432 43349 '

Test #8:

score: 0
Accepted
time: 3ms
memory: 15672kb

input:

3
1 2
3 2
2 2

output:

0 0 0 

result:

ok single line: '0 0 0 '

Test #9:

score: 0
Accepted
time: 3ms
memory: 16684kb

input:

1
1 1

output:

0 

result:

ok single line: '0 '

Test #10:

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

input:

4
1 3
1 2
2 2
2 1

output:

0 1 1 2 

result:

ok single line: '0 1 1 2 '

Test #11:

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

input:

5
1 4
2 3
1 2
2 2
2 1

output:

0 1 1 2 3 

result:

ok single line: '0 1 1 2 3 '

Test #12:

score: 0
Accepted
time: 3ms
memory: 16048kb

input:

6
1 6
6 5
7 4
9 3
10 2
11 1

output:

0 0 1 0 1 2 

result:

ok single line: '0 0 1 0 1 2 '

Test #13:

score: -100
Wrong Answer
time: 0ms
memory: 14944kb

input:

20
34227248 933434761
120240046 876270748
44578530 656030729
44490919 642226531
34227248 587975195
180397711 485137686
251054019 452891893
251054019 438080574
395968192 409864677
144053797 302891387
756155971 235957485
541312681 186580145
16852198 184550815
31513569 169889444
876043558 120467236
373...

output:

0 0 1 1 1 2 1 2 1 2 1 2 0 1 1 3 1 3 1 2 

result:

wrong answer 1st lines differ - expected: '0 0 1 1 1 2 1 2 1 2 1 2 0 1 1 3 2 3 2 3', found: '0 0 1 1 1 2 1 2 1 2 1 2 0 1 1 3 1 3 1 2 '