답안 #473579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473579 2021-09-15T16:50:22 Z Yazan_Alattar XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 28916 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 1000007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);

ll n, a[M], ans;

int main()
{
//    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    scanf("%lld", &n);
    for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    for(int j = 0; j < 32; ++j){
        vector <ll> v;
        for(int i = 1; i <= n; ++i) v.pb(a[i] & ((1ll << (j + 1)) - 1));
        sort(v.begin(), v.end());
        bool add = 0;
        for(int i = 0; i < v.size(); ++i){
            int l = lower_bound(v.begin() + i, v.end(), (1 << j) - v[i]) - v.begin();
            int r = lower_bound(v.begin() + i, v.end(), (1 << (j + 1)) - v[i]) - v.begin();
            add ^= (r - l) % 2;
            add ^= (n - (lower_bound(v.begin() + i, v.end(), (1 << j) + (1 << (j + 1)) - v[i]) - v.begin())) % 2;
        }
        if(add) ans |= (1 << j);
    }
    printf("%lld", ans);
    return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0; i < v.size(); ++i){
      |                        ~~^~~~~~~~~~
xorsum.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
xorsum.cpp:30:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 332 KB Output is correct
2 Correct 16 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1673 ms 28916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1673 ms 28916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 332 KB Output is correct
2 Correct 16 ms 428 KB Output is correct
3 Correct 515 ms 3820 KB Output is correct
4 Correct 535 ms 3856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 332 KB Output is correct
2 Correct 16 ms 428 KB Output is correct
3 Execution timed out 1673 ms 28916 KB Time limit exceeded
4 Halted 0 ms 0 KB -