Advertisement
Farjana_akter

Untitled

Aug 10th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6.  
  7. int main()
  8. {
  9. ll n,q,i,j,k;
  10. map<string,vector<ll> >mp;
  11. cin>>n>>q;
  12. k=0;
  13. string s;
  14. ll cd,d,base,l,u,C;
  15. vector<ll>c;
  16. while(n--)
  17. {
  18. cin.ignore();
  19. cin>>s;
  20. cin>>base>>cd>>d;
  21. c.clear();
  22. ll arr[d+5];
  23. // cout<<"base "<<base<<" cd "<<cd<<endl;
  24. ll low[d+5],up[d+5],total;
  25. memset(low,0,sizeof(low));
  26. memset(up,0,sizeof(up));
  27. memset(arr,0,sizeof(arr));
  28. for(i=1; i<=d; i++)
  29. {
  30. cin>>low[i]>>up[i];
  31. // cout<<low[i]<<up[i]<<endl;
  32. }
  33. arr[d]=cd;
  34. //cout<<"arr[d] "<<arr[d]<<endl;
  35. for(i=d-1; i>0; i--)
  36. {
  37. //cout<<i<<endl;
  38. l=low[i+1];
  39. u=up[i+1];
  40. C=arr[i+1];
  41. total=C*(u-l+1);
  42. arr[i]=total;
  43. // cout<<"arr[i] "<<arr[i]<<endl;
  44. }
  45.  
  46. arr[0]=base;
  47. // cout<<"arr[0] "<<arr[0]<<endl;
  48. for(i=1; i<=d; i++)
  49. arr[0]-=(low[i]*arr[i]);
  50. for(i=0;i<=d;i++)
  51. c.push_back(arr[i]);
  52. mp[s]=c;
  53. s.clear();
  54. }
  55. while(q--)
  56. {
  57. string s;
  58. cin>>s;
  59. cout<<s<<"[";
  60. ll address=mp.find(s)->second[0],ind;
  61. ll sz=mp.find(s)->second.size();
  62. for(i=1; i<sz; i++)
  63. {
  64. cin>>ind;
  65. address+=((mp.find(s)->second[i])*ind);
  66. if(i!=1)
  67. {
  68. cout<<", ";
  69. }
  70. cout<<ind;
  71. }
  72. cout<<"] = "<<address<<endl;
  73. }
  74. return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement