답안 #863013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863013 2023-10-19T13:10:53 Z 8pete8 Osumnjičeni (COCI21_osumnjiceni) C++14
30 / 110
344 ms 71844 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=2*1e5,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(){
    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,pos[i].f,pos[i].s,1);
        update(0,mxn,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)continue;
        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+=(1<<i);
            }
        }
        cout<<ans+1<<'\n';
    }
    //cout<<up[0][1]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 319 ms 71292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19548 KB Output is correct
2 Correct 18 ms 17756 KB Output is correct
3 Correct 18 ms 17796 KB Output is correct
4 Correct 19 ms 17756 KB Output is correct
5 Correct 20 ms 17756 KB Output is correct
6 Correct 17 ms 19804 KB Output is correct
7 Correct 15 ms 17768 KB Output is correct
8 Correct 16 ms 17624 KB Output is correct
9 Correct 16 ms 17756 KB Output is correct
10 Correct 16 ms 17768 KB Output is correct
11 Correct 16 ms 19808 KB Output is correct
12 Correct 19 ms 17500 KB Output is correct
13 Correct 15 ms 17756 KB Output is correct
14 Correct 19 ms 18008 KB Output is correct
15 Correct 17 ms 19804 KB Output is correct
16 Correct 3 ms 17240 KB Output is correct
17 Correct 16 ms 17616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19548 KB Output is correct
2 Correct 18 ms 17756 KB Output is correct
3 Correct 18 ms 17796 KB Output is correct
4 Correct 19 ms 17756 KB Output is correct
5 Correct 20 ms 17756 KB Output is correct
6 Correct 17 ms 19804 KB Output is correct
7 Correct 15 ms 17768 KB Output is correct
8 Correct 16 ms 17624 KB Output is correct
9 Correct 16 ms 17756 KB Output is correct
10 Correct 16 ms 17768 KB Output is correct
11 Correct 16 ms 19808 KB Output is correct
12 Correct 19 ms 17500 KB Output is correct
13 Correct 15 ms 17756 KB Output is correct
14 Correct 19 ms 18008 KB Output is correct
15 Correct 17 ms 19804 KB Output is correct
16 Correct 3 ms 17240 KB Output is correct
17 Correct 16 ms 17616 KB Output is correct
18 Correct 338 ms 20236 KB Output is correct
19 Correct 314 ms 20004 KB Output is correct
20 Correct 332 ms 22424 KB Output is correct
21 Correct 321 ms 20220 KB Output is correct
22 Correct 318 ms 20304 KB Output is correct
23 Correct 312 ms 20168 KB Output is correct
24 Correct 318 ms 20308 KB Output is correct
25 Correct 344 ms 20556 KB Output is correct
26 Correct 313 ms 20264 KB Output is correct
27 Correct 306 ms 20232 KB Output is correct
28 Correct 288 ms 19648 KB Output is correct
29 Correct 323 ms 19756 KB Output is correct
30 Correct 306 ms 19696 KB Output is correct
31 Correct 324 ms 19728 KB Output is correct
32 Correct 294 ms 21752 KB Output is correct
33 Correct 2 ms 17244 KB Output is correct
34 Correct 320 ms 20080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 334 ms 71844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 319 ms 71292 KB Output isn't correct
2 Halted 0 ms 0 KB -