답안 #954662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954662 2024-03-28T09:50:44 Z codefox Pairs (IOI07_pairs) C++14
30 / 100
2657 ms 338436 KB
#include<bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define ll long long
#define arr array<int, 2>

int N = 1<<18;
int M = 1<<17;

vector<vector<arr>> bin;
vector<int> counter;
vector<vector<int>> upd;

int go(int a, int b, int d)
{
    if (bin[a][b][d]==-1)
    {
        upd[a].push_back(upd[a][b]-1);
        bin[a].push_back({-1, -1});
        bin[a][b][d] = counter[a];
        counter[a]++;
    }
    return bin[a][b][d];
}

void update(int a, int b)
{
    a += N; 
    while (a)
    {
        int curr = 0;
        int bb = b;
        for (int i = 17; i >= 0; i--)
        {
            upd[a][curr]++;
            if (bb>=(1<<i))
            {
                bb -= 1<<i;
                curr = go(a, curr, 1);
            }
            else curr = go(a, curr, 0);
        }
        upd[a][curr]++;
        a/=2;
    }
}

ll ac2d(int a, int curr, int l, int r, int x, int y)
{
    if (r <=x || l >= y) return 0;
    if (l >= x && r <= y)
    {
        return upd[a][curr];
    }
    int m = (l+r)/2;
    ll sol = 0;
    if (bin[a][curr][0]!=-1) sol += ac2d(a, bin[a][curr][0], l, m, x, y);
    if (bin[a][curr][1]!=-1) sol += ac2d(a, bin[a][curr][1], m, r, x, y);
    return sol;
}

ll acc(int curr, int l, int r, int a, int b, int x, int y)
{
    if (r <=a || l >= b) return 0;
    if (l >= a && r <= b)
    {
        return ac2d(curr, 0, 0, N, x, y);
    }
    int m = (l+r)/2;
    return acc(curr*2, l, m, a, b, x, y)+ acc(curr*2+1, m, r, a, b, x, y);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int b, n, d, m;
    cin >> b >> n >> d >> m;

    if (b == 1)
    {
        vector<int> nums(n);
        for (int i =0; i < n; i++) cin >> nums[i];
        sort(nums.begin(), nums.end());

        ll sol = 0;
        queue<int> q;
        for (int i = 0; i < n; i++)
        {
            while (q.size() && nums[i]-q.front()> d) q.pop();
            sol += q.size();
            q.push(nums[i]);
        }
        cout << sol;
    }
    else if (b==2)
    {
        bin.assign(2*N, vector<arr>(1, {-1, -1}));
        counter.assign(2*N, 1);
        upd.assign(2*N, vector<int>(1, 0));

        ll sol = 0;

        for (int i = 0; i < n; i++)
        {
            int x, y;
            cin >> x >> y;
            sol += acc(1, 0, N, x+y-d, x+y+d, y-x+M-d, y-x+M+d);
            update(x+y, y-x+M);
        }
        cout << sol;
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 856 KB Output is correct
2 Correct 10 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 604 KB Output is correct
2 Correct 14 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 860 KB Output is correct
2 Correct 16 ms 868 KB Output is correct
3 Correct 14 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 64980 KB Output is correct
2 Incorrect 70 ms 65108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 302 ms 61600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 823 ms 97724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2657 ms 338436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -