답안 #704024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704024 2023-03-01T11:41:24 Z Pacybwoah Osumnjičeni (COCI21_osumnjiceni) C++14
60 / 110
1000 ms 193048 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);
    }
    if(n<=5000){
        vector<vector<ll>> preans(n+1,vector<ll>(n+1));
        for(int i=1;i<=n;i++){
            int cur=1,j=i,tmp=i;
            while(j<=n){
                for(;j<far[tmp];j++){
                    preans[i][j]=cur;
                }
                cur++;
                tmp=far[tmp];
            }
        }
        int a,b;
        cin>>q;
        for(int i=0;i<q;i++){
            cin>>a>>b;
            cout<<preans[a][b]<<"\n";
        }
        return 0;
    }
    int a,b;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        int ans=0;
        while(a<=b){
            a=far[a];
            ans++;
        }
        cout<<ans<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 504 ms 31528 KB Output is correct
2 Correct 474 ms 31052 KB Output is correct
3 Correct 477 ms 31208 KB Output is correct
4 Correct 487 ms 31548 KB Output is correct
5 Correct 507 ms 32984 KB Output is correct
6 Correct 50 ms 7876 KB Output is correct
7 Correct 61 ms 7876 KB Output is correct
8 Correct 66 ms 8084 KB Output is correct
9 Correct 72 ms 8020 KB Output is correct
10 Correct 80 ms 7948 KB Output is correct
11 Correct 308 ms 32284 KB Output is correct
12 Correct 324 ms 30244 KB Output is correct
13 Correct 285 ms 30220 KB Output is correct
14 Correct 330 ms 32212 KB Output is correct
15 Correct 321 ms 31440 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 56 ms 8084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 191432 KB Output is correct
2 Correct 115 ms 167916 KB Output is correct
3 Correct 111 ms 170448 KB Output is correct
4 Correct 123 ms 183764 KB Output is correct
5 Correct 114 ms 163256 KB Output is correct
6 Correct 108 ms 192188 KB Output is correct
7 Correct 109 ms 169696 KB Output is correct
8 Correct 112 ms 186188 KB Output is correct
9 Correct 103 ms 169516 KB Output is correct
10 Correct 97 ms 170612 KB Output is correct
11 Correct 89 ms 192172 KB Output is correct
12 Correct 91 ms 171016 KB Output is correct
13 Correct 83 ms 175308 KB Output is correct
14 Correct 95 ms 187472 KB Output is correct
15 Correct 90 ms 192560 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 100 ms 179428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 191432 KB Output is correct
2 Correct 115 ms 167916 KB Output is correct
3 Correct 111 ms 170448 KB Output is correct
4 Correct 123 ms 183764 KB Output is correct
5 Correct 114 ms 163256 KB Output is correct
6 Correct 108 ms 192188 KB Output is correct
7 Correct 109 ms 169696 KB Output is correct
8 Correct 112 ms 186188 KB Output is correct
9 Correct 103 ms 169516 KB Output is correct
10 Correct 97 ms 170612 KB Output is correct
11 Correct 89 ms 192172 KB Output is correct
12 Correct 91 ms 171016 KB Output is correct
13 Correct 83 ms 175308 KB Output is correct
14 Correct 95 ms 187472 KB Output is correct
15 Correct 90 ms 192560 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 100 ms 179428 KB Output is correct
18 Correct 183 ms 184656 KB Output is correct
19 Correct 171 ms 171520 KB Output is correct
20 Correct 194 ms 193048 KB Output is correct
21 Correct 170 ms 169976 KB Output is correct
22 Correct 166 ms 162448 KB Output is correct
23 Correct 155 ms 176844 KB Output is correct
24 Correct 177 ms 182560 KB Output is correct
25 Correct 165 ms 167384 KB Output is correct
26 Correct 165 ms 186292 KB Output is correct
27 Correct 162 ms 179532 KB Output is correct
28 Correct 139 ms 175364 KB Output is correct
29 Correct 144 ms 169660 KB Output is correct
30 Correct 147 ms 174136 KB Output is correct
31 Correct 138 ms 165532 KB Output is correct
32 Correct 143 ms 192344 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 135 ms 175472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 32828 KB Output is correct
2 Correct 507 ms 32232 KB Output is correct
3 Correct 474 ms 30184 KB Output is correct
4 Correct 471 ms 29748 KB Output is correct
5 Correct 479 ms 30748 KB Output is correct
6 Correct 62 ms 7928 KB Output is correct
7 Correct 69 ms 7856 KB Output is correct
8 Correct 70 ms 7936 KB Output is correct
9 Correct 74 ms 7876 KB Output is correct
10 Correct 88 ms 8056 KB Output is correct
11 Correct 299 ms 30024 KB Output is correct
12 Correct 327 ms 32820 KB Output is correct
13 Correct 296 ms 30104 KB Output is correct
14 Correct 333 ms 30780 KB Output is correct
15 Correct 350 ms 32692 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 88 ms 7900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 504 ms 31528 KB Output is correct
2 Correct 474 ms 31052 KB Output is correct
3 Correct 477 ms 31208 KB Output is correct
4 Correct 487 ms 31548 KB Output is correct
5 Correct 507 ms 32984 KB Output is correct
6 Correct 50 ms 7876 KB Output is correct
7 Correct 61 ms 7876 KB Output is correct
8 Correct 66 ms 8084 KB Output is correct
9 Correct 72 ms 8020 KB Output is correct
10 Correct 80 ms 7948 KB Output is correct
11 Correct 308 ms 32284 KB Output is correct
12 Correct 324 ms 30244 KB Output is correct
13 Correct 285 ms 30220 KB Output is correct
14 Correct 330 ms 32212 KB Output is correct
15 Correct 321 ms 31440 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 56 ms 8084 KB Output is correct
18 Correct 130 ms 191432 KB Output is correct
19 Correct 115 ms 167916 KB Output is correct
20 Correct 111 ms 170448 KB Output is correct
21 Correct 123 ms 183764 KB Output is correct
22 Correct 114 ms 163256 KB Output is correct
23 Correct 108 ms 192188 KB Output is correct
24 Correct 109 ms 169696 KB Output is correct
25 Correct 112 ms 186188 KB Output is correct
26 Correct 103 ms 169516 KB Output is correct
27 Correct 97 ms 170612 KB Output is correct
28 Correct 89 ms 192172 KB Output is correct
29 Correct 91 ms 171016 KB Output is correct
30 Correct 83 ms 175308 KB Output is correct
31 Correct 95 ms 187472 KB Output is correct
32 Correct 90 ms 192560 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 100 ms 179428 KB Output is correct
35 Correct 183 ms 184656 KB Output is correct
36 Correct 171 ms 171520 KB Output is correct
37 Correct 194 ms 193048 KB Output is correct
38 Correct 170 ms 169976 KB Output is correct
39 Correct 166 ms 162448 KB Output is correct
40 Correct 155 ms 176844 KB Output is correct
41 Correct 177 ms 182560 KB Output is correct
42 Correct 165 ms 167384 KB Output is correct
43 Correct 165 ms 186292 KB Output is correct
44 Correct 162 ms 179532 KB Output is correct
45 Correct 139 ms 175364 KB Output is correct
46 Correct 144 ms 169660 KB Output is correct
47 Correct 147 ms 174136 KB Output is correct
48 Correct 138 ms 165532 KB Output is correct
49 Correct 143 ms 192344 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 135 ms 175472 KB Output is correct
52 Correct 532 ms 32828 KB Output is correct
53 Correct 507 ms 32232 KB Output is correct
54 Correct 474 ms 30184 KB Output is correct
55 Correct 471 ms 29748 KB Output is correct
56 Correct 479 ms 30748 KB Output is correct
57 Correct 62 ms 7928 KB Output is correct
58 Correct 69 ms 7856 KB Output is correct
59 Correct 70 ms 7936 KB Output is correct
60 Correct 74 ms 7876 KB Output is correct
61 Correct 88 ms 8056 KB Output is correct
62 Correct 299 ms 30024 KB Output is correct
63 Correct 327 ms 32820 KB Output is correct
64 Correct 296 ms 30104 KB Output is correct
65 Correct 333 ms 30780 KB Output is correct
66 Correct 350 ms 32692 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 88 ms 7900 KB Output is correct
69 Execution timed out 1081 ms 34136 KB Time limit exceeded
70 Halted 0 ms 0 KB -