結果
| 問題 |
No.2901 Logical Sum of Substring
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-25 18:27:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,054 bytes |
| コンパイル時間 | 1,864 ms |
| コンパイル使用メモリ | 193,052 KB |
| 最終ジャッジ日時 | 2025-02-24 12:19:30 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 TLE * 1 -- * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], c[N], cnt, l, r, x, q, n, k, opt, ans;
void Insert(int x, int id){
for(int i = 0; i < k; ++i){
if(x & (1 << i)){
if(id == 1){
cnt += !c[i];
c[i]++;
}
else{
cnt -= (c[i] == 1);
c[i]--;
}
}
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
cin >> q;
while(q--){
cin >> opt;
if(opt == 1){
cin >> l >> x;
a[l] = x;
}
else{
cin >> l >> r;
for(int i = 0; i < k; ++i){
c[i] = 0;
}
ans = 1e9;
for(int i = l, j = l; i <= r; ++i){
for(; j <= r && cnt != k; j++){
Insert(a[j], 1);
if(j - i + 1 >= ans){
Insert(a[i], -1);
i++;
}
}
if(cnt == k){
ans = min(ans, j - i);
}
Insert(a[i], -1);
}
cout << (ans == 1e9 ? -1 : ans) << '\n';
}
}
return 0;
}
vjudge1