QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526635#8775. MountainCraftlsflsf2023WA 1ms8100kbC++142.6kb2024-08-21 18:51:072024-08-21 18:51:07

Judging History

你现在查看的是最新测评结果

  • [2024-08-21 18:51:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8100kb
  • [2024-08-21 18:51:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

pair < int , int > Q[200005];

bool Opt[200005];

map < pair < int , int > , int > Map;

int LL[400005];

int Pos[400005];

int a[200005];

int B[200005];
int C[200005];
int Sum[500], RR[500], Top[500], L[500], R[500];

int main()
{
	int q, w;
	scanf("%d%d", &q, &w);
	int t = 0;
	for (int i = 1 ; i <= q ; ++ i)
	  {
	  	int x, y;
	  	scanf("%d%d", &x, &y);
	  	if (Map[make_pair(x, y)] == 0)
	  	  Opt[i] = 1, Map[make_pair(x, y)] = 1;
	  	else
	  	  Opt[i] = 0, Map[make_pair(x, y)] = 0;
	  	int l = x - y;
	  	if (l < 0)
	  	  l = 0;
	  	int r = x + y;
	  	if (r > w)
	  	  r = w;
        Q[i].first = l, Q[i].second = r;
        LL[++ t] = l, LL[++ t] = r;
	  }
	sort(LL + 1, LL + t + 1);
	int n = 0;
	map < int , int > M;
	for (int i = 1 ; i <= t ; ++ i)
	  if (!M[LL[i]])
	    M[LL[i]] = ++ n, Pos[n] = LL[i];
	for (int i = 1 ; i <= q ; ++ i)
	  Q[i].first = M[Q[i].first], Q[i].second = M[Q[i].second] - 1;
	cout << n << endl;
	for (int i = 1 ; i < n ; ++ i)
	  a[i] = Pos[i + 1] - Pos[i];
	-- n;
	int S = sqrt(n);
	for (int i = 1 ; i <= n ; ++ i)
	  B[i] = (i - 1) / S + 1, Top[B[i]] += a[i], RR[B[i]] = i;
	for (int i = n ; i ; -- i)
	  L[B[i]] = i;
	//for (int i = 1 ; i <= n ; ++ i)
	  //printf("%ds%d\n", L[i], RR[i]);
	int Ans = 0;
	for (int i = 1 ; i <= q ; ++ i)
	  {
	  	int l = Q[i].first, r = Q[i].second;
	  	cout << l << " " << r << endl;
	  	//cout << B[l] << " " << B[r] << endl;
	  	if (Opt[i] == 1)
	  	  {
	  	  	for (int j = B[l] + 1 ; j < B[r] ; ++ j)
	  	  	  {
	  	  	  	++ Sum[j];
	  	  	  	if (Sum[j] == 1)
	  	  	  	  Ans += Top[j] - R[j];
			  }
			for (int j = l ; j <= RR[B[l]] ; ++ j)
			  {
			  	++ C[j];
			  	if (C[j] == 1)
			  	  R[B[j]] += a[j];
			  	if (Sum[B[j]] == 0 && C[j] == 1)
			  	  Ans += a[j];
			  }
			for (int j = L[B[r]] ; j <= r ; ++ j)
			  {
			  	++ C[j];
			  	if (C[j] == 1)
			  	  R[B[j]] += a[j];
			  	if (Sum[B[j]] == 0 && C[j] == 1)
			  	  Ans += a[j];
			  }
		  }
		else
		  {
		  	for (int j = B[l] + 1 ; j < B[r] ; ++ j)
		  	  {
		  	  	-- Sum[j];
		  	  	if (Sum[j] == 0)
		  	  	  Ans -= Top[j] - R[j];
			  }
			for (int j = l ; j <= RR[B[l]] ; ++ j)
			  {
			  	-- C[j];
			  	if (C[j] == 0)
			  	  R[B[j]] -= a[j];
			  	if (Sum[B[j]] == 0 && C[j] == 0)
			  	  Ans -= a[j];
			  }
			for (int j = L[B[r]] ; j <= r ; ++ j)
			  {
			  	-- C[j];
			  	if (C[j] == 0)
			  	  R[B[j]] -= a[j];
			  	if (Sum[B[j]] == 0 && C[j] == 0)
			  	  Ans -= a[j];
			  }
		  }
		printf("%.10lf\n", (double)Ans * (double)sqrt((double)2));
	  }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8100kb

input:

3 10
3 2
7 3
9 6

output:

5
1 3
5.6568542495
3 4
12.7279220614
2 4
12.7279220614

result:

wrong answer 1st numbers differ - expected: '5.6568540', found: '5.0000000', error = '0.1161165'