結果

問題 No.3198 Monotonic Query
ユーザー ゼリトキ
提出日時 2025-07-11 21:37:49
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 76 ms / 3,000 ms
コード長 1,308 bytes
コンパイル時間 3,298 ms
コンパイル使用メモリ 275,812 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2025-07-12 10:52:46
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
const long long mod=998244353;
const long long hmod=46216567629137;
class SegmentTree{
    public:
    int dat[800000],siz=1;
    SegmentTree(int N){
        siz=1;
        while(siz<N) siz*=2;
        for(int i=1;i<siz*2;i++) dat[i]=0;
    }
    void update(int pos,int x){
        pos=pos+siz-1;
        dat[pos]=x;
        while(pos>=2){
            pos/=2;
            dat[pos]=max(dat[pos*2],dat[pos*2+1]);
        }
    }
    int query(int l,int r,int a,int b,int u){
        if(r<=a || b<=l) return -1000000000;
        if(l<=a && b<=r) return dat[u];
        int m=(a+b)/2;
        int AnswerL=query(l,r,a,m,u*2);
        int AnswerR=query(l,r,m,b,u*2+1);
        return max(AnswerL,AnswerR);
    }
};
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    int Q;
    cin>>Q;
    int query[Q+1];
    int x[Q+1],k[Q+1];
    int siz=0;
    SegmentTree Z(Q);
    for(int i=1;i<=Q;i++){
        cin>>query[i];
        if(query[i]==1){
            cin>>x[i];
            siz++;
            Z.update(siz,x[i]);
        }
        if(query[i]==2){
            cin>>k[i];
            int ans=Z.query(siz-k[i]+1,siz+1,1,Z.siz+1,1);
            cout<<ans<<"\n";
        }
    }
}
0