题解 | 有趣的区间

有趣的区间

https://www.nowcoder.com/practice/40929e3b2f2e4ca2a481f242f8ffca71

注意到:只要区间内有一个奇数,那异或的结果就为奇数。

#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    long long ans=0;
    int last_1=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x&1)last_1=i;
        ans+=last_1;
    }
    cout<<ans<<endl;
    return 0;
}

全部评论

相关推荐

今天 16:04
已编辑
安徽农业大学 算法工程师
点赞 评论 收藏
分享
03-01 19:30
已编辑
南京大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务