Submission #556915

# Submission time Handle Problem Language Result Execution time Memory
556915 2022-05-04T11:03:16 Z new_acc Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
609 ms 33720 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=4e5+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=18;
pair<int,int> sorted[N],t[N];
int seg[(SS<<1)+10],lazy[(SS<<1)+10],nxt[N],jump[N][L+1];
void push(int v){
    lazy[(v<<1)]+=lazy[v],lazy[(v<<1)+1]+=lazy[v];
    seg[(v<<1)]+=lazy[v],seg[(v<<1)+1]+=lazy[v];
    lazy[v]=0;
}
void upd(int a,int b,int x,int p=0,int k=SS-1,int v=1){
    if(p>b or k<a) return;
    if(p>=a and k<=b){
        seg[v]+=x,lazy[v]+=x;
        return;
    }
    push(v);
    upd(a,b,x,p,(p+k)>>1,(v<<1)),upd(a,b,x,((p+k)>>1)+1,k,(v<<1)+1);
    seg[v]=max(seg[(v<<1)],seg[(v<<1)+1]);
}
int Query(int a,int b,int p=0,int k=SS-1,int v=1){
    if(p>b or k<a) return 0;
    if(p>=a and k<=b) return seg[v];
    push(v);
    return max(Query(a,b,p,(p+k)>>1,v<<1),Query(a,b,((p+k)>>1)+1,k,(v<<1)+1));
}
void solve(){
    int n;
    cin>>n;
    int curr=0;
    for(int a,b,i=1;i<=n;i++){
        cin>>a>>b;
        sorted[++curr]={a,i},sorted[++curr]={b,-i}; 
    }
    sort(sorted+1,sorted+1+curr);
    int l=0;
    for(int i=1;i<=curr;i++){
        if(sorted[i].fi!=sorted[i-1].fi or i==1) l++;
        if(sorted[i].se>0) t[sorted[i].se].fi=l;
        else t[sorted[i].se*(-1)].se=l;
    }
    curr=0;
    for(int i=1;i<=n;i++){
        curr=max(curr,i);
        while(curr<=n and Query(t[curr].fi,t[curr].se)==0){
            upd(t[curr].fi,t[curr].se,1);
            ++curr;
        }
        nxt[i]=curr;
        upd(t[i].fi,t[i].se,-1);
        jump[i][0]=nxt[i];
    }
    for(int i=0;i<=L;i++) jump[n+1][i]=n+1;
    for(int i=n;i>=1;i--)
        for(int k=1;k<=L;k++) jump[i][k]=jump[jump[i][k-1]][k-1];
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        int res=1;
        for(int i=L;i>=0;i--)
            if(jump[a][i]<=b) res+=(1<<i),a=jump[a][i];
        cout<<res<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 427 ms 27256 KB Output is correct
2 Correct 486 ms 29064 KB Output is correct
3 Correct 430 ms 29192 KB Output is correct
4 Correct 466 ms 29500 KB Output is correct
5 Correct 464 ms 30772 KB Output is correct
6 Correct 194 ms 22288 KB Output is correct
7 Correct 197 ms 22712 KB Output is correct
8 Correct 218 ms 22908 KB Output is correct
9 Correct 226 ms 23440 KB Output is correct
10 Correct 242 ms 22592 KB Output is correct
11 Correct 252 ms 29584 KB Output is correct
12 Correct 261 ms 27872 KB Output is correct
13 Correct 243 ms 27672 KB Output is correct
14 Correct 283 ms 29684 KB Output is correct
15 Correct 306 ms 28816 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 205 ms 23876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1108 KB Output is correct
2 Correct 13 ms 1152 KB Output is correct
3 Correct 11 ms 984 KB Output is correct
4 Correct 12 ms 980 KB Output is correct
5 Correct 12 ms 956 KB Output is correct
6 Correct 8 ms 956 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 8 ms 852 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 6 ms 980 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 7 ms 980 KB Output is correct
15 Correct 7 ms 980 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 6 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1108 KB Output is correct
2 Correct 13 ms 1152 KB Output is correct
3 Correct 11 ms 984 KB Output is correct
4 Correct 12 ms 980 KB Output is correct
5 Correct 12 ms 956 KB Output is correct
6 Correct 8 ms 956 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 8 ms 852 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 6 ms 980 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 7 ms 980 KB Output is correct
15 Correct 7 ms 980 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 6 ms 980 KB Output is correct
18 Correct 77 ms 1932 KB Output is correct
19 Correct 66 ms 1804 KB Output is correct
20 Correct 81 ms 2116 KB Output is correct
21 Correct 69 ms 1824 KB Output is correct
22 Correct 73 ms 1868 KB Output is correct
23 Correct 64 ms 1692 KB Output is correct
24 Correct 68 ms 1716 KB Output is correct
25 Correct 70 ms 1868 KB Output is correct
26 Correct 67 ms 1632 KB Output is correct
27 Correct 62 ms 1524 KB Output is correct
28 Correct 47 ms 1340 KB Output is correct
29 Correct 52 ms 1392 KB Output is correct
30 Correct 50 ms 1376 KB Output is correct
31 Correct 51 ms 1284 KB Output is correct
32 Correct 49 ms 1368 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 55 ms 1840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 531 ms 28668 KB Output is correct
2 Correct 466 ms 30160 KB Output is correct
3 Correct 423 ms 28116 KB Output is correct
4 Correct 416 ms 27844 KB Output is correct
5 Correct 430 ms 28724 KB Output is correct
6 Correct 184 ms 22472 KB Output is correct
7 Correct 200 ms 22396 KB Output is correct
8 Correct 206 ms 22480 KB Output is correct
9 Correct 208 ms 22284 KB Output is correct
10 Correct 240 ms 24036 KB Output is correct
11 Correct 226 ms 27500 KB Output is correct
12 Correct 269 ms 30244 KB Output is correct
13 Correct 231 ms 27652 KB Output is correct
14 Correct 280 ms 28360 KB Output is correct
15 Correct 293 ms 30000 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 193 ms 22884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 427 ms 27256 KB Output is correct
2 Correct 486 ms 29064 KB Output is correct
3 Correct 430 ms 29192 KB Output is correct
4 Correct 466 ms 29500 KB Output is correct
5 Correct 464 ms 30772 KB Output is correct
6 Correct 194 ms 22288 KB Output is correct
7 Correct 197 ms 22712 KB Output is correct
8 Correct 218 ms 22908 KB Output is correct
9 Correct 226 ms 23440 KB Output is correct
10 Correct 242 ms 22592 KB Output is correct
11 Correct 252 ms 29584 KB Output is correct
12 Correct 261 ms 27872 KB Output is correct
13 Correct 243 ms 27672 KB Output is correct
14 Correct 283 ms 29684 KB Output is correct
15 Correct 306 ms 28816 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 205 ms 23876 KB Output is correct
18 Correct 13 ms 1108 KB Output is correct
19 Correct 13 ms 1152 KB Output is correct
20 Correct 11 ms 984 KB Output is correct
21 Correct 12 ms 980 KB Output is correct
22 Correct 12 ms 956 KB Output is correct
23 Correct 8 ms 956 KB Output is correct
24 Correct 8 ms 852 KB Output is correct
25 Correct 8 ms 852 KB Output is correct
26 Correct 8 ms 852 KB Output is correct
27 Correct 7 ms 852 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 7 ms 980 KB Output is correct
30 Correct 7 ms 980 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 7 ms 980 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 6 ms 980 KB Output is correct
35 Correct 77 ms 1932 KB Output is correct
36 Correct 66 ms 1804 KB Output is correct
37 Correct 81 ms 2116 KB Output is correct
38 Correct 69 ms 1824 KB Output is correct
39 Correct 73 ms 1868 KB Output is correct
40 Correct 64 ms 1692 KB Output is correct
41 Correct 68 ms 1716 KB Output is correct
42 Correct 70 ms 1868 KB Output is correct
43 Correct 67 ms 1632 KB Output is correct
44 Correct 62 ms 1524 KB Output is correct
45 Correct 47 ms 1340 KB Output is correct
46 Correct 52 ms 1392 KB Output is correct
47 Correct 50 ms 1376 KB Output is correct
48 Correct 51 ms 1284 KB Output is correct
49 Correct 49 ms 1368 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 55 ms 1840 KB Output is correct
52 Correct 531 ms 28668 KB Output is correct
53 Correct 466 ms 30160 KB Output is correct
54 Correct 423 ms 28116 KB Output is correct
55 Correct 416 ms 27844 KB Output is correct
56 Correct 430 ms 28724 KB Output is correct
57 Correct 184 ms 22472 KB Output is correct
58 Correct 200 ms 22396 KB Output is correct
59 Correct 206 ms 22480 KB Output is correct
60 Correct 208 ms 22284 KB Output is correct
61 Correct 240 ms 24036 KB Output is correct
62 Correct 226 ms 27500 KB Output is correct
63 Correct 269 ms 30244 KB Output is correct
64 Correct 231 ms 27652 KB Output is correct
65 Correct 280 ms 28360 KB Output is correct
66 Correct 293 ms 30000 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 193 ms 22884 KB Output is correct
69 Correct 608 ms 32200 KB Output is correct
70 Correct 598 ms 33720 KB Output is correct
71 Correct 602 ms 31196 KB Output is correct
72 Correct 609 ms 33064 KB Output is correct
73 Correct 599 ms 32484 KB Output is correct
74 Correct 394 ms 28008 KB Output is correct
75 Correct 389 ms 26144 KB Output is correct
76 Correct 426 ms 28028 KB Output is correct
77 Correct 374 ms 25916 KB Output is correct
78 Correct 373 ms 26352 KB Output is correct
79 Correct 328 ms 32888 KB Output is correct
80 Correct 315 ms 30452 KB Output is correct
81 Correct 299 ms 30392 KB Output is correct
82 Correct 365 ms 31964 KB Output is correct
83 Correct 335 ms 30412 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 252 ms 25972 KB Output is correct