Submission #954655

# Submission time Handle Problem Language Result Execution time Memory
954655 2024-03-28T09:46:25 Z codefox Pairs (IOI07_pairs) C++14
0 / 100
62 ms 59996 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+1, x-y+M-d, x-y+M+d);
            update(x+y, x-y+M);
        }
        cout << sol;
    }

    return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:78:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 59984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 59988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 59748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 59984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 59928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 59972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 59968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 59984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 59804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 59984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 59996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 59784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 59868 KB Output isn't correct
2 Halted 0 ms 0 KB -