結果
| 問題 |
No.2901 Logical Sum of Substring
|
| コンテスト | |
| ユーザー |
cai_lw
|
| 提出日時 | 2024-08-19 00:03:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,496 bytes |
| コンパイル時間 | 2,021 ms |
| コンパイル使用メモリ | 196,296 KB |
| 最終ジャッジ日時 | 2025-02-23 23:10:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 TLE * 1 -- * 14 |
ソースコード
#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(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();
}
void clear(){
fsum.clear();
bval.clear();
ftop=0;
bsum=0;
}
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();
}else{
que.clear();
break;
}
}
cout<<(ans==INT_MAX?-1:ans)<<'\n';
}
}
}
cai_lw