Author: SashaT9, prepared: SashaT9, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
int cnt=0;
for(int i=0;i<n;i++)
{
int x;cin>>x;
if(x%2!=0)cnt++;
}
if(cnt%2==0)cout<<"YES\n";
else cout<<"NO\n";
}
}
Code Python
for i in range(int(input())):
n=int(input())
a=[*map(int,input().split())]
cnt=0
for i in range(n):
if a[i]%2!=0:cnt+=1
if cnt%2==0:print('YES')
else:print('NO')
Author: SashaT9, prepared: FBI, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
string s;cin>>s;
s='0'+s;
int p=s.size();
for(int i=s.size()-1;i>=0;i--)
{
if(s[i]>='5')s[i-1]++,p=i;
}
for(int i=(s[0]=='0');i<s.size();i++)
{
cout<<(i>=p?'0':s[i]);
}
cout<<"\n";
}
}
Code Python
for i in range(int(input())):
s=[0]+[*map(int,list(input()))]
k=len(s)
for i in range(len(s)-1,0,-1):
if s[i]>4:s[i-1]+=1;k=i
if s[0]!=0:print(s[0],end='')
s=[*map(str,s)]
print(''.join(s[1:k]+['0']*(len(s)-k)))
Author: SashaT9, prepared: SashaT9, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
int m=n*(n-1)/2,b[m];
for(int i=0;i<m;i++)cin>>b[i];
sort(b,b+m);
for(int i=0;i<m;i+=--n)cout<<b[i]<<' ';
cout<<"1000000000\n";
}
}
Code Python
for _ in range(int(input())):
n=int(input())
l=sorted(map(int,input().split()))
j=0
for i in range(n-1,0,-1):
print(l[j],end=' ')
j+=i
print(l[-1])
Author: Pa_sha, prepared: SashaT9, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],b[N];
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int mx=INT_MIN;
for(int i=1;i<=n;i++)mx=max(mx,a[i]-b[i]);
int c=0;
for(int i=1;i<=n;i++)c+=(a[i]-b[i]==mx);
cout<<c<<"\n";
for(int i=1;i<=n;i++)if(a[i]-b[i]==mx)cout<<i<<' ';
cout<<"\n";
}
}
Code Python
for _ in range(int(input())):
n=int(input())
a=[*map(int,input().split())]
b=[*map(int,input().split())]
c=[a[i]-b[i] for i in range(n)]
mx=max(c)
ans=[]
for i in range(n):
if c[i]==mx:ans.append(i+1)
print(len(ans))
print(*ans)
Author: SashaT9, prepared: SashaT9, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
pair<int,int>x[N];
long long a[N];
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
long long s1=0,s2=0;
for(int i=1;i<=n;i++)
{
cin>>x[i].first;
x[i].second=i;
s2+=x[i].first;
}
sort(x+1,x+n+1);
for(int i=1;i<=n;i++)
{
s2-=x[i].first;
s1+=x[i].first;
a[x[i].second]=n+1ll*x[i].first*(2*i-n)-s1+s2;
}
for(int i=1;i<=n;i++)cout<<a[i]<<" \n"[i==n];
}
}
Code Python
for i in range(int(input())):
n=int(input())
a=sorted([(b,i)for i,b in enumerate(map(int,input().split()))])
ans=[0]*n
s1=0
s2=sum(a[i][0] for i in range(n))
for i in range(n):
ans[a[i][1]]=s2-a[i][0]*(n-i)+n-i+a[i][0]*i-s1+i
s1+=a[i][0]
s2-=a[i][0]
print(*ans)
Author: Pa_sha, prepared: Pa_sha, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
map<long long,int>cnt;
long long my_sqrt(long long a)
{
long long l=0,r=5000000001;
while(r-l>1)
{
long long mid=(l+r)/2;
if(1ll*mid*mid<=a)l=mid;
else r=mid;
}
return l;
}
long long get(int b,long long c)
{
long long D=1ll*b*b-4ll*c;
if(D<0)return 0;
long long x1=(b-my_sqrt(D))/2;
long long x2=(b+my_sqrt(D))/2;
if(x1+x2!=b||x1*x2!=c)return 0;
if(x1==x2)return 1ll*cnt[x1]*(cnt[x1]-1)/2ll;
else return 1ll*cnt[x1]*cnt[x2];
}
int main()
{
int t;cin>>t;
while(t--)
{
int n;cin>>n;
cnt.clear();
for(int i=1;i<=n;i++)
{
int x;cin>>x;
cnt[x]++;
}
int q;cin>>q;
for(int i=0;i<q;i++)
{
int b;long long c;
cin>>b>>c;
cout<<get(b,c)<<" \n"[i==q-1];
}
}
}
Code Python
from collections import Counter
from math import sqrt
for _ in range(int(input())):
n=int(input())
a=[*map(int,input().split())]
d=Counter(map(str,a))
for i in range(int(input())):
x,y=map(int,input().split())
if x*x-4*y<0:print(0);continue
D=int(sqrt(x*x-4*y))
x1=(x+D)//2
x2=(x-D)//2
if x1+x2!=x or x1*x2!=y:print(0);continue
if x1!=x2:print(d[str(x1)]*d[str(x2)])
else:print(d[str(x1)]*(d[str(x1)]-1)//2)
Author: SashaT9, prepared: SashaT9, Esestree
Tutorial
Tutorial is loading...
Code C++
#include<bits/stdc++.h>
using namespace std;
const int N=200000,mod=998244353;
int p[N+1],sz[N+1];
struct edge
{
int u,v,w;
void read(){cin>>u>>v>>w;}
bool operator<(edge x){return w<x.w;}
}a[N+1];
int leader(int v)
{
if(p[v]==v)return v;
else return p[v]=leader(p[v]);
}
void unite(int u,int v)
{
u=leader(u);
v=leader(v);
p[u]=v;
sz[v]+=sz[u];
}
long long binpow(long long a,long long n)
{
if(n==0)return 1;
if(n%2==0)return binpow(a*a%mod,n/2);
else return a*binpow(a,n-1)%mod;
}
int main()
{
int t;cin>>t;
while(t--)
{
int n,S;cin>>n>>S;
for(int i=1;i<=n;i++)p[i]=i,sz[i]=1;
for(int i=0;i<n-1;i++)a[i].read();
sort(a,a+n-1);
long long ans=1;
for(int i=0;i<n-1;i++)
{
int sub_u=sz[leader(a[i].u)];
int sub_v=sz[leader(a[i].v)];
ans=ans*binpow(S-a[i].w+1,1ll*sub_u*sub_v-1)%mod;
unite(a[i].u,a[i].v);
}
cout<<ans<<"\n";
}
}
Code Python
mod=998244353
def find_(v):
stack=[v]
while dsu[v]!=v:
stack.append(dsu[v])
v=stack[-1]
while stack:
dsu[stack[-1]]=dsu[v]
v=stack.pop()
return dsu[v]
for i in range(int(input())):
n,S=map(int,input().split())
l=[tuple(map(int,input().split()))for i in range(n-1)]
l.sort(key=lambda x:x[2])
ans=1
dsu=[i for i in range(n)]
coun=[1]*n
for a,b,c in l:
a-=1;b-=1
if find_(a)!=find_(b):
ans=ans*pow(S-c+1,coun[dsu[a]]*coun[dsu[b]]-1,mod)
ans%=mod
coun[dsu[a]]+=coun[dsu[b]]
coun[dsu[b]]=0
dsu[b]=dsu[a]
print(ans)