結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー askr58askr58
提出日時 2024-02-23 23:20:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,500 ms
コード長 1,670 bytes
コンパイル時間 4,358 ms
コンパイル使用メモリ 258,388 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 23:20:25
合計ジャッジ時間 14,557 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 119 ms
6,676 KB
testcase_03 AC 29 ms
6,676 KB
testcase_04 AC 172 ms
6,676 KB
testcase_05 AC 139 ms
6,676 KB
testcase_06 AC 70 ms
6,676 KB
testcase_07 AC 143 ms
6,676 KB
testcase_08 AC 63 ms
6,676 KB
testcase_09 AC 301 ms
6,676 KB
testcase_10 AC 308 ms
6,676 KB
testcase_11 AC 305 ms
6,676 KB
testcase_12 AC 333 ms
6,676 KB
testcase_13 AC 308 ms
6,676 KB
testcase_14 AC 307 ms
6,676 KB
testcase_15 AC 304 ms
6,676 KB
testcase_16 AC 297 ms
6,676 KB
testcase_17 AC 283 ms
6,676 KB
testcase_18 AC 298 ms
6,676 KB
testcase_19 AC 297 ms
6,676 KB
testcase_20 AC 298 ms
6,676 KB
testcase_21 AC 290 ms
6,676 KB
testcase_22 AC 290 ms
6,676 KB
testcase_23 AC 275 ms
6,676 KB
testcase_24 AC 273 ms
6,676 KB
testcase_25 AC 272 ms
6,676 KB
testcase_26 AC 278 ms
6,676 KB
testcase_27 AC 276 ms
6,676 KB
testcase_28 AC 274 ms
6,676 KB
testcase_29 AC 274 ms
6,676 KB
testcase_30 AC 291 ms
6,676 KB
testcase_31 AC 277 ms
6,676 KB
testcase_32 AC 205 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=998244353;

vector<pair<int,int>> sortedx;
struct lst{
    int sz,n;
    vector<int> node;
    lst(){}
    lst(int n):n(n){
        sz=1;
        while(sz<n)sz*=2;
        node.resize(2*sz,-1);
    }

    void operate(int l,int r,int t){
        l+=sz;r+=sz;
        while(l<r){
            if(l&1)node[l++]=t;
            if(r&1)node[--r]=t;
            l>>=1;
            r>>=1;
        }
    }

    void print(){
        for(int i=1;i<sz;i++){
            node[i*2]=max(node[i*2],node[i]);
            node[i*2+1]=max(node[i*2+1],node[i]);
        }
        vector<int> ans(n);
        for(int i=0;i<n;i++)ans[sortedx[i].second]=node[i+sz];
        for(int i=0;i<n;i++)cout<<ans[i]<<endl;

    }
};
int main(){
    
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    for(int i=0;i<n;i++)cin>>x[i];
    if(n==1){
        int t;
        cin>>t;
        int ans=-1;
        for(int i=0;i<t;i++){
            int l,r;
            cin>>l>>r;
            if(l<=x[0]&&x[0]<=r)ans=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    sortedx.resize(n);
    for(int i=0;i<n;i++){
        sortedx[i].first=x[i];
        sortedx[i].second=i;
    }
    sort(sortedx.begin(),sortedx.end());
    auto f=[&](int p){
        int l=-1,r=n;
        while(l+1<r){
            int c=(l+r)/2;
            if(sortedx[c].first<=p)l=c;
            else r=c;
        }
        return l;
    };
    lst ls(n);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int l,r;

        cin>>l>>r;
        l=f(l-1)+1;
        r=f(r)+1;
        ls.operate(l,r,i+1);

    }
    ls.print();




    
}
0