답안 #411723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411723 2021-05-25T19:09:46 Z Jasiekstrz Pairs (IOI07_pairs) C++17
60 / 100
276 ms 15796 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
namespace d1
{
	int tab[N+10];
	long long solve()
	{
		int n,d,m;
		cin>>n>>d>>m;
		for(int i=1;i<=n;i++)
			cin>>tab[i];
		sort(tab+1,tab+n+1);
		long long ans=0;
		for(int i=1,j=1;i<=n;i++)
		{
			while(tab[i]-tab[j]>d)
				j++;
			ans+=i-j;
		}
		return ans;
	}
};
namespace d2
{
	const int P=27e4;
	struct Event
	{
		int x,y;
		int val;
		bool operator<(const Event &oth)
		{
			return x<oth.x;
		}
	};
	pair<int,int> tab[N+10];
	vector<Event> ev;
	int pot;
	int tree[2*P+10];
	void add(int x,int c)
	{
		for(x+=pot-1;x>0;x/=2)
			tree[x]+=c;
		return;
	}
	long long read(int l,int r)
	{
		l=max(1,l);r=min(pot,r);
		long long ans=0;
		for(l+=pot-1,r+=pot-1;l<=r;l/=2,r/=2)
		{
			if(l%2==1)
				ans+=tree[l++];
			if(r%2==0)
				ans+=tree[r--];
		}
		return ans;
	}
	long long solve()
	{
		int n,d,m;
		cin>>n>>d>>m;
		for(int i=1;i<=n;i++)
		{
			cin>>tab[i].fi>>tab[i].se;
			ev.push_back({tab[i].fi-tab[i].se,tab[i].fi+tab[i].se,1});
			ev.push_back({tab[i].fi-tab[i].se+d+1,tab[i].fi+tab[i].se,-1});
		}
		sort(ev.begin(),ev.end());
		for(pot=1;pot<2*m;pot++);
		long long ans=0;
		for(int i=-m,j=0;i<=m;i++)
		{
			size_t it;
			for(it=j;it<ev.size() && ev[it].x==i;it++)
			{
				if(ev[it].val==-1)
					add(ev[it].y,ev[it].val);
			}
			for(it=j;it<ev.size() && ev[it].x==i;it++)
			{
				if(ev[it].val==1)
				{
					ans+=read(ev[it].y-d,ev[it].y+d);
					add(ev[it].y,ev[it].val);
					//cerr<<ev[it].x<<" "<<ev[it].y<<" ["<<ans<<"]\n";
				}
			}
			j=it;
		}
		return ans;
	}
};
namespace d3
{
	const int M=75;
	int pref[M+10][2*M+10][2*M+10];
	int tab[M+10][2*M+10][2*M+10];
	vector<tuple<int,int,int>> t;
	int read(int a,int b,int c)
	{
		if(a<0 || b<0 || c<0)
			return 0;
		a=min(a,M);
		b=min(b,2*M);
		c=min(c,2*M);
		return pref[a][b][c];
	}
	long long read_d(int a,int b,int c,int d)
	{
		d++;
		return read(a,b,c)-read(a,b-d,c)-read(a,b,c-d)+read(a,b-d,c-d);
	}
	long long solve()
	{
		int n,m,d;
		cin>>n>>d>>m;
		long long ans=0;
		for(int i=1;i<=n;i++)
		{
			int a,b,c;
			cin>>a>>b>>c;
			tab[a][b+c][b-c+m]++;
			ans-=tab[a][b+c][b-c+m];
			t.emplace_back(a,b+c,b-c+m);
		}
		for(int i=1;i<=M;i++)
		{
			for(int j=1;j<=2*M;j++)
			{
				for(int k=1;k<=2*M;k++)
				{
					pref[i][j][k]=tab[i][j][k]+read(i,j-1,k)+read(i,j,k-1)-read(i,j-1,k-1);
				}
			}
		}
		for(auto [a,b,c]:t)
		{
			for(int i=1;i<=a;i++)
			{
				if(a-i>d)
					continue;
				ans+=read_d(i,b,c,d-(a-i))+read_d(i,b-1,c+d,d-(a-i)-1);
			}
		}
		return ans;
	}
};
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int board_type;
	cin>>board_type;
	if(board_type==1)
		cout<<d1::solve();
	else if(board_type==2)
		cout<<d2::solve();
	else
		cout<<d3::solve();
	cout<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 712 KB Output is correct
2 Correct 18 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 588 KB Output is correct
2 Correct 23 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 720 KB Output is correct
2 Correct 20 ms 716 KB Output is correct
3 Correct 21 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4040 KB Output is correct
2 Correct 34 ms 4032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 3972 KB Output is correct
2 Correct 45 ms 4032 KB Output is correct
3 Correct 42 ms 4032 KB Output is correct
4 Correct 44 ms 4024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 4604 KB Output is correct
2 Correct 65 ms 4616 KB Output is correct
3 Correct 54 ms 4620 KB Output is correct
4 Correct 50 ms 4648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 10308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 8976 KB Output is correct
2 Incorrect 63 ms 8916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 117 ms 13480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 15796 KB Output isn't correct
2 Halted 0 ms 0 KB -