Submission #197651

# Submission time Handle Problem Language Result Execution time Memory
197651 2020-01-22T05:36:59 Z arnold518 Pairs (IOI07_pairs) C++14
30 / 100
79 ms 11868 KB
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 1e5;

struct Point
{
	int x, y, z;
	Point() {}
	Point(int x) : x(x), y(0), z(0) {}
	Point(int x, int y) : x(x), y(y), z(0) {}
	Point(int x, int y, int z) : x(x), y(y), z(z) {}
	bool operator < (const Point &p) const { return x<p.x; }
};

struct Query
{
	int x, y1, y2, d;
	bool operator < (const Query &p) const { return x<p.x; }
};

int B, N, D, M;
Point A[MAXN+10];
ll ans;

struct BIT
{
	vector<int> tree;
	BIT() : tree(2*M+10) {}
	void update(int i) { for(; i<2*M; i+=(i&-i)) tree[i]++; }
	int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
	int query(int l, int r) { return query(r)-query(l-1); }
};

ll f(vector<Point> &V, vector<Point> &S, vector<int> &R)
{
	int i, j;

	vector<Point> V2;
	for(i=0; i<V.size(); i++) V2.push_back(Point(V[i].x+V[i].y-1, V[i].x-V[i].y+M));

	vector<Query> S2;
	for(i=0; i<S.size(); i++)
	{
		int x1=S[i].x+S[i].y-1-R[i], x2=S[i].x+S[i].y-1+R[i];
		int y1=S[i].x-S[i].y+M-R[i], y2=S[i].x-S[i].y+M+R[i];
		x1=max(x1, 1); x2=min(y2, 2*M-1);
		y1=max(y1, 1); y2=min(y2, 2*M-1);

		S2.push_back({x1-1, y1, y2, -1});
		S2.push_back({x2, y1, y2, 1});
	}
	sort(S2.begin(), S2.end());
	sort(V2.begin(), V2.end());

	BIT bit;
	ll ret=0;
	for(i=0, j=0; i<S2.size(); i++)
	{
		for(; j<V2.size() && V2[j].x<=S2[i].x; j++) bit.update(V2[j].y);
		ans+=S2[i].d*bit.query(S2[i].y1, S2[i].y2);
	}
	return ans;
}

int main()
{
	int i, j;

	scanf("%d%d%d%d", &B, &N, &D, &M);
	for(i=1; i<=N; i++)
	{
		if(B==1) scanf("%d", &A[i].x);
		if(B==2) scanf("%d%d", &A[i].x, &A[i].y);
		if(B==3) scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].z);
	}

	if(B==1)
	{
		sort(A+1, A+N+1);
		for(i=1; i<=N; i++) ans+=upper_bound(A+1, A+N+1, Point(A[i].x+D))-lower_bound(A+1, A+N+1, Point(A[i].x-D));
		ans-=N; ans/=2;
		printf("%lld", ans);
		return 0;
	}

	if(B==2)
	{
		vector<Point> V, S;
		vector<int> R;
		for(i=1; i<=N; i++) V.push_back(A[i]), S.push_back(A[i]), R.push_back(D);
		ans=f(V, S, R);
		ans-=N; ans/=2;
		printf("%lld", ans);
	}
}

Compilation message

pairs.cpp: In function 'll f(std::vector<Point>&, std::vector<Point>&, std::vector<int>&)':
pairs.cpp:44:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<V.size(); i++) V2.push_back(Point(V[i].x+V[i].y-1, V[i].x-V[i].y+M));
           ~^~~~~~~~~
pairs.cpp:47:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<S.size(); i++)
           ~^~~~~~~~~
pairs.cpp:62:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0, j=0; i<S2.size(); i++)
                ~^~~~~~~~~~
pairs.cpp:64:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(; j<V2.size() && V2[j].x<=S2[i].x; j++) bit.update(V2[j].y);
         ~^~~~~~~~~~
pairs.cpp:61:5: warning: unused variable 'ret' [-Wunused-variable]
  ll ret=0;
     ^~~
pairs.cpp: In function 'int main()':
pairs.cpp:72:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pairs.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &B, &N, &D, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:77:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(B==1) scanf("%d", &A[i].x);
            ~~~~~^~~~~~~~~~~~~~~
pairs.cpp:78:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(B==2) scanf("%d%d", &A[i].x, &A[i].y);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:79:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(B==3) scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].z);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1916 KB Output is correct
2 Correct 26 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2408 KB Output is correct
2 Correct 33 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2312 KB Output is correct
2 Correct 36 ms 2348 KB Output is correct
3 Correct 34 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 11420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 11424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2336 KB Output isn't correct
2 Halted 0 ms 0 KB -