Submission #863018

# Submission time Handle Problem Language Result Execution time Memory
863018 2023-10-19T13:17:15 Z 8pete8 Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
541 ms 92064 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mod=9901,mxn=4*1e5+5,inf=1e18,lg=25,minf=-1e18;
int seg[4*mxn+10],add[4*mxn+10],nxt[mxn+10],up[mxn+10][lg+5];
pii pos[mxn+10];
vector<int>v;
vector<pii>id;
void init(){for(int i=0;i<=4*mxn+5;i++)seg[i]=inf,add[i]=inf;}
void push(int pos,int l,int r){
    seg[pos]=min(seg[pos],add[pos]);
    if(l!=r){
        add[pos*2]=min(add[pos],add[pos*2+1]);
        add[pos*2+1]=min(add[pos],add[pos*2+1]);
    }
    add[pos]=inf;
}
int qry(int l,int r,int ql,int qr,int pos){
    push(pos,l,r);
    int mid=l+(r-l)/2;
    if(l>qr||r<ql)return inf; 
    if(ql<=l&&r<=qr)return seg[pos];
    return min(qry(l,mid,ql,qr,pos*2),qry(mid+1,r,ql,qr,pos*2+1));
}
void update(int l,int r,int ql,int qr,int pos,int val){
    push(pos,l,r);
    int mid=l+(r-l)/2;
    if(l>qr||r<ql)return;
    if(ql<=l&&r<=qr){
        add[pos]=min(add[pos],val);
        push(pos,l,r);
        return;
    }
    update(l,mid,ql,qr,pos*2,val);
    update(mid+1,r,ql,qr,pos*2+1,val);
    seg[pos]=min(seg[pos*2],seg[pos*2+1]);
}
int32_t main(){
    fastio
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        id.pb({a,b});
        v.pb(a);
        v.pb(b);
    }
    sort(all(v));
    for(int i=0;i<n;i++){
        pos[i].f=lb(all(v),id[i].f)-v.begin();
        pos[i].s=lb(all(v),id[i].s)-v.begin();
    }
    init();
    nxt[n]=n;
    for(int i=n-1;i>=0;i--){
        nxt[i]=qry(0,mxn+5,pos[i].f,pos[i].s,1);
        update(0,mxn+5,pos[i].f,pos[i].s,1,i);
        nxt[i]=min(nxt[i],nxt[i+1]);
        up[i][0]=nxt[i];
    }
    for(int i=1;i<=lg;i++)for(int j=0;j<n;j++)if(up[j][i-1]!=0)up[j][i]=up[up[j][i-1]][i-1];
    int a,b,ans,m;cin>>m;
    while(m--){
        ans=0;
        cin>>a>>b;
        --a,--b;
        for(int i=lg;i>=0;i--)if(up[a][i]-1<b&&up[a][i])a=up[a][i],ans+=(1ll<<i);
        cout<<ans+1<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 352 ms 87976 KB Output is correct
2 Correct 365 ms 87976 KB Output is correct
3 Correct 353 ms 88740 KB Output is correct
4 Correct 360 ms 87720 KB Output is correct
5 Correct 371 ms 89980 KB Output is correct
6 Correct 153 ms 86424 KB Output is correct
7 Correct 165 ms 88988 KB Output is correct
8 Correct 148 ms 88732 KB Output is correct
9 Correct 159 ms 88324 KB Output is correct
10 Correct 147 ms 88120 KB Output is correct
11 Correct 269 ms 90192 KB Output is correct
12 Correct 247 ms 85548 KB Output is correct
13 Correct 243 ms 86328 KB Output is correct
14 Correct 257 ms 90280 KB Output is correct
15 Correct 249 ms 87948 KB Output is correct
16 Correct 5 ms 30044 KB Output is correct
17 Correct 167 ms 90512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 32604 KB Output is correct
2 Correct 16 ms 32600 KB Output is correct
3 Correct 12 ms 32604 KB Output is correct
4 Correct 12 ms 32604 KB Output is correct
5 Correct 12 ms 32604 KB Output is correct
6 Correct 10 ms 32604 KB Output is correct
7 Correct 9 ms 32604 KB Output is correct
8 Correct 9 ms 32604 KB Output is correct
9 Correct 9 ms 32604 KB Output is correct
10 Correct 9 ms 32604 KB Output is correct
11 Correct 11 ms 32536 KB Output is correct
12 Correct 10 ms 32604 KB Output is correct
13 Correct 10 ms 32604 KB Output is correct
14 Correct 10 ms 32604 KB Output is correct
15 Correct 10 ms 32600 KB Output is correct
16 Correct 4 ms 30296 KB Output is correct
17 Correct 9 ms 32604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 32604 KB Output is correct
2 Correct 16 ms 32600 KB Output is correct
3 Correct 12 ms 32604 KB Output is correct
4 Correct 12 ms 32604 KB Output is correct
5 Correct 12 ms 32604 KB Output is correct
6 Correct 10 ms 32604 KB Output is correct
7 Correct 9 ms 32604 KB Output is correct
8 Correct 9 ms 32604 KB Output is correct
9 Correct 9 ms 32604 KB Output is correct
10 Correct 9 ms 32604 KB Output is correct
11 Correct 11 ms 32536 KB Output is correct
12 Correct 10 ms 32604 KB Output is correct
13 Correct 10 ms 32604 KB Output is correct
14 Correct 10 ms 32604 KB Output is correct
15 Correct 10 ms 32600 KB Output is correct
16 Correct 4 ms 30296 KB Output is correct
17 Correct 9 ms 32604 KB Output is correct
18 Correct 68 ms 33248 KB Output is correct
19 Correct 62 ms 33364 KB Output is correct
20 Correct 68 ms 33364 KB Output is correct
21 Correct 70 ms 33276 KB Output is correct
22 Correct 64 ms 33364 KB Output is correct
23 Correct 61 ms 33384 KB Output is correct
24 Correct 66 ms 33280 KB Output is correct
25 Correct 63 ms 33268 KB Output is correct
26 Correct 67 ms 33400 KB Output is correct
27 Correct 55 ms 33212 KB Output is correct
28 Correct 44 ms 32744 KB Output is correct
29 Correct 45 ms 32860 KB Output is correct
30 Correct 48 ms 32848 KB Output is correct
31 Correct 52 ms 33136 KB Output is correct
32 Correct 48 ms 32900 KB Output is correct
33 Correct 4 ms 30040 KB Output is correct
34 Correct 47 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 91364 KB Output is correct
2 Correct 359 ms 90532 KB Output is correct
3 Correct 335 ms 86168 KB Output is correct
4 Correct 326 ms 85656 KB Output is correct
5 Correct 340 ms 88408 KB Output is correct
6 Correct 157 ms 85932 KB Output is correct
7 Correct 150 ms 85924 KB Output is correct
8 Correct 148 ms 85668 KB Output is correct
9 Correct 155 ms 86688 KB Output is correct
10 Correct 157 ms 90776 KB Output is correct
11 Correct 239 ms 85928 KB Output is correct
12 Correct 272 ms 90152 KB Output is correct
13 Correct 238 ms 85676 KB Output is correct
14 Correct 246 ms 89244 KB Output is correct
15 Correct 265 ms 90836 KB Output is correct
16 Correct 5 ms 30044 KB Output is correct
17 Correct 146 ms 88400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 87976 KB Output is correct
2 Correct 365 ms 87976 KB Output is correct
3 Correct 353 ms 88740 KB Output is correct
4 Correct 360 ms 87720 KB Output is correct
5 Correct 371 ms 89980 KB Output is correct
6 Correct 153 ms 86424 KB Output is correct
7 Correct 165 ms 88988 KB Output is correct
8 Correct 148 ms 88732 KB Output is correct
9 Correct 159 ms 88324 KB Output is correct
10 Correct 147 ms 88120 KB Output is correct
11 Correct 269 ms 90192 KB Output is correct
12 Correct 247 ms 85548 KB Output is correct
13 Correct 243 ms 86328 KB Output is correct
14 Correct 257 ms 90280 KB Output is correct
15 Correct 249 ms 87948 KB Output is correct
16 Correct 5 ms 30044 KB Output is correct
17 Correct 167 ms 90512 KB Output is correct
18 Correct 12 ms 32604 KB Output is correct
19 Correct 16 ms 32600 KB Output is correct
20 Correct 12 ms 32604 KB Output is correct
21 Correct 12 ms 32604 KB Output is correct
22 Correct 12 ms 32604 KB Output is correct
23 Correct 10 ms 32604 KB Output is correct
24 Correct 9 ms 32604 KB Output is correct
25 Correct 9 ms 32604 KB Output is correct
26 Correct 9 ms 32604 KB Output is correct
27 Correct 9 ms 32604 KB Output is correct
28 Correct 11 ms 32536 KB Output is correct
29 Correct 10 ms 32604 KB Output is correct
30 Correct 10 ms 32604 KB Output is correct
31 Correct 10 ms 32604 KB Output is correct
32 Correct 10 ms 32600 KB Output is correct
33 Correct 4 ms 30296 KB Output is correct
34 Correct 9 ms 32604 KB Output is correct
35 Correct 68 ms 33248 KB Output is correct
36 Correct 62 ms 33364 KB Output is correct
37 Correct 68 ms 33364 KB Output is correct
38 Correct 70 ms 33276 KB Output is correct
39 Correct 64 ms 33364 KB Output is correct
40 Correct 61 ms 33384 KB Output is correct
41 Correct 66 ms 33280 KB Output is correct
42 Correct 63 ms 33268 KB Output is correct
43 Correct 67 ms 33400 KB Output is correct
44 Correct 55 ms 33212 KB Output is correct
45 Correct 44 ms 32744 KB Output is correct
46 Correct 45 ms 32860 KB Output is correct
47 Correct 48 ms 32848 KB Output is correct
48 Correct 52 ms 33136 KB Output is correct
49 Correct 48 ms 32900 KB Output is correct
50 Correct 4 ms 30040 KB Output is correct
51 Correct 47 ms 33360 KB Output is correct
52 Correct 389 ms 91364 KB Output is correct
53 Correct 359 ms 90532 KB Output is correct
54 Correct 335 ms 86168 KB Output is correct
55 Correct 326 ms 85656 KB Output is correct
56 Correct 340 ms 88408 KB Output is correct
57 Correct 157 ms 85932 KB Output is correct
58 Correct 150 ms 85924 KB Output is correct
59 Correct 148 ms 85668 KB Output is correct
60 Correct 155 ms 86688 KB Output is correct
61 Correct 157 ms 90776 KB Output is correct
62 Correct 239 ms 85928 KB Output is correct
63 Correct 272 ms 90152 KB Output is correct
64 Correct 238 ms 85676 KB Output is correct
65 Correct 246 ms 89244 KB Output is correct
66 Correct 265 ms 90836 KB Output is correct
67 Correct 5 ms 30044 KB Output is correct
68 Correct 146 ms 88400 KB Output is correct
69 Correct 507 ms 89504 KB Output is correct
70 Correct 541 ms 91548 KB Output is correct
71 Correct 489 ms 86408 KB Output is correct
72 Correct 520 ms 88784 KB Output is correct
73 Correct 512 ms 89860 KB Output is correct
74 Correct 359 ms 92064 KB Output is correct
75 Correct 302 ms 87780 KB Output is correct
76 Correct 310 ms 91044 KB Output is correct
77 Correct 282 ms 87016 KB Output is correct
78 Correct 277 ms 89252 KB Output is correct
79 Correct 321 ms 90968 KB Output is correct
80 Correct 333 ms 85792 KB Output is correct
81 Correct 292 ms 86908 KB Output is correct
82 Correct 314 ms 90404 KB Output is correct
83 Correct 298 ms 88640 KB Output is correct
84 Correct 4 ms 30040 KB Output is correct
85 Correct 207 ms 87244 KB Output is correct