Submission #411722

# Submission time Handle Problem Language Result Execution time Memory
411722 2021-05-25T19:05:42 Z Jasiekstrz Pairs (IOI07_pairs) C++17
60 / 100
173 ms 15824 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;
		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;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 716 KB Output is correct
2 Correct 15 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 712 KB Output is correct
2 Correct 20 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 588 KB Output is correct
2 Correct 22 ms 716 KB Output is correct
3 Correct 20 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3968 KB Output is correct
2 Correct 33 ms 4032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 4032 KB Output is correct
2 Correct 44 ms 4032 KB Output is correct
3 Correct 49 ms 3996 KB Output is correct
4 Correct 44 ms 4032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 4636 KB Output is correct
2 Correct 65 ms 4656 KB Output is correct
3 Correct 51 ms 4656 KB Output is correct
4 Correct 50 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 10316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2120 KB Output is correct
2 Incorrect 41 ms 2672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 11100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 173 ms 15824 KB Output isn't correct
2 Halted 0 ms 0 KB -