Submission #766210

# Submission time Handle Problem Language Result Execution time Memory
766210 2023-06-25T11:31:04 Z Ahmed57 XOR Sum (info1cup17_xorsum) C++17
77 / 100
1600 ms 12332 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    long long all = 0;
    reverse(arr,arr+n);
    for(int i = 0;i<30;i++){
        vector<int> v;
        long long ans = 0;
        for(int j = 0;j<n;j++){
            if((arr[j]+arr[j])&(1LL<<i)){
                ans++;
            }
            v.push_back(arr[j]&((1LL<<(i+1))-1));
        }
        sort(v.begin(),v.end());
        int il = 0 , ir = 0;
        int ll = 0;
        for(int j = v.size()-1;j>=0;j--){
            long long l=(1LL<<i),r=(1LL<<(i+1));
            l-=v[j] , r-=v[j];
            if(l<0){
            l%=((1LL<<(i+1)));
            l+=(1LL<<(i+1));
            l&=((1LL<<(i+1))-1);
            }
            while(ir<v.size()&&v[ir]<r)ir++;
            if(l>=ll){
                while(il<v.size()&&v[il]<l)il++;
            }else{
                il = 0;
                while(il<v.size()&&v[il]<l)il++;
            }
            //cout<<l<<" "<<r<<" "<<il<<" "<<ir<<" "<<v[il]<<" "<<v[ir]<<endl;
            ll = l;
            if(l<=r)ans+=(ir-il);
            else ans+=ir+(n-il);
        }
        //cout<<endl;
        if(((ans/2)&1))all+=(1LL<<i);
    }
    cout<<all<<endl;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             while(ir<v.size()&&v[ir]<r)ir++;
      |                   ~~^~~~~~~~~
xorsum.cpp:39:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 while(il<v.size()&&v[il]<l)il++;
      |                       ~~^~~~~~~~~
xorsum.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                 while(il<v.size()&&v[il]<l)il++;
      |                       ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 650 ms 12332 KB Output is correct
2 Correct 591 ms 12056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 650 ms 12332 KB Output is correct
2 Correct 591 ms 12056 KB Output is correct
3 Correct 1022 ms 12248 KB Output is correct
4 Correct 965 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 163 ms 1616 KB Output is correct
4 Correct 163 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 650 ms 12332 KB Output is correct
4 Correct 591 ms 12056 KB Output is correct
5 Correct 1022 ms 12248 KB Output is correct
6 Correct 965 ms 12116 KB Output is correct
7 Correct 163 ms 1616 KB Output is correct
8 Correct 163 ms 1612 KB Output is correct
9 Execution timed out 1630 ms 12296 KB Time limit exceeded
10 Halted 0 ms 0 KB -