Submission #509475

# Submission time Handle Problem Language Result Execution time Memory
509475 2022-01-14T06:02:21 Z blue Pairs (IOI07_pairs) C++17
30 / 100
109 ms 11084 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 = i.xmy; 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 11 ms 588 KB Output is correct
2 Correct 10 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 588 KB Output is correct
2 Correct 15 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 588 KB Output is correct
2 Correct 22 ms 696 KB Output is correct
3 Correct 21 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Runtime error 4 ms 3244 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 109 ms 9960 KB Output is correct
2 Incorrect 93 ms 10020 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 10120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 11084 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 -
# 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 208 KB Output isn't correct
2 Halted 0 ms 0 KB -