結果

問題 No.2901 Logical Sum of Substring
ユーザー cai_lwcai_lw
提出日時 2024-08-18 23:58:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,302 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 206,112 KB
実行使用メモリ 10,916 KB
最終ジャッジ日時 2024-09-20 20:52:19
合計ジャッジ時間 16,074 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 79 ms
5,376 KB
testcase_09 AC 77 ms
5,376 KB
testcase_10 AC 78 ms
5,376 KB
testcase_11 AC 2,518 ms
5,376 KB
testcase_12 AC 2,507 ms
5,376 KB
testcase_13 AC 2,508 ms
5,376 KB
testcase_14 AC 319 ms
5,376 KB
testcase_15 AC 309 ms
5,376 KB
testcase_16 AC 319 ms
5,376 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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()){
            for(int i=bval.size()-1;i>0;i--){
                ftop|=bval[i];
                fsum.push_back(ftop);
            }
            bval.clear();
            bsum=0;
        }else{
            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