Advertisement
fireLUFFY

EduRound-C

Apr 30th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. //  Author: fireLUFFYY, NITR
  2.  
  3. #pragma GCC optimize("Ofast")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
  5. #pragma GCC optimize("unroll-loops")
  6. #pragma comment(linker, "/stack:200000000")
  7.  
  8. #include<bits/stdc++.h>
  9.  
  10. #define int long long
  11. #define ull unsigned long long
  12. #define vi vector<int>
  13. #define vvl vector<vector<int>>
  14. #define deql deque<int>
  15. #define prquel priority_queue<int>
  16. #define loop(i,n) for(int i=0;i<n;i++)
  17. #define loopn(i,a,b) for(int i=a;i<=b;i++)
  18. #define rloop(i,n) for(int i=n;i>0;i--)
  19. #define sortv(a) sort(a.begin(),a.end())
  20. #define sortvr(a) sort(a.rbegin(),a.rend())
  21. #define verase(a) a.erase(unique(a.begin(),a.end()),a.end())
  22. #define all(a) a.begin(),a.end()
  23. #define dbg(x) cout<<#x<<" = "<<x<<"\n";
  24. #define mp make_pair
  25. #define pb push_back
  26. #define pf push_front
  27. #define fi first
  28. #define se second
  29. #define endl "\n"
  30. #define inf 2e18
  31. using namespace std;
  32.  
  33. int MOD=1000000007;
  34. int mod=998244353;
  35. const int N=200050;
  36. const int nn=1000050;
  37. int fact[N]; // array to store values of factorial
  38. bool prime[nn]; //array to store precalculated primes till 10^6
  39. bool pow2(int x){if(x&&(!(x&(x-1)))) return true; else return false;}
  40. int gcd(int a,int b) { if(a == 0)return b;return gcd(b % a, a);}
  41. int lcm(int a,int b){int val=max(a,b)/gcd(a,b);val*=min(a,b);return val;}
  42. int multiply(int x, int y){return (x * 1ll * y) % MOD;}
  43. int power(int x, int y){int z = 1;while(y){if(y & 1) z = multiply(z, x);x = multiply(x, x);y >>= 1;}return z;}
  44. int modInverse(int x){return power(x, MOD - 2);}
  45. int divide(int x, int y){return multiply(x, modInverse(y));}
  46. void cal_factorial(){fact[0] = 1;for(int i = 1; i < N; i++)fact[i] = multiply(fact[i - 1], i);}// function to calculate factorial upto N
  47. void cal_primes(){memset(prime,true,sizeof(prime)); loopn(i,2,sqrt(nn)){ if(prime[i]==true){ for(int j=i*i;j<=nn;j+=i){prime[j]=false;}}}}
  48. int nCr(int n, int k){return divide(fact[n], multiply(fact[k], fact[n - k]));}
  49. void FASTIO(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
  50.  
  51.  
  52. void solve(int t)
  53. {
  54.     int testcases=t;
  55.     while(t--)
  56.     {
  57.     //  cout<<"#"<<(testcases-t)<<" Test-Case: "<<endl;
  58.         int n,sum=0,it,ans=0,nn;    cin>>n;
  59.         if(n==1)
  60.         {
  61.             int st,un;  cin>>un>>st;
  62.             cout<<st<<endl;
  63.         }
  64.         else
  65.         {
  66.             int u[n],s[n];
  67.             loop(i,n)
  68.             cin>>u[i];
  69.             loop(i,n)
  70.             cin>>s[i];
  71.            
  72.             vi v[n+1];
  73.             loop(i,n)
  74.             v[u[i]].pb(s[i]);
  75.             loop(i,n)
  76.             {
  77.                 if(v[i].size()>0)
  78.                     sortvr(v[i]);
  79.             }
  80.  
  81.             loop(i,n)
  82.             {
  83.                 sum=0,it=0;
  84.                 for(auto x:v[i])
  85.                 {
  86.                     sum+=x;
  87.                     v[i][it]=sum;
  88.                     it+=1;
  89.                 }
  90.             }
  91.             loopn(i,1,n)
  92.             {
  93.                 ans=0;
  94.                 loop(j,n)
  95.                 {
  96.                     nn=(v[j].size()/i);
  97.                 //  cout<<"nn: "<<nn<<endl;
  98.                     if(nn>0){
  99.                         ans+=v[j][(nn*i)-1];
  100.                 //      cout<<"ans: "<<ans<<endl;
  101.                     }
  102.                 }
  103.                 cout<<ans<<" ";
  104.             }
  105.             cout<<endl;
  106.         }
  107.     }
  108. }
  109.  
  110. main()
  111. {
  112.     auto start=chrono::system_clock::now();
  113.     {
  114.         #ifndef ONLINE_JUDGE
  115.             freopen("input.txt","r",stdin);
  116.             freopen("output.txt","w",stdout);
  117.         #endif
  118.         FASTIO();
  119.         int t=1;
  120.         cin>>t;
  121.         solve(t);
  122.     }
  123.     auto end=chrono::system_clock::now();
  124.     chrono::duration<double> elapsed=end-start;
  125. //  cout<<" Time taken: "<<elapsed.count()<<" sec";
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement