Submission #581066

#TimeUsernameProblemLanguageResultExecution timeMemory
581066messiuuuuuPairs (IOI07_pairs)C++14
30 / 100
1223 ms524288 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...