답안 #556914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556914 2022-05-04T11:00:43 Z new_acc Osumnjičeni (COCI21_osumnjiceni) C++14
30 / 110
80 ms 3640 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=2e5+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();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 3540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1100 KB Output is correct
2 Correct 10 ms 1064 KB Output is correct
3 Correct 10 ms 1076 KB Output is correct
4 Correct 11 ms 1108 KB Output is correct
5 Correct 12 ms 1092 KB Output is correct
6 Correct 7 ms 980 KB Output is correct
7 Correct 7 ms 944 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 7 ms 1108 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 7 ms 1104 KB Output is correct
14 Correct 8 ms 1108 KB Output is correct
15 Correct 7 ms 1108 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 6 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1100 KB Output is correct
2 Correct 10 ms 1064 KB Output is correct
3 Correct 10 ms 1076 KB Output is correct
4 Correct 11 ms 1108 KB Output is correct
5 Correct 12 ms 1092 KB Output is correct
6 Correct 7 ms 980 KB Output is correct
7 Correct 7 ms 944 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 8 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 7 ms 1108 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 7 ms 1104 KB Output is correct
14 Correct 8 ms 1108 KB Output is correct
15 Correct 7 ms 1108 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 6 ms 852 KB Output is correct
18 Correct 74 ms 1900 KB Output is correct
19 Correct 66 ms 1816 KB Output is correct
20 Correct 80 ms 1992 KB Output is correct
21 Correct 68 ms 1828 KB Output is correct
22 Correct 77 ms 1900 KB Output is correct
23 Correct 65 ms 1652 KB Output is correct
24 Correct 70 ms 1824 KB Output is correct
25 Correct 68 ms 1732 KB Output is correct
26 Correct 66 ms 1612 KB Output is correct
27 Correct 64 ms 1672 KB Output is correct
28 Correct 48 ms 1484 KB Output is correct
29 Correct 51 ms 1484 KB Output is correct
30 Correct 49 ms 1348 KB Output is correct
31 Correct 50 ms 1356 KB Output is correct
32 Correct 53 ms 1384 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 54 ms 1800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 3640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 3540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -