Submission #72997

#TimeUsernameProblemLanguageResultExecution timeMemory
72997sebinkimPairs (IOI07_pairs)C++14
60 / 100
756 ms43800 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll X[101010], Y[101010], Z[101010], K[101010]; ll D[111][222][222]; ll T[606060]; ll n, d, m; ll ans; bool comp_XY(ll ca, ll cb) { if(X[ca] == X[cb]) return Y[ca] < Y[cb]; else return X[ca] < X[cb]; } void update(ll* tree, ll p, ll s, ll e, ll v, ll c) { tree[p] += c; if(s == e) return; if(v <= s+e>>1) update(tree, p<<1, s, (s+e>>1), v, c); else update(tree, p<<1|1, (s+e>>1)+1, e, v, c); } ll get_sum(ll* tree, ll p, ll s, ll e, ll l, ll r) { if(r < s || e < l) return 0; else if(l <= s && e <= r) return tree[p]; return get_sum(tree, p<<1, s, (s+e>>1), l, r) + get_sum(tree, p<<1|1, (s+e>>1)+1, e, l, r); } ll square_sum(ll p, ll a, ll b, ll c, ll d) { a = max(1ll, a); b = max(1ll, b); c = min(m+m, c); d = min(m+m, d); return D[p][c][d] - D[p][a-1][d] - D[p][c][b-1] + D[p][a-1][b-1]; } void tc1() { ll i, j; for(i=0;i<n;i++){ scanf("%lld", X+i); } sort(X, X+n); for(i=j=0;i<n;i++){ for(;j<n && X[j] - X[i] <= d;j++); ans += j - i - 1; } printf("%lld\n", ans); } void tc2() { ll i, j, x, y; for(i=0;i<n;i++){ scanf("%lld%lld", &x, &y); X[i] = x + y; // 2 ~ 2m Y[i] = x - y + m; // 1 ~ 2m-1 K[i] = i; } sort(K, K+n, comp_XY); for(i=j=0;i<n;i++){ for(;j<n && X[K[j]] - X[K[i]] <= d; j++){ update(T, 1, 1, m+m, Y[K[j]], 1); } update(T, 1, 1, m+m, Y[K[i]], -1); ans += get_sum(T, 1, 1, m+m, Y[K[i]] - d, Y[K[i]] + d); } printf("%lld\n", ans); } void tc3() { ll i, j, x, y, z, l; d = min(m+m, d); for(i=0;i<n;i++){ scanf("%lld%lld%lld", &x, &y, &z); X[i] = x; Y[i] = y + z; Z[i] = y - z + m; D[X[i]][Y[i]][Z[i]] ++; } for(i=1;i<=m;i++){ for(j=1;j<=m+m;j++){ for(l=1;l<=m+m;l++){ D[i][j][l] += D[i][j-1][l] + D[i][j][l-1] - D[i][j-1][l-1]; } } } for(i=0;i<n;i++){ ll s = 0; for(j=-d;j<=d;j++){ if(X[i] + j < 1 || X[i] + j > m) continue; l = d - (j > 0? j : -j); s += square_sum(X[i] + j, Y[i] - l, Z[i] - l, Y[i] + l, Z[i] + l); } ans += s; } ans = (ans - n) / 2; printf("%lld\n", ans); } int main() { ll dim; scanf("%lld%lld%lld%lld", &dim, &n, &d, &m); if(dim == 1) tc1(); else if(dim == 2) tc2(); else tc3(); return 0; }

Compilation message (stderr)

pairs.cpp: In function 'void update(ll*, ll, ll, ll, ll, ll)':
pairs.cpp:23:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  if(v <= s+e>>1) update(tree, p<<1, s, (s+e>>1), v, c);
          ~^~
pairs.cpp:23:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  if(v <= s+e>>1) update(tree, p<<1, s, (s+e>>1), v, c);
                                         ~^~
pairs.cpp:24:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  else update(tree, p<<1|1, (s+e>>1)+1, e, v, c);
                             ~^~
pairs.cpp: In function 'll get_sum(ll*, ll, ll, ll, ll, ll)':
pairs.cpp:32:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  return get_sum(tree, p<<1, s, (s+e>>1), l, r) + get_sum(tree, p<<1|1, (s+e>>1)+1, e, l, r);
                                 ~^~
pairs.cpp:32:74: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  return get_sum(tree, p<<1, s, (s+e>>1), l, r) + get_sum(tree, p<<1|1, (s+e>>1)+1, e, l, r);
                                                                         ~^~
pairs.cpp: In function 'void tc1()':
pairs.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", X+i);
   ~~~~~^~~~~~~~~~~~~
pairs.cpp: In function 'void tc2()':
pairs.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void tc3()':
pairs.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x, &y, &z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:126:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld%lld", &dim, &n, &d, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...