Submission #509478

# Submission time Handle Problem Language Result Execution time Memory
509478 2022-01-14T06:04:31 Z blue Pairs (IOI07_pairs) C++17
60 / 100
112 ms 11120 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;






















void solve_1()
{
    int N, D, M;
    cin >> N >> D >> M;

    int X[N];
    for(int i = 0; i < N; i++) cin >> X[i];

    ll ans = 0;
    sort(X, X+N);

    int l = 0;
    for(int r = 0; r < N; r++)
    {
        while(X[r] - X[l] > D) l++;
        ans += r-l;
    }

    cout << ans << '\n';
}







struct info2
{
    int xpy;
    int xmy;
    ll mul;
};

bool operator < (info2 A, info2 B)
{
    if(A.xpy == B.xpy) return (A.mul == 0);
    return A.xpy < B.xpy;
}



void solve_2()
{
    int N, D, M;
    cin >> N >> D >> M;

    int X[1+N], Y[1+N];
    for(int i = 1; i <= N; i++) cin >> X[i] >> Y[i];

    ll ans = 0;

    vector<info2> I;
    for(int i = 1; i <= N; i++)
    {
        I.push_back({X[i] + Y[i], X[i] - Y[i] + M, 0});

        I.push_back({X[i] + Y[i] - D - 1, X[i] - Y[i] + D + M, -1});
        I.push_back({X[i] + Y[i] - D - 1, X[i] - Y[i] - D - 1 + M, +1});

        I.push_back({X[i] + Y[i] + D, X[i] - Y[i] + D + M, +1});
        I.push_back({X[i] + Y[i] + D, X[i] - Y[i] - D - 1 + M, -1});
    }

    sort(I.begin(), I.end());

    vll BIT(1 + 2*M, 0);

    for(info2 i: I)
    {
        if(i.mul == 0)
        {
            for(int j = i.xmy; j <= 2*M; j += j&-j)
                BIT[j]++;
        }
        else
        {
            // if(i.xmy < 1) continue;

            for(int j = min(i.xmy, 2*M); j >= 1; j -= j&-j)
                ans += BIT[j] * i.mul;
        }
    }

    ans -= N;
    ans >>= 1;

    cout << ans << '\n';
}
















void solve_3()
{
    ;
}


















int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int B;
    cin >> B;
    if(B == 1) solve_1();
    else if(B == 2) solve_2();
    else solve_3();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 696 KB Output is correct
2 Correct 11 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 700 KB Output is correct
2 Correct 21 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 700 KB Output is correct
2 Correct 17 ms 700 KB Output is correct
3 Correct 21 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 9428 KB Output is correct
2 Correct 112 ms 9396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 9396 KB Output is correct
2 Correct 79 ms 10140 KB Output is correct
3 Correct 80 ms 10140 KB Output is correct
4 Correct 87 ms 10160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 9940 KB Output is correct
2 Correct 94 ms 11120 KB Output is correct
3 Correct 93 ms 11024 KB Output is correct
4 Correct 87 ms 11052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -