跳到正文

题解

题解:P17332 「TPOI-2B」AND and Subsequence

FloydIJK约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月29日
收录
2026年8月29日
更新
2026年9月11日
篇幅
约 1 分钟
题目
P17332

版本

  1. v1当前

你发现这个操作很菜,随便猜一下,消除不是 00 的 aia_i 时,往右边扩展让它还是能一次消除就是对的。

Code
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define n_ 100005
int a[n_];
void solve(){
    int n;cin>>n;int r=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;){
        int pos=i;if(a[i]==0){
		i++;continue;}
        for(int j=i+1;j<=n;j++){
            if((a[j]&a[i])!=a[i])break;
            pos=j;
        }int lst=i,x=a[i];
        for(int j=i;j<=pos;j++){
            a[j]-=x;
            if(a[j]==0&&lst==j-1)lst=j;
        }i=lst+1;r++;
    }cout<<r<<"\n";
}
signed main(){
    int t;cin>>t;while(t--)solve();
}
原文