TAHMID37

UVA_12532

Jul 20th, 2021 (edited)
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.30 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define all(x) (x).begin(),(x).end()
  22. #define debug 0
  23. #define MAXN   100001
  24. #define ar array
  25. #define lb lower_bound
  26. #define ub upper_bound
  27. #define minpq priority_queue<ll, vector<ll>, greater<ll>>
  28. #define maxpq priority_queue<ll>
  29. const int mxN=2e5;
  30. const int MOD=1e9+7;
  31. template<typename ForwardIterator, typename T>
  32. ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
  33. {auto it = std::lower_bound (first, last, value);
  34. return (it == first ? last : --it);}
  35. bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)
  36. {
  37.     return (a.second < b.second);
  38. }
  39. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  40. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  41. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  42.  
  43.  
  44. ll arr[mxN];
  45.  
  46. ll tree[mxN*3];
  47.  
  48. void init(ll node,ll b,ll e)
  49. {
  50.     if(b==e)
  51.     {
  52.         tree[node]=arr[b];
  53.         return ;
  54.     }
  55.  
  56.     ll left=node*2;
  57.     ll right=node*2+1;
  58.  
  59.     ll mid=(b+e)/2;
  60.  
  61.     init(left,b,mid);
  62.     init(right,mid+1,e);
  63.  
  64.     tree[node]=tree[left]*tree[right];
  65.  
  66. }
  67.  
  68.  
  69. ll query(ll node,ll b,ll e,ll i,ll j)
  70. {
  71.     if(i>e||j<b)
  72.         return 1;
  73.     if(b>=i&&e<=j)
  74.          return tree[node];
  75.  
  76.     ll left=node*2;
  77.     ll right=node*2+1;
  78.     ll mid=(b+e)/2;
  79.  
  80.     ll p1=query(left,b,mid,i,j);
  81.     ll p2=query(right,mid+1,e,i,j);
  82.  
  83.     return p1*p2;
  84.  
  85. }
  86.  
  87.  
  88. void update(ll node,ll b,ll e,ll i,ll value)
  89. {
  90.     if(i>e||i<b)
  91.         return ;
  92.     if(b>=i&&e<=i)
  93.     {
  94.         tree[node]=value;
  95.         return ;
  96.     }
  97.  
  98.     ll left=node*2;
  99.     ll right=node*2+1;
  100.     ll mid=(b+e)>>1;
  101.  
  102.     update(left,b,mid,i,value);
  103.     update(right,mid+1,e,i,value);
  104.  
  105.     tree[node]=tree[left]*tree[right];
  106.  
  107. }
  108.  
  109.  
  110.  
  111. int main()
  112. {
  113.     ll t;
  114.     ll n,q,i,j,k;
  115.  
  116.     while(cin>>n)
  117.     {
  118.         cin>>q;
  119.  
  120.         for(i=1;i<=n;i++)
  121.         {
  122.             ll x;
  123.             cin>>x;
  124.             if(x>0)
  125.                 arr[i]=1;
  126.             else if(x<0)
  127.                 arr[i]=-1;
  128.             else
  129.                 arr[i]=0;
  130.         }
  131.  
  132.         init(1,1,n);
  133.  
  134.         string s;
  135.  
  136.         for(i=0;i<q;i++)
  137.         {
  138.             char c;
  139.             ll l,r;
  140.             cin>>c;
  141.             cin>>l>>r;
  142.  
  143.             if(c=='C'){
  144.  
  145.                 if(r>0)
  146.                  r=1;
  147.                 else if(r<0)
  148.                  r=-1;
  149.                 else
  150.                     r=0;
  151.  
  152.                 update(1,1,n,l,r);
  153.             }
  154.  
  155.             else if(c=='P')
  156.             {
  157.                 ll x=query(1,1,n,l,r);
  158.                 if(x==0)
  159.                     s+='0';
  160.                 else if(x>0)
  161.                     s+='+';
  162.                 else
  163.                     s+='-';
  164.             }
  165.         }
  166.  
  167.  
  168.         cout<<s<<'\n';
  169.  
  170.     }
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
Add Comment
Please, Sign In to add comment