Codeforces Round #679 (Div. 2, based on Technocup 2021 Elimination Round 1)
A. Finding Sasuke
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int mod = 998244353;
void solve() {
int n;
cin>>n;
for(int i=0;i<n;i+=2){
int x,y;
cin>>x>>y;
cout<<y<<" "<<-x<<" ";
}
cout<<"\n";
}
signed main() {
int _ = 1;
cin >> _;
while (_--) solve();
return 0;
}
B. A New Technique
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int mod = 998244353;
int k,n,m,ans[510][510];
int mp[250010];
void solve() {
cin>>n>>m;
for (int i = 1; i <=n; ++i)
for (int j = 1; j <=m; ++j)
cin>>k,mp[k]=j;
for (int i = 1; i <=m; ++i) {
for (int j = 1; j <=n; ++j) {
cin>>k;
ans[j][mp[k]]=k;
}
}
for (int i = 1; i <=n; ++i) {
for (int j = 1; j <=m; ++j) {
cout<<ans[i][j]<<" ";
}
cout<<"\n";
}
}
signed main() {
int _ = 1;
cin >> _;
while (_--) solve();
return 0;
}
C. Perform Easily
#include <bits/stdc++.h>
using namespace std;
int a[19],n,b[100500],ans=1e9;
int main() {
for (int i=0; i<6; ++i)
scanf("%d",a+i);
sort(a,a+6);
a[6]=1e9;
scanf("%d",&n);
for (int i=0; i<n; ++i)
scanf("%d",b+i);
sort(b,b+n);
for (int i=0; i<n; ++i)
for (int j=0; j<6; ++j) {
int l=b[i]-a[j],r=0;
if (l>b[0]-a[0]) continue;
for (int i=0; i<5; ++i) {
r=max(r,*(lower_bound(b,b+n,l+a[i+1])-1)-a[i]);
}
if(b[n-1]>=l+a[5])
{
r=max(r,b[n-1]-a[5]);
}
ans=min(ans,r-l);
}
cout<<ans;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e10+5;
const int maxn=1e5+5;
vector<int>a,vv,uu[maxn*6];
int b[maxn];
map<int,int >ma,car;
void solve() {
car.clear();
ma.clear();
for(int i=0;i<6*maxn;i++)
uu[i].clear();
vv.clear();
a.clear();
for(int i=1;i<7;i++)
{
int xx;
cin>>xx;
a.push_back(xx);
}
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
int m=a.size();
int n;
cin>>n;
int res=inf;
int min_=inf;
int max_=0;
int sum=0;
for(int i=1;i<=n;i++)
{
cin>>b[i];
int mm=inf;
for(int j=0;j<m;j++)
{
int yy=abs(b[i]-a[j]);
vv.push_back(yy);
if(yy<mm)
{
mm=yy;
}
}
if(mm<min_)
min_=mm;
if(mm>max_)
max_=mm;
}
res=max_-min_;
sort(vv.begin(),vv.end());
vv.erase(unique(vv.begin(),vv.end()),vv.end());
for(int i=0;i<vv.size();i++)
ma[vv[i]]=i;
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
int yy=abs(b[i]-a[j]);
uu[ma[yy]].push_back(i);
}
}
int r=lower_bound(vv.begin(),vv.end(),max_)-vv.begin();
int l=lower_bound(vv.begin(),vv.end(),min_)-vv.begin();
sum=n;
for(int i=l;i<=r;i++)
{
for(int j=0;j<uu[i].size();j++)
{
car[uu[i][j]]++;
}
}
while(r+1<vv.size())
{
while(sum==n)
{
if(vv[r]-vv[l]<res)
{
res=vv[r]-vv[l];
}
l++;
for(int i=0;i<uu[l-1].size();i++)
{
if(car[uu[l-1][i]]==1)
sum--;
car[uu[l-1][i]]--;
}
}
r++;
for(int i=0;i<uu[r].size();i++)
{
if(car[uu[r][i]]==0)
sum++;
car[uu[r][i]]++;
}
}
cout<<res;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}