답안 #215931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
215931 2020-03-26T12:34:54 Z wendy_virgo XOR Sum (info1cup17_xorsum) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e6+6;

int n;
int64_t a[N],pow10[10];

void Sub1(){
    int ans=0;
    for(int i=1;i<=n;++i){
        for(int j=i;j<=n;++j){
            ans^=(a[i]+a[j]);
        }
    }
    cout<<ans<<'\n';
}

int GetDigit(int64_t x,int k){
    return (x/pow10[k-1])%10;
}

void SortByDigit(vector<int64_t> &a,int k){
    vector<int> freq(10);
    for(int i=0;i<a.size();++i){
        freq[GetDigit(a[i],k)]++;
    }
    for(int i=1;i<=9;++i){
        freq[i]+=freq[i-1];
    }
    vector<int64_t> b(a.size());
    for(int i=(int)a.size()-1;i>=0;--i){
        int id=GetDigit(a[i],k);
        b[freq[id]-1]=a[i];
        freq[id]--;
    }
    a=b;
}

void RadixSort(vector<int64_t> &vec){
    for(int i=1;i<=9;++i){
        SortByDigit(vec,i);
    }
    assert(is_sorted(begin(vec),end(vec)));
}

int Check(int pos){
    int res=0;
    vector<vector<int64_t>> vec(2);
    for(int i=1;i<=n;++i){
        int64_t val=0;
        for(int j=0;j<pos;++j){
            if((a[i]>>j)&1){
                val|=1<<j;
            }
        }
        vec[(a[i]>>pos)&1].push_back(val);
    }
    RadixSort(vec[0]);
    RadixSort(vec[1]);
//    for(int i=0;i<2;++i){
//        sort(begin(vec[i]),end(vec[i]));
//    }
    int ptr=(int)vec[0].size()-1;
    for(int i=0;i<vec[0].size();++i){
        int64_t val=(1<<pos)-vec[0][i];
        while(ptr>=0&&vec[0][ptr]>=val){
            ptr--;
        }
        if(ptr+1<=i){
            res^=(i-(ptr+1)+1)%2;
        }
    }
    ptr=(int)vec[1].size()-1;
    for(int i=0;i<vec[1].size();++i){
        int64_t val=(1<<pos)-vec[1][i];
        while(ptr>=0&&vec[1][ptr]>=val){
            ptr--;
        }
        if(ptr+1<=i){
            res^=(i-(ptr+1)+1)%2;
        }
    }
    ptr=(int)vec[1].size()-1;
    for(int i=0;i<vec[0].size();++i){
        int64_t val=(1<<pos)-vec[0][i];
        while(ptr>=0&&vec[1][ptr]>=val){
            ptr--;
        }
        res^=(ptr+1)%2;
    }
    return res;
}

void Sub2(){
    int64_t ans=0;
    for(int i=0;i<=31;++i){
        if(Check(i)){
            ans+=(int64_t)1<<i;
        }
    }
    cout<<ans;
}

void Gen(){
    srand(time(0));
    freopen("info1cup17_xorsum.inp","w",stdout);
    int n=rand()%5+1;
    cout<<n<<'\n';
    for(int i=1;i<=n;++i){
        cout<<rand()%10+1<<' ';
    }
    exit(0);
}

int main()
{
//    Gen();
//    freopen("info1cup17_xorsum.inp","r",stdin);
//    freopen("info1cup17_xorsum.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i];
	}
	pow10[0]=1;
	for(int i=1;i<=9;++i){
        pow10[i]=pow10[i-1]*10;
	}
//	Sub1();
	Sub2();
    return 0;
}

Compilation message

xorsum.cpp:25:22: error: 'int64_t pow10 [10]' redeclared as different kind of symbol
 int64_t a[N],pow10[10];
                      ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from xorsum.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:122:1: note: previous declaration 'double pow10(double)'
 __MATHCALL (pow10,, (_Mdouble_ __x));
 ^
xorsum.cpp: In function 'int GetDigit(int64_t, int)':
xorsum.cpp:38:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
     return (x/pow10[k-1])%10;
                        ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
xorsum.cpp:38:14: error: invalid operands of types 'int64_t {aka long int}' and 'double(double) throw ()' to binary 'operator/'
     return (x/pow10[k-1])%10;
             ~^~~~~~~~~~~
xorsum.cpp: In function 'void SortByDigit(std::vector<long int>&, int)':
xorsum.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();++i){
                 ~^~~~~~~~~
xorsum.cpp: In function 'int Check(int)':
xorsum.cpp:83:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[0].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp:93:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[1].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp:103:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[0].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:145:9: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  pow10[0]=1;
         ^
xorsum.cpp:145:11: error: assignment of function 'double pow10(double)'
  pow10[0]=1;
           ^
xorsum.cpp:145:11: error: cannot convert 'int' to 'double(double) throw ()' in assignment
xorsum.cpp:147:16: warning: pointer to a function used in arithmetic [-Wpointer-arith]
         pow10[i]=pow10[i-1]*10;
                ^
xorsum.cpp:147:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
         pow10[i]=pow10[i-1]*10;
                           ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
xorsum.cpp:147:28: error: invalid operands of types 'double(double) throw ()' and 'int' to binary 'operator*'
         pow10[i]=pow10[i-1]*10;
                  ~~~~~~~~~~^~~
xorsum.cpp: In function 'void Gen()':
xorsum.cpp:125:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("info1cup17_xorsum.inp","w",stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~