SuitNdtie

TOI10: Treasure Chest

Apr 30th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<vector>
  4. using namespace std;
  5. typedef long long int ll;
  6. struct mp{
  7.     ll c2,c3,c5,c7;
  8. };
  9. mp Mplus(mp a,mp b){
  10.     mp c;
  11.     c.c2 = a.c2 + b.c2;
  12.     c.c3 = a.c3 + b.c3;
  13.     c.c5 = a.c5 + b.c5;
  14.     c.c7 = a.c7 + b.c7;
  15.     return c;
  16. }
  17. mp Mminus(mp a,mp b){
  18.     mp c;
  19.     c.c2 = a.c2 - b.c2;
  20.     c.c3 = a.c3 - b.c3;
  21.     c.c5 = a.c5 - b.c5;
  22.     c.c7 = a.c7 - b.c7;
  23.     return c;
  24. }
  25. mp ItM(ll x){
  26.     mp ans = {0,0,0,0};
  27.     ll arr[4] = {2,3,5,7};
  28.     for(int i = 0 ; i < 4 ; i ++){
  29.         while(x % arr[i] == 0){
  30.             switch(arr[i]){
  31.                 case(2):{
  32.                     ans.c2++;
  33.                     break;
  34.                 }
  35.                 case(3):{
  36.                     ans.c3++;
  37.                     break;
  38.                 }
  39.                 case(5):{
  40.                     ans.c5++;
  41.                     break;
  42.                 }
  43.                 case(7):{
  44.                     ans.c7++;
  45.                     break;
  46.                 }
  47.             }
  48.             x/=arr[i];
  49.         }  
  50.     }
  51.     return ans;
  52. }
  53. struct elem{
  54.     mp p;
  55.     ll pos;
  56.     int state;
  57. };
  58. bool mycmp(elem a,elem b){
  59.     return a.pos < b.pos;
  60. }
  61. ll ctD(mp x){
  62.     return (x.c2+1)*(x.c3+1)*(x.c5+1)*(x.c7+1);
  63. }
  64. int main(){
  65.     ll m,n;
  66.     scanf("%lld %lld",&m,&n);
  67.     vector<elem> vec;
  68.     for(int i = 0 ; i < m ; i ++){
  69.         ll x,s,t;
  70.         scanf("%lld %lld %lld",&x,&s,&t);
  71.         vec.push_back({ItM(x),s,1});
  72.         vec.push_back({ItM(x),t+1,-1});
  73.     }
  74.     sort(vec.begin(),vec.end(),mycmp);
  75.     ll prevpos = 0; // (L,R]
  76.    
  77.     ll maxD = 0;
  78.     ll ans = 0;
  79.     mp now = {0,0,0,0};
  80.     for(int i = 0 ; i < vec.size() ; i++){
  81.         ll pos = vec[i].pos;
  82.     //  printf("Test %lld\n",pos);
  83.         mp p = vec[i].p;
  84.         int state = vec[i].state;
  85.         if(pos != prevpos){
  86.             ll cD = ctD(now);
  87.         //  printf("Test (%lld-%lld) %lld \n",prevpos,pos,cD);
  88.             if(cD > maxD){
  89.                 ans = pos - prevpos;
  90.                 maxD = cD;
  91.             }
  92.             else if(cD == maxD){
  93.                 ans += pos - prevpos;
  94.             }
  95.         }
  96.         if(state == 1){
  97.             now = Mplus(now,p);
  98.         }else{
  99.             now = Mminus(now,p);
  100.         }
  101.         prevpos = pos;
  102.     }
  103.     printf("%lld %lld",maxD,ans);
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment