Submission #581066

# Submission time Handle Problem Language Result Execution time Memory
581066 2022-06-22T08:56:14 Z messiuuuuu Pairs (IOI07_pairs) C++14
30 / 100
1223 ms 524288 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;

int n, d, m;
pair<int, int> point[MAXN];

void Input()
{
    cin >> n >> n >> d >> m;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        point[i] = {x - y + m, x + y};
    }
}

struct BIT2D
{
    vector<vector<int>> fe, node;
    int sz;

    void Init(int _sz)
    {
        sz = _sz;
        fe.resize(sz + 5);
        node.resize(sz + 5);
    }

    void fakeAdd(int x, int y)
    {
        for (; x <= sz; x += x & -x)
            node[x].pb(y);
    }

    void fakeGet(int x, int y)
    {
        for (; x; x -= x & -x)
            node[x].pb(y);
    }

    void Build()
    {
        for (int i = 1; i <= sz; i++)
        {
            sort(node[i].begin(), node[i].end());
            fe[i].resize((int)node[i].size() + 5);
        }
    }

    void add(int x, int y, int val)
    {
        for (; x <= sz; x += x & -x)
        {
            for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j <= node[x].size(); j += j & -j)
            {
                fe[x][j] += val;
            }
        }
    }

    int get(int x, int y)
    {
        int res = 0;
        for (; x; x -= x & -x)
        {
            for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j; j -= j & -j)
            {
                res += fe[x][j];
            }
        }
        return res;
    }
};

void Solve()
{
    m *= 2;
    m++;
    BIT2D bit;
    bit.Init(m);
    for (int i = 1; i <= n; i++)
    {
        bit.fakeAdd(point[i].fi, point[i].se);
        bit.fakeGet(min(m, point[i].fi + d), min(m, point[i].se + d));
        bit.fakeGet(max(0, point[i].fi - d - 1), min(m, point[i].se + d));
        bit.fakeGet(min(m, point[i].fi + d), max(0, point[i].se - d - 1));
        bit.fakeGet(max(0, point[i].fi - d - 1), max(0, point[i].se - d - 1));
    }
    bit.Build();

    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += bit.get(min(m, point[i].fi + d), min(m, point[i].se + d));
        ans -= bit.get(max(0, point[i].fi - d - 1), min(m, point[i].se + d));
        ans -= bit.get(min(m, point[i].fi + d), max(0, point[i].se - d - 1));
        ans += bit.get(max(0, point[i].fi - d - 1), max(0, point[i].se - d - 1));
        bit.add(point[i].fi, point[i].se, 1);
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

pairs.cpp: In member function 'void BIT2D::add(int, int, int)':
pairs.cpp:63:98: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j <= node[x].size(); j += j & -j)
      |                                                                                                ~~^~~~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 255 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 375 ms 25200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 209 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 222 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12628 KB Output is correct
2 Correct 19 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 524 ms 17816 KB Output is correct
2 Correct 163 ms 12036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 797 ms 24872 KB Output is correct
2 Correct 632 ms 23664 KB Output is correct
3 Correct 756 ms 25764 KB Output is correct
4 Correct 611 ms 24168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1223 ms 52936 KB Output is correct
2 Correct 1050 ms 49704 KB Output is correct
3 Correct 1031 ms 44916 KB Output is correct
4 Correct 1163 ms 47064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 173 ms 10792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 441 ms 15632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 467 ms 16824 KB Output isn't correct
2 Halted 0 ms 0 KB -