답안 #97196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97196 2019-02-14T10:03:17 Z caesar2001 XOR Sum (info1cup17_xorsum) C++14
100 / 100
1568 ms 35704 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>

using namespace std;

typedef long long ll;

ll getsol(int n, const vector<pair<int, int>> &v, int l, int r) {
    int i = n, k = n;
    ll ans = 0;
    for(int j = 1; j <= n; j ++) {
        while(i >= 1 && l - v[j].first <= v[i].first)
            i --;
        while(k >= 1 && r - v[j].first <= v[k].first)
            k --;
        if(k >= 1 && v[k].first < r - v[j].first)
            ans += (k - i);
    }

    return ans;
}

int main() {
   //freopen("a.in", "r", stdin);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> v(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];

    vector<pair<int, int>> arr(n + 1, {0, 0});
    for(int i = 1; i <= n; i ++)
        arr[i].second = i;

    ll ans = 0;
    vector<vector<pair<int, int>>> sorted(2, vector<pair<int, int>> (n + 1));
    for(int bit = 0; bit <= 29; bit ++) {
        vector<int> sz(2, 0);
        for(int i = 1; i <= n; i ++)
            sorted[(v[arr[i].second] & (1 << bit)) == (1 << bit)][sz[(v[arr[i].second] & (1 << bit)) == (1 << bit)] ++] = {arr[i].first + (v[arr[i].second] & (1 << bit)), arr[i].second};

        int pos = 0;
        for(int i = 0; i < sz[0]; i ++)
            arr[++ pos] = sorted[0][i];
        for(int i = 0; i < sz[1]; i ++)
            arr[++ pos] = sorted[1][i];

        ll aux = getsol(n, arr, 1 << bit, 1 << (bit + 1)) + getsol(n, arr, (1 << (bit + 1)) + (1 << bit), (1 << (bit + 2)));
        for(int i = 1; i <= n; i ++)
            if((2 * v[i]) & (1 << bit))
                aux ++;

        aux /= 2;
        if(aux % 2 == 1)
            ans += (1 << bit);
    }

    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1042 ms 35580 KB Output is correct
2 Correct 900 ms 33148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1042 ms 35580 KB Output is correct
2 Correct 900 ms 33148 KB Output is correct
3 Correct 1307 ms 35592 KB Output is correct
4 Correct 1401 ms 34296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 103 ms 3840 KB Output is correct
4 Correct 102 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 1042 ms 35580 KB Output is correct
4 Correct 900 ms 33148 KB Output is correct
5 Correct 1307 ms 35592 KB Output is correct
6 Correct 1401 ms 34296 KB Output is correct
7 Correct 103 ms 3840 KB Output is correct
8 Correct 102 ms 3832 KB Output is correct
9 Correct 1568 ms 35544 KB Output is correct
10 Correct 1533 ms 35704 KB Output is correct
11 Correct 1480 ms 35576 KB Output is correct