题解 | Poi 的新加法(Easy Version)

Poi 的新加法(Easy Version)

https://www.nowcoder.com/practice/9f766daa7e4042a786633c341fe9d7e2

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

const int N = 1e6 + 5;

int T;

int n, q;
LL a[N];

inline void solve(){
    cin>>n>>q;
    for(int i = 1; i <= n; i++) cin>>a[i];
    while(q--) {
        int l , r;
        cin>>l>>r;
        LL ans = a[l];
        for(int i = l + 1; i <= r; i++) ans = ans + a[i] - (ans ^ a[i]);
        cout<<ans<<'\n';
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--) solve();
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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