Submission #1095407

# Submission time Handle Problem Language Result Execution time Memory
1095407 2024-10-02T04:18:32 Z rahidilbayramli XOR Sum (info1cup17_xorsum) C++17
18 / 100
1600 ms 65608 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//random_device rd;
//mt19937 gen(rd());
//uniform_int_distribution<> d(0, 1e9);
void solve()
{
    ll n, i, j;
    cin >> n;
    ll a[n+5];
    for(i = 1; i <= n; i++)
        cin >> a[i];
    if(n <= 4000)
    {
        ll xorr = 0;
        for(i = 1; i <= n; i++)
        {
            for(j = i; j <= n; j++)
                xorr ^= (a[i] + a[j]);
        }
        cout << xorr << "\n";
    }
    else
    {
        map<ll, ll>mp;
        for(i = 1; i <= n; i++)
            mp[a[i]]++;
        vector<pll>vect;
        for(auto u : mp)
            vect.pb(u);
        ll xorr = 0;
        for(i = 0; i < vect.size(); i++)
        {
            ll cnt = (vect[i].s * (vect[i].s + 1)) / 2;
            if(cnt % 2 == 1)
                xorr ^= (vect[i].f * 2);
            for(j = i + 1; j < vect.size(); j++)
            {
                ll f = (vect[i].f + vect[j].f);
                ll cnt = (vect[i].s * vect[j].s);
                if(cnt % 2)
                    xorr ^= f;
            }
        }
        cout << xorr << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}

Compilation message

xorsum.cpp: In function 'void solve()':
xorsum.cpp:50:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(i = 0; i < vect.size(); i++)
      |                    ~~^~~~~~~~~~~~~
xorsum.cpp:55:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(j = i + 1; j < vect.size(); j++)
      |                            ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 13256 KB Output is correct
2 Correct 117 ms 12324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 13256 KB Output is correct
2 Correct 117 ms 12324 KB Output is correct
3 Execution timed out 1628 ms 65608 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Execution timed out 1657 ms 10448 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 130 ms 13256 KB Output is correct
4 Correct 117 ms 12324 KB Output is correct
5 Execution timed out 1628 ms 65608 KB Time limit exceeded
6 Halted 0 ms 0 KB -