답안 #453270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
453270 2021-08-04T10:21:18 Z prvocislo Pairs (IOI07_pairs) C++17
100 / 100
585 ms 21904 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
using namespace std;
 
const int maxn = 1.5e5 + 5;
vector<int> st[maxn * 2];
void upd(int x, int y)
{
    for (x += maxn; x > 0; x >>= 1) st[x].push_back(y);
}
int query1d(int y1, int y2, int vr) { return upper_bound(st[vr].begin(), st[vr].end(), y2) - lower_bound(st[vr].begin(), st[vr].end(), y1); }
int query(int x1, int y1, int x2, int y2)
{
    x1 = max(x1, 0), x2 = min(x2, maxn - 1);
    int ans = 0;
    for (x1 += maxn, x2 += maxn + 1; x1 < x2; x1 >>= 1, x2 >>= 1)
    {
        if (x1 & 1) ans += query1d(y1, y2, x1++);
        if (x2 & 1) ans += query1d(y1, y2, --x2);
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int b, n, d, m;
    cin >> b >> n >> d >> m;
    vector<int> x(n), y(n), z(n);
    if (b == 3)
    {
        const int maxn = 80;
        vector<vector<vector<int> > > pf(maxn, vector<vector<int> >(maxn * 2, vector<int>(maxn * 2, 0)));
        for (int i = 0, x1, y1; i < n; i++)
        {
            cin >> x1 >> y1 >> z[i];
            x[i] = x1 + y1, y[i] = maxn + x1 - y1;
            pf[z[i]][x[i]][y[i]]++;
        }
        for (int i = 0; i < pf.size(); i++) for (int j = 1; j < pf[i].size(); j++) for (int k = 1; k < pf[i][j].size(); k++)
            pf[i][j][k] += pf[i][j - 1][k] + pf[i][j][k - 1] - pf[i][j - 1][k - 1];
        ll ans = 0;
        for (int i = 0; i < n; i++) for (int zi = 0; zi < maxn; zi++)
        {
            int di = d - abs(zi - z[i]);
            if (di < 0) continue;
            int x1 = max(1, x[i] - di), y1 = max(1, y[i] - di), x2 = min(maxn * 2 - 1, x[i] + di), y2 = min(maxn * 2 - 1, y[i] + di);
            ans += pf[zi][x2][y2] - pf[zi][x1 - 1][y2] - pf[zi][x2][y1 - 1] + pf[zi][x1 - 1][y1 - 1];
            //cout << pf[zi][x2][y2] - pf[zi][x1 - 1][y2] - pf[zi][x2][y1 - 1] + pf[zi][x1 - 1][y1 - 1] << "\n";
        }
        ans -= n;
        cout << ans / 2 << "\n";
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        if (b == 1) cin >> y[i];
        else
        {
            int x1, y1; cin >> x1 >> y1;
            x[i] = x1 + y1, y[i] = x1 - y1;
        }
        upd(x[i], y[i]);
    }
    for (int i = 0; i < maxn * 2; i++) sort(st[i].begin(), st[i].end());
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += query(x[i] - d, y[i] - d, x[i] + d, y[i] + d);
    }
    cout << (ans - n) / 2 << "\n";
    return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int i = 0; i < pf.size(); i++) for (int j = 1; j < pf[i].size(); j++) for (int k = 1; k < pf[i][j].size(); k++)
      |                         ~~^~~~~~~~~~~
pairs.cpp:43:63: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int i = 0; i < pf.size(); i++) for (int j = 1; j < pf[i].size(); j++) for (int k = 1; k < pf[i][j].size(); k++)
      |                                                             ~~^~~~~~~~~~~~~~
pairs.cpp:43:102: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int i = 0; i < pf.size(); i++) for (int j = 1; j < pf[i].size(); j++) for (int k = 1; k < pf[i][j].size(); k++)
      |                                                                                                    ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 6 ms 7336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 16084 KB Output is correct
2 Correct 155 ms 16128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 16256 KB Output is correct
2 Correct 180 ms 16340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 16292 KB Output is correct
2 Correct 216 ms 15760 KB Output is correct
3 Correct 193 ms 15748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7628 KB Output is correct
2 Correct 11 ms 7592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 17036 KB Output is correct
2 Correct 146 ms 17092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 17848 KB Output is correct
2 Correct 273 ms 17896 KB Output is correct
3 Correct 294 ms 17948 KB Output is correct
4 Correct 310 ms 17872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 585 ms 21904 KB Output is correct
2 Correct 480 ms 21364 KB Output is correct
3 Correct 246 ms 18188 KB Output is correct
4 Correct 292 ms 18012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 15948 KB Output is correct
2 Correct 18 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 17100 KB Output is correct
2 Correct 64 ms 17100 KB Output is correct
3 Correct 84 ms 17164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 17156 KB Output is correct
2 Correct 410 ms 17168 KB Output is correct
3 Correct 149 ms 17152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 17156 KB Output is correct
2 Correct 576 ms 17156 KB Output is correct
3 Correct 172 ms 17220 KB Output is correct