Submission #54617

# Submission time Handle Problem Language Result Execution time Memory
54617 2018-07-04T08:14:10 Z 김세빈(#1491) Pairs (IOI07_pairs) C++11
60 / 100
117 ms 7036 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll X[101010], Y[101010], K[101010];
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);
}

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()
{
}

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

pairs.cpp: In function 'void update(ll*, ll, ll, ll, ll, ll)':
pairs.cpp:22:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  if(v <= s+e>>1) update(tree, p<<1, s, (s+e>>1), v, c);
          ~^~
pairs.cpp:22:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  if(v <= s+e>>1) update(tree, p<<1, s, (s+e>>1), v, c);
                                         ~^~
pairs.cpp:23: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:31: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:31: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:39: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:57: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 'int main()':
pairs.cpp:84: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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1244 KB Output is correct
2 Correct 20 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1372 KB Output is correct
2 Correct 28 ms 1444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1444 KB Output is correct
2 Correct 27 ms 1444 KB Output is correct
3 Correct 27 ms 1444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3300 KB Output is correct
2 Correct 7 ms 3300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 3300 KB Output is correct
2 Correct 45 ms 3300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 3300 KB Output is correct
2 Correct 97 ms 3300 KB Output is correct
3 Correct 75 ms 3300 KB Output is correct
4 Correct 72 ms 3300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 7036 KB Output is correct
2 Correct 111 ms 7036 KB Output is correct
3 Correct 84 ms 7036 KB Output is correct
4 Correct 85 ms 7036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7036 KB Output isn't correct
2 Halted 0 ms 0 KB -