Submission #355621

# Submission time Handle Problem Language Result Execution time Memory
355621 2021-01-22T21:05:57 Z ogibogi2004 Pairs (IOI07_pairs) C++14
30 / 100
94 ms 15456 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int b,n,d,m;
void solve1()
{
	vector<int>v;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	queue<int>q;
	long long ans=0;
	for(int i=0;i<v.size();i++)
	{
		q.push(v[i]);
		while(v[i]-q.front()>d)
		{
			q.pop();
		}
		ans+=q.size()-1;
	}
	cout<<ans<<endl;
}
vector<int>animals[500000];
int bit[500000];
void update(int idx,int val)
{
	idx++;
	for(;idx<500000;idx+=idx&(-idx))
	{
		bit[idx]+=val;
	}
}
int query(int idx)
{
	//cout<<idx<<endl;
	idx++;
	int ret=0;
	for(;idx>0;idx-=idx&(-idx))
	{
		ret+=bit[idx];
	}
	return ret;
}
ll query(int l,int r)
{
	return query(r)-query(l-1);
}
void solve2()
{
	vector<pair<int,int> >v;
	int min1=(int)1e9,min2=(int)1e9;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		v.push_back({x-y,x+y});
		min1=min(min1,v.back().first);
		min2=min(min2,v.back().second);
	}
	for(int i=0;i<v.size();i++)
	{
		v[i].first-=min1;
		v[i].second-=min2;
	}
	for(auto xd:v)
	{
		animals[xd.first].push_back(xd.second);
	}
	ll ans=0;
	for(int i=0;i<500000;i++)
	{
		//cout<<i<<endl;
		sort(animals[i].begin(),animals[i].end());
		if(i-d-1>=0)
		{
			for(auto a:animals[i-d])
			{
				update(a,-1);
			}
		}
		for(auto a:animals[i])
		{
			ans+=query(a-d,a+d);
			update(a,+1);
		}
	}
	cout<<ans<<endl;
}
int main()
{
	cin>>b>>n>>d>>m;
	if(b==1)solve1();
	if(b==2)solve2();
return 0;
}

Compilation message

pairs.cpp: In function 'void solve1()':
pairs.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
pairs.cpp: In function 'void solve2()':
pairs.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12012 KB Output is correct
2 Correct 8 ms 12012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12772 KB Output is correct
2 Correct 37 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 12816 KB Output is correct
2 Correct 61 ms 12920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 12648 KB Output is correct
2 Correct 55 ms 12648 KB Output is correct
3 Correct 60 ms 12648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 12684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 13536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 13664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 15456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12012 KB Output isn't correct
2 Halted 0 ms 0 KB -