Submission #704409

# Submission time Handle Problem Language Result Execution time Memory
704409 2023-03-02T05:48:30 Z Pacybwoah Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
930 ms 74636 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define ll long long
using namespace std;
struct node{
    ll val,tag;
};
vector<node> seg;
void push(ll l,ll r,int ind){
    if(l==r) return;
    ll mid=(l+r)>>1;
    seg[ind*2].val+=(mid-l+1)*seg[ind].tag;
    seg[ind*2+1].val+=(r-mid)*seg[ind].tag;
    seg[ind*2].tag+=seg[ind].tag;
    seg[ind*2+1].tag+=seg[ind].tag;
    seg[ind].tag=0;
}
ll query(ll l,ll r,int start,int end,int ind){
    if(r<start||end<l) return 0;
    if(start<=l&&r<=end){
        return seg[ind].val;
    }
    ll mid=(l+r)>>1;
    push(l,r,ind);
    return query(l,mid,start,end,ind*2)+query(mid+1,r,start,end,ind*2+1);
}
void modify(ll l,ll r,int start,int end,ll num,int ind){
    if(r<start||end<l) return;
    if(start<=l&&r<=end){
        seg[ind].val+=(r-l+1)*num;
        seg[ind].tag+=num;
        return;
    }
    ll mid=(l+r)>>1;
    push(l,r,ind);
    modify(l,mid,start,end,num,ind*2);
    modify(mid+1,r,start,end,num,ind*2+1);
    seg[ind].val=(seg[ind*2].val+seg[ind*2+1].val);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin>>n;
    vector<pair<ll,ll>> vec(n+1);
    for(int i=1;i<=n;i++) cin>>vec[i].first>>vec[i].second;
    vector<ll> cc;
    for(int i=1;i<=n;i++){
        cc.push_back(vec[i].first);
        cc.push_back(vec[i].second);
    }
    sort(cc.begin(),cc.end());
    cc.resize(unique(cc.begin(),cc.end())-cc.begin());
    for(int i=1;i<=n;i++){
        vec[i].first=lower_bound(cc.begin(),cc.end(),vec[i].first)-cc.begin()+1;
        vec[i].second=lower_bound(cc.begin(),cc.end(),vec[i].second)-cc.begin()+1;
    }
    vector<int> far(n+1);
    seg.resize(4*cc.size()+4);
    ll len=cc.size()+1;
    int ii=1;
    for(int i=1;i<=n;i++){
        while(ii<=n&&query(1,len,vec[ii].first,vec[ii].second,1)==0) modify(1,len,vec[ii].first,vec[ii].second,1,1),ii++;
        far[i]=ii;
        modify(1,len,vec[i].first,vec[i].second,-1,1);
    }
    vector<vector<ll>> far2(n+1,vector<ll>(19));
    for(int i=1;i<=n;i++){
        far2[i][0]=far[i];
    }
    for(int i=1;i<19;i++){
        for(int j=1;j<=n;j++){
            if(far2[j][i-1]==n+1) far2[j][i]=n+1;
            else far2[j][i]=far2[far2[j][i-1]][i-1];
        }
    }
    int a,b;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        int ans=1;
        for(int j=18;j>=0;j--){
            if(far2[a][j]<=b){
                a=far2[a][j];
                ans+=(1<<j);
            }
        }
        cout<<ans<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 618 ms 68976 KB Output is correct
2 Correct 569 ms 68108 KB Output is correct
3 Correct 569 ms 68220 KB Output is correct
4 Correct 574 ms 69068 KB Output is correct
5 Correct 715 ms 71996 KB Output is correct
6 Correct 125 ms 42984 KB Output is correct
7 Correct 135 ms 43628 KB Output is correct
8 Correct 136 ms 43968 KB Output is correct
9 Correct 140 ms 44932 KB Output is correct
10 Correct 140 ms 43368 KB Output is correct
11 Correct 395 ms 70224 KB Output is correct
12 Correct 379 ms 65760 KB Output is correct
13 Correct 406 ms 65764 KB Output is correct
14 Correct 451 ms 70136 KB Output is correct
15 Correct 412 ms 68128 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 139 ms 45624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2132 KB Output is correct
2 Correct 12 ms 2000 KB Output is correct
3 Correct 11 ms 2000 KB Output is correct
4 Correct 12 ms 2132 KB Output is correct
5 Correct 12 ms 2004 KB Output is correct
6 Correct 6 ms 1492 KB Output is correct
7 Correct 5 ms 1400 KB Output is correct
8 Correct 5 ms 1532 KB Output is correct
9 Correct 5 ms 1396 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 8 ms 2136 KB Output is correct
12 Correct 9 ms 1992 KB Output is correct
13 Correct 8 ms 2060 KB Output is correct
14 Correct 8 ms 2116 KB Output is correct
15 Correct 8 ms 2124 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2132 KB Output is correct
2 Correct 12 ms 2000 KB Output is correct
3 Correct 11 ms 2000 KB Output is correct
4 Correct 12 ms 2132 KB Output is correct
5 Correct 12 ms 2004 KB Output is correct
6 Correct 6 ms 1492 KB Output is correct
7 Correct 5 ms 1400 KB Output is correct
8 Correct 5 ms 1532 KB Output is correct
9 Correct 5 ms 1396 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 8 ms 2136 KB Output is correct
12 Correct 9 ms 1992 KB Output is correct
13 Correct 8 ms 2060 KB Output is correct
14 Correct 8 ms 2116 KB Output is correct
15 Correct 8 ms 2124 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 1492 KB Output is correct
18 Correct 86 ms 4712 KB Output is correct
19 Correct 75 ms 4428 KB Output is correct
20 Correct 85 ms 4824 KB Output is correct
21 Correct 79 ms 4396 KB Output is correct
22 Correct 83 ms 4496 KB Output is correct
23 Correct 77 ms 4000 KB Output is correct
24 Correct 73 ms 4052 KB Output is correct
25 Correct 78 ms 4040 KB Output is correct
26 Correct 81 ms 3932 KB Output is correct
27 Correct 68 ms 3804 KB Output is correct
28 Correct 50 ms 3984 KB Output is correct
29 Correct 56 ms 4164 KB Output is correct
30 Correct 54 ms 4108 KB Output is correct
31 Correct 54 ms 4048 KB Output is correct
32 Correct 54 ms 4200 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 68 ms 3740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 72332 KB Output is correct
2 Correct 602 ms 70740 KB Output is correct
3 Correct 523 ms 65848 KB Output is correct
4 Correct 527 ms 65228 KB Output is correct
5 Correct 610 ms 67340 KB Output is correct
6 Correct 125 ms 43196 KB Output is correct
7 Correct 128 ms 42800 KB Output is correct
8 Correct 129 ms 43228 KB Output is correct
9 Correct 140 ms 42832 KB Output is correct
10 Correct 163 ms 46112 KB Output is correct
11 Correct 348 ms 65332 KB Output is correct
12 Correct 419 ms 71520 KB Output is correct
13 Correct 376 ms 65184 KB Output is correct
14 Correct 422 ms 67120 KB Output is correct
15 Correct 416 ms 71256 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 117 ms 43820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 618 ms 68976 KB Output is correct
2 Correct 569 ms 68108 KB Output is correct
3 Correct 569 ms 68220 KB Output is correct
4 Correct 574 ms 69068 KB Output is correct
5 Correct 715 ms 71996 KB Output is correct
6 Correct 125 ms 42984 KB Output is correct
7 Correct 135 ms 43628 KB Output is correct
8 Correct 136 ms 43968 KB Output is correct
9 Correct 140 ms 44932 KB Output is correct
10 Correct 140 ms 43368 KB Output is correct
11 Correct 395 ms 70224 KB Output is correct
12 Correct 379 ms 65760 KB Output is correct
13 Correct 406 ms 65764 KB Output is correct
14 Correct 451 ms 70136 KB Output is correct
15 Correct 412 ms 68128 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 139 ms 45624 KB Output is correct
18 Correct 12 ms 2132 KB Output is correct
19 Correct 12 ms 2000 KB Output is correct
20 Correct 11 ms 2000 KB Output is correct
21 Correct 12 ms 2132 KB Output is correct
22 Correct 12 ms 2004 KB Output is correct
23 Correct 6 ms 1492 KB Output is correct
24 Correct 5 ms 1400 KB Output is correct
25 Correct 5 ms 1532 KB Output is correct
26 Correct 5 ms 1396 KB Output is correct
27 Correct 5 ms 1492 KB Output is correct
28 Correct 8 ms 2136 KB Output is correct
29 Correct 9 ms 1992 KB Output is correct
30 Correct 8 ms 2060 KB Output is correct
31 Correct 8 ms 2116 KB Output is correct
32 Correct 8 ms 2124 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 4 ms 1492 KB Output is correct
35 Correct 86 ms 4712 KB Output is correct
36 Correct 75 ms 4428 KB Output is correct
37 Correct 85 ms 4824 KB Output is correct
38 Correct 79 ms 4396 KB Output is correct
39 Correct 83 ms 4496 KB Output is correct
40 Correct 77 ms 4000 KB Output is correct
41 Correct 73 ms 4052 KB Output is correct
42 Correct 78 ms 4040 KB Output is correct
43 Correct 81 ms 3932 KB Output is correct
44 Correct 68 ms 3804 KB Output is correct
45 Correct 50 ms 3984 KB Output is correct
46 Correct 56 ms 4164 KB Output is correct
47 Correct 54 ms 4108 KB Output is correct
48 Correct 54 ms 4048 KB Output is correct
49 Correct 54 ms 4200 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 68 ms 3740 KB Output is correct
52 Correct 632 ms 72332 KB Output is correct
53 Correct 602 ms 70740 KB Output is correct
54 Correct 523 ms 65848 KB Output is correct
55 Correct 527 ms 65228 KB Output is correct
56 Correct 610 ms 67340 KB Output is correct
57 Correct 125 ms 43196 KB Output is correct
58 Correct 128 ms 42800 KB Output is correct
59 Correct 129 ms 43228 KB Output is correct
60 Correct 140 ms 42832 KB Output is correct
61 Correct 163 ms 46112 KB Output is correct
62 Correct 348 ms 65332 KB Output is correct
63 Correct 419 ms 71520 KB Output is correct
64 Correct 376 ms 65184 KB Output is correct
65 Correct 422 ms 67120 KB Output is correct
66 Correct 416 ms 71256 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 117 ms 43820 KB Output is correct
69 Correct 881 ms 70716 KB Output is correct
70 Correct 930 ms 74636 KB Output is correct
71 Correct 799 ms 68816 KB Output is correct
72 Correct 877 ms 72452 KB Output is correct
73 Correct 872 ms 71204 KB Output is correct
74 Correct 438 ms 50216 KB Output is correct
75 Correct 426 ms 46800 KB Output is correct
76 Correct 513 ms 50560 KB Output is correct
77 Correct 432 ms 46700 KB Output is correct
78 Correct 441 ms 47364 KB Output is correct
79 Correct 508 ms 74032 KB Output is correct
80 Correct 504 ms 68620 KB Output is correct
81 Correct 441 ms 68228 KB Output is correct
82 Correct 506 ms 72072 KB Output is correct
83 Correct 470 ms 68656 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 208 ms 46640 KB Output is correct