QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547375#858. GCD vs. XORRafat_KabirWA 1971ms180480kbC++204.1kb2024-09-04 21:08:382024-09-04 21:08:38

Judging History

你现在查看的是最新测评结果

  • [2024-09-04 21:08:38]
  • 评测
  • 测评结果:WA
  • 用时:1971ms
  • 内存:180480kb
  • [2024-09-04 21:08:38]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
#define MAXN 1000001

void solve(int it)
{
    // freopen("test.txt", "w", stdout);
    // vector<set<int>> A(MAXN);
    vv32 A(MAXN);
    vv32 same(MAXN);
    FOR(1, MAXN-1, i){
        ll x = i;
        while(x <= MAXN-1){
            A[i].pb(x);
            x += i;
        }
    }
    // cout << "done\n";
    // ll sum = 0;
    // FOR(1, MAXN-1, i){
    //     // cout << i << "->";
    //     // coutAll(A[i]);
    //     sum += A[i].size();
    // }
    // cout << sum;
    FOR(1, MAXN-1, i){
        for(auto x : A[i]){
            if((x <= (x^i)) && __gcd(x, (x^i)) == i){
                same[x].pb(x^i);
            }
        }
        // cout << i << "\n";
    }
    // cout << "done\n";
    FOR(1, MAXN-1, i){
        sort(all(same[i]));
        same[i].erase(unique(all(same[i])),  same[i].end());
    }
    // coutAll(same[100]);
    // ll sum =0;
    // FOR(1, MAXN-1, i) sum = max(sum, (ll)same[i].size());
    // cout << sum;
    int t;
    cin >> t;
    v32 cnt(MAXN);
    while(t--){
        int n; cin >> n;
        v32 arr(n);
        FOR(0, n -1 , i){
            int x; cin >> x;
            arr[i] = x;
            cnt[x]++;
        }
        ll ans = 0;
        FOR(1, MAXN-1, i){
            for(auto x : same[i]){
                ans += 1LL*cnt[x]*cnt[i];
            }
        }
        cout << ans << "\n";
        for(auto x : arr) cnt[x]--;
    }



}


int main()
{
    fast_cin();    
    ll t = 1;
    // cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 323ms
memory: 166020kb

input:

1
4
2 3 4 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 447ms
memory: 166176kb

input:

20
43
128 66 452 384 400 441 232 203 228 33 284 156 128 190 197 292 388 31 179 343 147 206 450 284 180 73 273 130 168 250 405 203 235 340 309 28 267 395 152 191 295 463 344
54
48 7 12 37 49 24 5 18 15 37 26 57 53 59 22 10 2 16 36 52 64 1 56 42 38 46 53 7 2 8 60 38 54 11 19 50 20 61 6 50 27 5 26 3 4 ...

output:

9
54
13
7
8
34
47
11
1
102
6
5
37
1
3
8
8
348
15
0

result:

ok 20 numbers

Test #3:

score: -100
Wrong Answer
time: 1971ms
memory: 180480kb

input:

20
1318434
383714 853663 66866 511925 858736 184314 296349 849141 468962 414270 917939 220934 778184 984811 194692 105206 528188 310859 57152 790101 274637 529663 931099 79533 179471 539390 210762 400829 514992 127623 369248 168711 380204 767781 753089 645551 714964 101060 340524 937457 928656 65201...

output:

117581018
124768997
111535890
104007447
146529260
130138457
95540251
97998302
89345045
145484350
123078895
105931664
95038257
98905338
117006667
145887110
136580967
103265343
179238048
999999972775

result:

wrong answer 1st numbers differ - expected: '3032046', found: '117581018'