제출 #1301627

#제출 시각아이디문제언어결과실행 시간메모리
1301627InvMODXOR Sum (info1cup17_xorsum)C++17
100 / 100
682 ms17548 KiB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())

template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"

using ll = long long;
using ld = long double;

template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}

const int lg = 29;

/*
    brute:
    + fix a number x and bit B
    + get prefix sum in range [tL, tR]
*/

void Main()
{
    int N; cin >> N;

    vi a(N + 1), o, z, v;
    FOR(i, 1, N){
        cin >> a[i];
        ((a[i] & 1) ? o.eb(i) : z.eb(i));
    }
    v.insert(v.end(), all(z));
    v.insert(v.end(), all(o));

    int ans = 0;
    FOR(b, 0, lg + 1){
        vector<pi> range;
        range.eb(pi((1ll << b), (1ll << b + 1) - 1));
        range.eb(pi((1ll << b + 1) | (1ll << b), (1ll << b + 2) - 1));

        auto f = [&](int x) -> int{
            return (a[x] & ((1 << b + 1) - 1));
        };


        int cnt = 0;
        FOR(_, 0, 1){
            int L, R; L = R = sz(v) - 1;
            FOR(i, 0, sz(v) - 1){
                while(R >= i && f(v[R]) + f(v[i]) > range[_].se) --R;
                while(L >= i && f(v[L]) + f(v[i]) >= range[_].fi) --L;

                if(R >= i){
                    cnt ^= ((R - max(i - 1, L)) & 1);
                }
            }
        }
        ans = ans | (cnt << b);

        o.clear(), z.clear();
        for(int i : v){
            (((a[i] >> (b + 1)) & 1) ? o.eb(i) : z.eb(i));
        }
        v.clear();
        v.insert(v.end(), all(z));
        v.insert(v.end(), all(o));
    }
    cout << ans << el;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    int t = 1; while(t--) Main();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

xorsum.cpp: In function 'int32_t main()':
xorsum.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...