Submission #362141

# Submission time Handle Problem Language Result Execution time Memory
362141 2021-02-01T20:22:21 Z ogibogi2004 Permutation Recovery (info1cup17_permutation) C++14
25 / 100
12 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=70004;
const ll sq=800;
ll mod;
ll d[MAXN];
ll d1[MAXN],e;
ll t[MAXN],n;
ll add(ll a,ll b)
{
	return (a+b+2*mod)%mod;
}
struct block
{
	unordered_map<ll,vector<ll> >mp;
	ll added;
};
block b[sq];
ll p[MAXN];
int main()
{
	srand(3432);e=rand();
	mod=rand()%((ll)1e18);
	mod+=(ll)5e17;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{    
		string s;
		cin>>s;
		for(ll j=0;j<s.size();j++)
		{
		 	t[i]=((ll)t[i]*10+s[j]-'0')%mod;
		}
	}
	for(ll i=1;i<=n;i++)
	{
		d[i]=add(t[i],-t[i-1]);
		d1[i]=d[i];
	}
	for(ll i=1;i<=n;i++)
	{
		b[i/sq].added=0;
		b[i/sq].mp[d[i]^e].push_back(i);
	}
	//for(ll i=1;i<=n;i++)cout<<d1[i]<<" ";
	//cout<<endl;
	for(ll j=1;j<=n;j++)
	{
		for(ll l=n/sq;l>=0;l--)
		{
			if(b[l].mp.count((1+b[l].added)^e)&&b[l].mp[(1+b[l].added)^e].size()>0)
			{
				ll t=b[l].mp[(1+b[l].added)^e].back();
				for(ll i=l+1;i<=n/sq;i++)
				{
					b[i].added=add(b[i].added,d[t]);
				}
				for(ll i=t+1;i<=n&&i%sq!=0;i++)
				{
					d1[i]-=d[t];
				}
				b[l].mp.clear();
				p[t]=j;
				for(ll i=max(1ll,l*sq);i<=n&&i/sq==l;i++)
				{
					if(p[i]==0)b[i/sq].mp[d1[i]^e].push_back(i);
				}
				break;
			}
		}
		//for(ll i=1;i<=n;i++)cout<<d1[i]<<" ";
		//cout<<endl;
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<p[i]<<" ";
	}
	cout<<endl;
return 0;
}

Compilation message

permutation.cpp: In function 'int main()':
permutation.cpp:31:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(ll j=0;j<s.size();j++)
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
3 Incorrect 12 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -