답안 #581041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581041 2022-06-22T08:44:20 Z messiuuuuu Pairs (IOI07_pairs) C++17
0 / 100
392 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(point[i].fi + d, point[i].se + d);
        bit.fakeGet(point[i].fi - d - 1, point[i].se + d);
        bit.fakeGet(point[i].fi + d, point[i].se - d - 1);
        bit.fakeGet(point[i].fi - d - 1, point[i].se - d - 1);
    }
    bit.Build();

    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += bit.get(point[i].fi + d, point[i].se + d);
        ans -= bit.get(point[i].fi - d - 1, point[i].se + d);
        ans -= bit.get(point[i].fi + d, point[i].se - d - 1);
        ans += bit.get(point[i].fi - d - 1, 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 236 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 392 ms 25672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 223 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 235 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12628 KB Output is correct
2 Runtime error 11 ms 14816 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 2780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2988 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 16464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 2752 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2956 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -