QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326557 | #5533. Trick | hotboy2703 | 29 | 77ms | 17972kb | C++14 | 4.1kb | 2024-02-13 13:53:54 | 2024-02-13 13:53:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
mt19937_64 rng(1);
mt19937_64 rng2(chrono::steady_clock::now().time_since_epoch().count());
ll random2(ll l,ll r){
return rng2()%(r-l+1)+l;
}
ll random(ll l,ll r){
return rng()%(r-l+1)+l;
}
ll myrandom(ll i){
return rng()%i;
}
ll base1=998244353, base2=1e9+7;
ll match[505][505];
const ll MOD = 10000121;
ll random_val[MOD];
ll f(ll x,ll y,ll n){
ll val = ((random_val[x]%MOD+500)*(2*n+5)+random_val[y]%MOD+1+69420)*45;
val += MOD/2;
val = val%MOD;
val = val*val%MOD;
return random_val[val]%(2*n+1);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for (ll i = 0;i < MOD;i ++)random_val[i] = rng();
ll t, type; cin >> t >> type;
auto assistant_small=[&](ll n)
{
ll sum=0, Mod=n*2+1;
vector <ll> a(n);
for (ll& i:a) cin >> i, sum=(sum+i)%Mod;
for (ll i=0; i<n; i++)
for (ll j=0; j<n; j++)
if (i!=j && match[a[i]][a[j]]==sum)
{
cout << a[i] << " " << a[j] << "\n";
return;
}
};
auto magician_small=[&](ll n)
{
ll Mod=n*2+1, fa1, fb1, fa2, fb2; cin >> fa1 >> fb1 >> fa2 >> fb2;
ll sum=match[fa1][fb1]+match[fa2][fb2];
sum=((n*2+1-sum)%Mod+Mod)%Mod; cout << sum << "\n";
};
auto assistant=[&](ll n)
{
ll sum=0, fa=0, fb=0, Mod=n*2+1;
vector <ll> a(n);
for (ll& i:a) cin >> i, sum=(sum+i)%Mod;
sort(a.begin(), a.end());
for (ll i=0; i<n; i++)
for (ll j=i+1; j<n; j++)
{
if ((a[i]+a[j])%Mod==sum) fa=a[i], fb=a[j];
if ((a[i]+a[j]+n)%Mod==sum) fa=a[j], fb=a[i];
}
cout << fa << " " << fb << "\n";
};
auto magician=[&](ll n)
{
ll Mod=n*2+1, fa1, fb1, fa2, fb2; cin >> fa1 >> fb1 >> fa2 >> fb2;
ll sum=(fa1<fb1?fa1+fb1:fa1+fb1+n)+(fa2<fb2?fa2+fb2:fa2+fb2+n);
sum=((n*2+1-sum)%Mod+Mod)%Mod; cout << sum << "\n";
};
while (t--)
{
ll n; cin >> n;
if (n <= 6){
auto init=[&](ll a, ll b)
{
for (ll s=0; s<=n*2; s++)
match[(a+s)%(n*2+1)][(b+s)%(n*2+1)]=s;
};
if (n<=500)
{
if (n%2==0)
{
for (ll i=n*2; i>=n+2; i--)
init(i, n*2+1-i);
init(0, n*2), init(0, 1), init(n*2-3, n+1);
init(n, 2), init(n, n*2-1), init(4, n+1);
}
else
{
for (ll i=1; i<=n-1; i++)
init(i, n*2+1-i);
init(0, n*2), init(0, 1), init(n, 2);
init(n, n*2-1), init(4, n+1), init(n*2-3, n+1);
}
if (type<=2) assistant_small(n);
else magician_small(n);
}
else
{
if (type<=2) assistant(n);
else magician(n);
}
}
else{
if (type==3){
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll res = -(f(a,b,n)+f(c,d,n));
res = (res%(2*n+1)+2*n+1)%(2*n+1);
cout<<res<<'\n';
}
else{
vector <ll> a(n);
ll sum = 0;
for (auto &x:a){cin>>x;sum = (sum+x)%(2*n+1);}
ll u,v;
u = random2(0,sz(a)-1);
v = random2(0,sz(a)-1);
while ((u == v || f(a[u],a[v],n) != sum)){
u = random2(0,sz(a)-1);
v = random2(0,sz(a)-1);
}
cout<<a[u]<<' '<<a[v]<<'\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 29
Accepted
Test #1:
score: 29
Accepted
time: 77ms = 0ms + 77ms
memory: 1kb,17972kb
input:
12012 1 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 4 6 6 0 1 2 3 5 6 6 0 1 2 3 5 6 6 0 1 2 3 5 6 6 0 1 2 3 5 6 6 0 1 2 3 5 6 6 0 1 2 3 5 6 6 0 1 2 3 5 ...
output:
0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 6 0 6 0 6 0 6 0 6 0 6 0 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 4 6 4 6 4 6 4 6 4 6 4 6 4 6 6 5 6 5 6 5 6 5 6 5 6 5 6 5 0 5 0 5 0 5 0 5 0 5 0 5 0 5 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 7 1 7 1 7 1 7 1 7 1 7 1 7 3 7 3 7 3 7 3 7 3 7 3 7 3 7 2 0 2 0 2 0 2 0 2 0 2 0 2 0 0 5 0 5 0 5 0 5 0 5 ...
input:
12012 2 6 7 8 9 10 11 12 6 6 8 9 10 11 12 6 6 7 9 10 11 12 6 6 7 8 10 11 12 6 6 7 8 9 11 12 6 6 7 8 9 10 12 6 6 7 8 9 10 11 6 7 8 9 10 11 12 6 5 8 9 10 11 12 6 5 7 9 10 11 12 6 5 7 8 10 11 12 6 5 7 8 9 11 12 6 5 7 8 9 10 12 6 5 7 8 9 10 11 6 7 8 9 10 11 12 6 4 8 9 10 11 12 6 4 7 9 10 11 12 6 4 7 8 1...
output:
9 12 8 11 7 10 10 7 7 12 9 7 8 6 9 12 9 5 10 7 5 8 5 12 5 10 7 5 9 12 8 4 7 12 4 7 7 4 4 9 9 11 9 12 10 8 3 10 8 3 11 12 3 8 7 11 9 12 2 9 9 2 7 2 8 12 2 7 7 9 9 12 10 1 10 12 8 12 7 11 1 10 7 8 9 12 9 0 7 0 7 11 7 9 0 9 10 0 8 11 9 5 9 6 5 12 8 6 10 12 9 11 8 11 8 4 4 11 8 6 4 9 6 4 8 10 8 11 10 8 ...
input:
12012 3 6 0 4 9 12 6 0 4 8 11 6 0 4 7 10 6 0 4 10 7 6 0 4 7 12 6 0 4 9 7 6 0 4 8 6 6 0 6 9 12 6 0 6 9 5 6 0 6 10 7 6 0 6 5 8 6 0 6 5 12 6 0 6 5 10 6 0 6 7 5 6 2 6 9 12 6 2 6 8 4 6 2 6 7 12 6 2 6 4 7 6 2 6 7 4 6 2 6 4 9 6 2 6 9 11 6 4 6 9 12 6 4 6 10 8 6 4 6 3 10 6 4 6 8 3 6 4 6 11 12 6 4 6 3 8 6 4 6...
output:
6 7 8 9 10 11 12 5 7 8 9 10 11 12 4 7 8 9 10 11 12 3 7 8 9 10 11 12 2 7 8 9 10 11 12 1 7 8 9 10 11 12 0 7 8 9 10 11 12 5 6 8 9 10 11 12 4 6 8 9 10 11 12 3 6 8 9 10 11 12 2 6 8 9 10 11 12 1 6 8 9 10 11 12 0 6 8 9 10 11 12 4 5 8 9 10 11 12 3 5 8 9 10 11 12 2 5 8 9 10 11 12 1 5 8 9 10 11 12 0 5 8 9 10 ...
result:
ok very good job! (12012 test cases)
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
6576 1 6 12 2 3 11 5 6 6 0 1 8 3 10 5 6 0 1 6 11 7 5 6 0 12 8 3 5 9 6 0 1 7 3 4 6 6 0 12 8 3 4 5 6 0 1 2 7 12 5 6 1 2 8 4 7 6 6 12 7 9 4 10 6 6 0 1 11 4 5 6 7 10 14 3 4 12 8 9 7 0 10 2 9 4 5 7 7 1 9 3 11 10 6 7 7 0 13 14 8 9 6 12 7 12 1 8 3 7 5 9 7 0 1 2 8 9 5 7 7 0 10 12 4 11 8 9 7 13 1 2 3 4 11 6 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
6525 1 6 10 1 11 3 12 6 6 1 7 10 12 5 6 6 0 10 12 7 9 8 6 12 1 8 4 7 11 6 11 8 9 4 10 6 6 0 7 2 3 4 5 6 0 8 3 10 11 6 6 0 1 2 4 7 6 6 0 1 11 9 5 6 6 7 1 12 8 6 5 7 0 1 13 10 12 5 6 7 0 14 2 3 4 12 6 7 11 1 3 8 12 6 13 7 0 1 2 3 13 5 14 7 11 9 10 8 4 14 7 7 0 8 14 3 4 13 11 7 0 10 2 14 8 5 6 7 0 13 2...
output:
result:
Subtask #4:
score: 0
Skipped