結果

問題 No.2901 Logical Sum of Substring
ユーザー cai_lw
提出日時 2024-08-18 22:42:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,310 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 197,564 KB
最終ジャッジ日時 2025-02-23 23:08:37
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Queue{
    std::vector<int> fsum,bval;
    int ftop=0,bsum=0;
    void reserve(int n){
        fsum.reserve(n);
        bval.reserve(n);
    }
    void push(int x){
        bsum|=x;
        bval.push_back(x);
    }
    void pop(){
        if(fsum.empty()){
            ftop=0;
            for(auto it=bval.rbegin();it!=bval.rend();++it){
                ftop|=*it;
                fsum.push_back(ftop);
            }
            bval.clear();
            bsum=0;
        }
        fsum.pop_back();
        ftop=fsum.empty()?0:fsum.back();
    }
    int sum() const{
        return ftop|bsum;
    }
};

int main(){
    int n,k,q;
    cin>>n>>k;
    int full=(1<<k)-1;
    vector<int> a(n);
    for(int &x:a)
        cin>>x;
    Queue que;
    que.reserve(n);
    cin>>q;
    while(q--){
        int t,l,r;
        cin>>t>>l>>r;
        if(t==1){
            a[l-1]=r;
        }else{
            int ans=INT_MAX,j=l-1;
            for(int i=l-1;i<r;i++){
                while(j<r&&que.sum()!=full){
                    que.push(a[j]);
                    j++;
                }
                if(que.sum()==full)
                    ans=min(ans,j-i);
                que.pop();
            }
            cout<<(ans==INT_MAX?-1:ans)<<'\n';
        }
    }
}
0