2021CCPC online replay supplement - "Monopoly" (hash / two points)

Say some nonsense

In fact, the origin of this online game can be said to be a little twists and turns. At the end of the first online game, our team actually collapsed. Due to system reasons, the four questions that could have been ac could not be submitted. Finally, even 2000 did not squeeze into (there were only 5000 teams in total!

Although the official apologized after the game and made the decision to replay, I personally think that apologizing can not make up for the huge mistakes that have occurred.

However, at the scene of the replay, that is, the just concluded online game, HDOJ had a huge loophole. Some players responded that they could view the AC code of other teams by modifying the pip value in the address bar. Did the last rank also have a lot of water? These two CCPC online games were a great test for the players' mentality, from failing to hand in the question to the code After the leakage, the final ranking moisture is unknown. Even in question 1007, the question group gave false positive solutions and test data, so should question 1007 still be included in ranking? However, HDU has made it clear that it will not replay again after the game.

Although our team narrowly won the qualification of CCPC in the second half of the year with the last 10 minutes of the replay, it made us have great doubts about the moisture of CCPC anyway..




Portal

Title Introduction: the prototype of this title is the game "millionaire" . there is A circular map with A length of n, each point is recorded as 1-n in turn, and each point has its corresponding integral, which can be positive or negative. Each query gives A target score x, and player A is required to traverse the whole map in turn from point 1 for unlimited times. Ask the minimum number of steps that can get the score X. if the goal cannot be achieved, output - 1;

Idea: note that the prefix sum of point I is a[i], the integral sum of traversing a circle is sum, and k is any nonnegative integer

Not hard to get:

If the target score can be achieved, there are

However, the test data given by the topic is large, and the query times of 1e5*1e5 will be tle if you do it violently. Therefore, consider hash or dichotomy.

First consider hashing, using the map in stl

The code is as follows:

//Dichotomy
#include<iostream>
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int mx=100005;
int t,n,m,cnt;
struct node
{
	ll sm,id;
	int ip;
}po[mx];
inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-') 
			f=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
	}
	return x*f;
}

inline bool cmp(node a,node b)
{
	if(a.id==b.id)
	{
		if(a.sm==b.sm) 
			return a.ip<b.ip;
		return a.sm<b.sm;
	}
	return a.id<b.id;
}
int main()
{
	t=read();
	for(int op=1;op<=t;++op)
	{
		n=read();m=read();
		ll sm=0,p,rp;
		bool flag=false;
		po[0].sm=0;po[0].ip=0;
		for(int i=1;i<n;++i)
		{
			sm+=read();po[i].sm=sm;
			po[i].ip=i;
		}
		sm+=read();
		if(sm<0){
			flag=true;sm=-sm;
			for(int i=0;i<n;++i) po[i].sm=-po[i].sm;
		}
		for(int i=0;i<n;++i) po[i].id=sm!=0?(po[i].sm%sm+sm)%sm:0;
		sort(po,po+n,cmp);cnt=0;
		for(int i=1;i<n;++i) if(po[i].id!=po[i].id||po[i].sm!=po[i-1].sm) po[++cnt]=po[i];
		if(sm==0){
			for(int i=1;i<=m;++i)
			{
				p=read();
				int l=0,r=cnt,mid;
				while(l<r)
				{
					mid=(l+r)>>1;
					if(po[mid].sm<p) 
						l=mid+1;
					else 
						r=mid;
				}
				if(po[l].sm!=p) printf("-1\n");
				else printf("%d\n",po[l].ip);
			}
		}
		else
		for(int i=1;i<=m;++i){
			p=read();if(flag) p=-p;
			rp=(p%sm+sm)%sm;
			int l=0,r=cnt,mid;
			while(l<r){
				mid=(l+r+1)>>1;
				if(po[mid].id<rp) l=mid;
				else if(po[mid].id>rp) r=mid-1;
				else if(po[mid].sm>p) r=mid-1;
				else l=mid;
			}
			if(po[l].id!=rp) printf("-1\n");
			else if(sm>0&&po[l].sm>p) printf("-1\n");
			else if(sm<0&&po[l].sm<p) printf("-1\n");
			else printf("%lld\n",po[l].ip+n*(p-po[l].sm)/sm);
		}
		
	}
	return 0;
}

Tags: Algorithm data structure

Posted on Sun, 17 Oct 2021 19:07:13 -0400 by Muddy_Funster