/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 23ms 540.0 KiB
#5 Accepted 19ms 540.0 KiB
#6 Accepted 55ms 584.0 KiB
#7 Accepted 108ms 596.0 KiB
#8 Accepted 257ms 588.0 KiB
#9 Time Exceeded ≥2100ms ≥796.0 KiB
#10 Time Exceeded ≥2100ms ≥1.02 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
const int B = 30;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n + 1);
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        vector<map<int, int>> cnt(B + 1);
        int ans = 0;
        for (int j = 1; j <= n; j++)
        {
            int aj = a[j];
            for (int k = 0; k < B; k++)
            {
                int pfx = (aj >> (k + 1)) ^ (j >> (k + 1));
                int bit = ((aj >> k) & 1) ^ ((j >> k) & 1) ^ 1;
                int key = (pfx << 1) | bit;
                auto mp = cnt[k];
                auto it = mp.find(key);
                if (it != mp.end())
                    ans += it->second;
            }
            for (int k = 0; k < B; k++)
            {
                if (((aj >> k) & 1) == ((j >> k) & 1))
                {
                    int pfx = aj >> (k + 1);
                    int key = (pfx << 1) | ((j >> k) & 1);
                    cnt[k][key]++;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1198 E. Good Signal Pairs
Contest
Brain Booster #10
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 17:03:43
Judged At
2025-06-13 17:03:43
Judged By
Score
8
Total Time
≥2100ms
Peak Memory
≥1.02 MiB