Submission #279688

# Submission time Handle Problem Language Result Execution time Memory
279688 2020-08-22T09:53:11 Z patrikpavic2 Pairs (IOI07_pairs) C++17
30 / 100
60 ms 2540 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;

const int N = 3e5 + 500;
const int OFF = 1e5 + 500;
const int M = 80;

int loga[N], B, n, m, D;

inline int trans(int x){
	return max(min(x + OFF, N - 1), 0);
}

void add(int x, int y){
	x = trans(x);
	for(; x < N ; x += x & -x)
		loga[x] += y;
}

int query(int x){
	int ret = 0;
	x = trans(x);
	for(; x ; x -= x & -x)
		ret += loga[x];
	return ret;
}

vector < pii > v;

int main(){
	scanf("%d%d%d%d", &B, &n, &D, &m);
	if(B == 2){
		for(int i = 0;i < n;i++){
			int x, y; scanf("%d%d", &x, &y);
			v.PB({x + y, x - y});
		}
		sort(v.begin(), v.end());
		int l = 0, r = 0;
		ll sol = 0;
		for(int i = 0;i < n;i++){
			while(v[i].X - v[l].X > D)
				add(v[l++].Y, -1);
			while(r < n && v[r].X - v[i].X <= D)
				add(v[r++].Y, 1);
			sol += query(v[i].Y + D) - query(v[i].Y - D - 1);
		}
		printf("%lld\n", (sol - n) / 2);
	}
	return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d%d%d%d", &B, &n, &D, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:45:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |    int x, y; scanf("%d%d", &x, &y);
      |              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 896 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2040 KB Output is correct
2 Correct 39 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2168 KB Output is correct
2 Correct 45 ms 2168 KB Output is correct
3 Correct 45 ms 2168 KB Output is correct
4 Correct 45 ms 2032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 2536 KB Output is correct
2 Correct 50 ms 2540 KB Output is correct
3 Correct 49 ms 2540 KB Output is correct
4 Correct 52 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -