답안 #918768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918768 2024-01-30T11:57:12 Z JakobZorz Abracadabra (CEOI22_abracadabra) C++17
0 / 100
3000 ms 19900 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int n;
int l[200001];
int r[200001];
vector<int>init;

void insert(int a,int b){
    if(a==b){
        a=0;
        b=0;
    }
    l[init[a]]=a;
    r[init[a]]=b;
}

pair<int,int>get(int sum){
    for(int i=0;i<=n;i++){
        sum-=r[i]-l[i];
        if(sum<0)
            return{i,sum+r[i]-l[i]};
    }
    abort();
}

void solve(){
    int q;
    cin>>n>>q;
    init.resize(n);
    vector<int>nxt(n);
    for(int&i:init)
        cin>>i;
    
    stack<pair<int,int>>st;
    st.push({n+1,n});
    for(int i=n-1;i>=0;i--){
        while(st.top().first<init[i])
            st.pop();
        nxt[i]=st.top().second;
        st.push({init[i],i});
    }
    
    vector<vector<pair<int,int>>>qrs(n+1);
    vector<int>ans(q,-1);
    for(int i=0;i<q;i++){
        int t,qi;
        cin>>t>>qi;
        t=min(t,n);
        qrs[t].push_back({qi-1,i});
    }
    
    for(int curr=0;curr<n;){
        insert(curr,nxt[curr]);
        curr=nxt[curr];
    }
    
    for(int round=0;round<=n;round++){
        for(auto i:qrs[round]){
            auto res=get(i.first);
            
            ans[i.second]=init[l[res.first]+res.second];
        }
        
        auto res=get(n/2);
        
        if(res.second==0)
            continue;
        
        int nl=l[res.first]+res.second;
        int nr=r[res.first];
        insert(l[res.first],l[res.first]+res.second);
        
        for(int curr=nl;curr<nr;){
            insert(curr,nxt[curr]);
            curr=nxt[curr];
        }
    }
    
    for(int i:ans){
        if(i==-1)
            abort();
        cout<<i<<"\n";
    }
}
 
int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("input.in","r",stdin);freopen("output.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}

/*
6 6
1 4 2 3 5 6
0 1
0 2
0 3
0 4
0 5
0 6

1
4
2
3
5
6

6 3
1 5 6 2 3 4
1 2
0 4
1 5
 
2
2
5
 

6 6
2 1 5 4 6 3
0 1
1 1
0 3
1 3
0 6
10 6
 
2
2
5
4
3
3
 

10 10
7 5 2 9 10 8 4 3 6 1
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
 
2
3
6
1
7
5
8
4
9
10
 
6 6
4 5 6 1 2 3
10 1
10 2
10 3
10 4
10 5
10 6
 
1
2
3
4
5
6
 
 
 */
# 결과 실행 시간 메모리 Grader output
1 Incorrect 425 ms 18512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 19900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3045 ms 6388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 425 ms 18512 KB Output isn't correct
2 Halted 0 ms 0 KB -