Submission #355622

# Submission time Handle Problem Language Result Execution time Memory
355622 2021-01-22T21:07:33 Z ogibogi2004 Pairs (IOI07_pairs) C++14
60 / 100
96 ms 16608 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-1])
			{
				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 9 ms 12012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 12648 KB Output is correct
2 Correct 37 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 12648 KB Output is correct
2 Correct 58 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 12648 KB Output is correct
2 Correct 61 ms 12776 KB Output is correct
3 Correct 54 ms 12796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12792 KB Output is correct
2 Correct 11 ms 12652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 13536 KB Output is correct
2 Correct 62 ms 14048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 13664 KB Output is correct
2 Correct 72 ms 14432 KB Output is correct
3 Correct 72 ms 14304 KB Output is correct
4 Correct 70 ms 14304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 15456 KB Output is correct
2 Correct 96 ms 16608 KB Output is correct
3 Correct 82 ms 15328 KB Output is correct
4 Correct 81 ms 15328 KB Output is correct
# 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 7 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 -