UPC Spring 2020 Mixed Personal Training Game 35 [B&D&G]

Question B: Number Title Description Little H is a collector. He likes to collect positive integers.Little H has a habit...

Question B: Number
Title Description
Little H is a collector. He likes to collect positive integers.Little H has a habit of counting how many pairs of positive integers the greatest common factor is exactly k out of all the positive integers in his collection before he goes to bed.
Small H may collect a new positive integer each day, or it may discard a positive integer for some reason.This keeps the positive integers in his collection changing and the values calculated each day before going to bed may be different.But k never changes.Also, small H guarantees that k is 1 or prime.
Little H wants to know how many pairs of positive integers have the maximum common factor k after each new positive integer he collects or discards.

input
The first row has two integers n,k.Next n rows, two integers a and B each.
If a=0, little H discards a positive integer b in his collection.If there is no b in the positive integer of Little H collection at this time, it may be that Little H has misremembered, so no change is needed.
If a=1, it means that little H has a new positive integer b in his collection.Note that small H can collect many identical positive integers.

output
Output n lines, one integer per line, indicating the answer after a discard or collection.

sample input
[Example 1]
5 2
1 2
1 4
0 2
1 2
1 2
[Example 2]
8 3
1 3
0 3
0 3
1 3
1 6
1 9
1 12
1 2

sample output
[Example 1]
0
1
0
1
3
[Example 2]
0
0
0
0
1
3
5
5

Tips
Note z as the maximum of the positive integers that Small H has collected.
For all data, 1 < k < z.
For 20% of the data, n < 70.
For 50% of the data, n is less than 1000.
For 100% of the data, 1 < n,z < 10^5.

Questions:

#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5+5; vector<int> g[N]; int n,k,cnt[N],a[N],m=100000,miu[N]; ll ans; bool bz[N]; ll c2(ll x){ return x * (x - 1) / 2; } void add(int x) { if(x % k) return; a[x]++; x /= k; int len = g[x].size(),i; for(int i=0; i<len; i++) { int y = g[x][i]; ans -= miu[y] * c2(cnt[y]); cnt[y]++; ans += miu[y] * c2(cnt[y]); } } void del(int x) { if(x % k) return; if(!a[x]) return; a[x]--; x /= k; int len = g[x].size(),i; for(int i=0; i<len; i++) { int y = g[x][i]; ans -= miu[y] * c2(cnt[y]); cnt[y]--; ans += miu[y] * c2(cnt[y]); } } int main() { int op,x; for(int i=1; i<=m; i++) for(int j=i; j<=m; j+=i) g[j].push_back(i); for(int i=1; i<=m; i++) miu[i] = 1; for(int i=2; i<=m; i++) if(!bz[i]) { miu[i]=-1; for(int j=2*i; j<=m; j+=i) { bz[j] = 1; if(j/i%i == 0) miu[j] = 0; else miu[j] *= -1; } } scanf("%d%d",&n,&k); while(n--) { scanf("%d%d",&op,&x); if(op == 0) del(x); else add(x); printf("%lld\n",ans); } }

Question D: Virus
Title Description
chen_03 will create a computer virus.
Someone has implanted Jay's computer with a virus. To get rid of it, Jay has to answer a question.
On the computer screen, Jay is asked to enter a positive integer, which can be divided by all the numbers in [1,n], and kept to a minimum because this number can be very large, so just output the result of modelling 109+7.
However, Jay successfully cracked the virus and inserted it into your computer.
Then you have to start solving the problem.

input
Enter a positive integer n.

output
Output a positive integer for the answer.

sample input
10

sample output
2520

Questions:

#include <bits/stdc++.h> using namespace std; typedef long long ll; ll x; int main() { cin>>x; vector<ll>v; for(int i=2; i<=x/i; i++) { ll res=0; if(x%i==0) { while(x%i==0) x/=i,res++; v.push_back(res); } } if(x>1) v.push_back(1); ll sum=0; for(int i=0; i<v.size(); i++) { ll ans=0; int j=1; while(ans+j<=v[i]) { ans+=j; sum++; j++; } } cout<<sum<<endl; return 0; }

Question G: Pigeons (gu)
Title Description
A total of n people have entered the computer room i n turn, and the strength of the first person is ai.
When the first person walks into the computer room, he will worship the person x who is already in the computer room, if and only if ax>ai.
Similarly, when the ith person walks into the computer room, he will be worshipped by the person who is currently in the computer room, if and only if a x<ai.
The volume of the third person is VI.If he worships K people when he walks into the computer room, he will produce vi*k noise value.
Suppose when he enters the computer room, the people who worship him assemble as , then these people will produce *** noise values.
The ctt2006 giant wants to know how much noise each person is making when they walk into the computer room.As he was busy hanging the training team, he left the problem to you.

input
The first line has a positive integer n, which represents the number of people.
Next n rows, two numbers ai,vi in each row, the meaning is described in the title.

output
Number of n rows separated by spaces.Number i represents the noise the ith person makes when he enters the computer room, including before.
Since these values can be very large, simply output their mod 998244353 values.

sample input
5
3 1
2 3
1 4
5 2
4 5

sample output
0 3 11 19 32

Tips
Example 1 explains:
The first person walks into the computer room, because there is only one person, the noise is 0;
The second person walks into the computer room, there is 1 stronger person than him, there is no weaker person than him, the total noise produced currently is 3 x 1=3;
The third person walks into the computer room, there is 1,2 stronger than him, there is no weaker person than him, the total noise produced currently is: 3*1+4*2=11;
The fourth person walks into the computer room, there is no stronger person than him, there are 1,2,3 weaker people than him, the total noise produced currently is 3*1+4*2+1+3+4=19;
The fifth person walks into the computer room, 4 stronger than him, 1, 2, 3 weaker than him, and currently produces a total of noise: 3 x 1+4 x 2+1+3+4+1+3+4+5=19.

Questions:
Each person entering the computer room needs to maintain two values:
One is the sum of personal noise in Bydia;
The first is the sum of the iPersonal Bye Room Bugs.
For the first value, we only need two-dimensional tree array maintenance.

// 2-D Tree Array #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=998244353; const int N=5e5+10000; ll c[N][2]; ll a[N],b[N],num[N]; ll sum[N]; int n; int lowbit(int x){ return x&(-x); } void add(int i,int val,int u) { while(i<N) { c[i][u]=(c[i][u]+val)%MOD; i+=lowbit(i); } } ll ask(int i,int u) { ll res=0; while(i) { res=(res+c[i][u])%MOD; i-=lowbit(i); } return res; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld %lld",&a[i],&b[i]),num[i]=a[i]; sort(num+1,num+1+n); int m=unique(num+1,num+1+n)-num; for(int i=1;i<=n;i++) { int k=lower_bound(num+1,num+1+m,a[i])-num; add(k,1,1); add(k,b[i],2); ll val=ask(k-1,2); val=(val+(ask(N-1,1)-ask(k,1))*b[i]%MOD)%MOD; sum[i]=val; } for(int i=1;i<=n;i++) { sum[i]=(sum[i-1]+sum[i])%MOD; cout<<sum[i]%MOD<<" "; } return 0; }

5 June 2020, 21:28 | Views: 6540

Add new comment

For adding a comment, please log in
or create account

0 comments