Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- typedef long long ll;
- using namespace std;
- using namespace __gnu_pbds;
- template <typename T>
- using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
- #define all(x) x.begin(), x.end()
- #define f(i,a,b) for(int i = (a); i <= (b); i++)
- #define fd(i,a,b) for(int i = (a); i >= (b); i--)
- #define mp make_pair
- #define faster_io() ios_base::sync_with_stdio(false)
- #define pb push_back
- #define pii pair<int,int>
- #define SZ(x) ((int)x.size())
- #define vii vector<pair<int,int>>
- const int INF = 1000000005;
- const ll INFLL = 1000000000000000002ll;
- const ll MOD = 1000000007;
- inline ll min(ll a, ll b, ll c){return min(min(a,b),c);}
- inline ll min(ll a, ll b, ll c, ll d){return min(min(min(a,b),c),d);}
- inline ll max(ll a, ll b, ll c){return max(max(a,b),c);}
- inline ll max(ll a, ll b, ll c, ll d){return max(max(max(a,b),c),d);}
- // ----------------------------------------------------------------------------------------------------------
- const int RIGHT = 131072;
- const int SIZE = 265000;
- int L[SIZE], N, Q, Tests;
- ll T[SIZE];
- ll query(int l, int r, int n, int a, int b)
- {
- if(a > r || b < l) return 0;
- if(a >= l && b <= r) return T[n];
- if(L[n])
- {
- T[2*n] += (ll) L[n] * ((b-a+1)/2);
- T[2*n+1] += (ll) L[n] * ((b-a+1)/2);
- L[2*n] += L[n];
- L[2*n+1] += L[n];
- L[n] = 0;
- }
- int mid = (a+b) / 2;
- return query(l,r,2*n,a,mid) + query(l,r,2*n+1,mid+1,b);
- }
- void update(int l, int r, int n, int a, int b)
- {
- if(a > r || b < l) return;
- if(a >= l && b <= r)
- {
- T[n] += b-a+1;
- L[n]++;
- return;
- }
- if(L[n])
- {
- T[2*n] += (ll) L[n] * ((b-a+1)/2);
- T[2*n+1] += (ll) L[n] * ((b-a+1)/2);
- L[2*n] += L[n];
- L[2*n+1] += L[n];
- L[n] = 0;
- }
- int mid = (a+b) / 2;
- update(l,r,2*n,a,mid), update(l,r,2*n+1,mid+1,b);
- T[n] = T[2*n] + T[2*n+1];
- }
- int main()
- {
- cin >> Tests;
- f(tt,1,Tests)
- {
- f(i,0,SIZE-1) T[i] = L[i] = 0;
- printf("Scenario #%d:\n", tt);
- scanf("%d %d", &N, &Q);
- while(Q--)
- {
- char s[15];
- int l,r;
- scanf("%s %d %d", s, &l, &r);
- if(s[0] == 'a') printf("%lld\n", query(l,r,1,1,RIGHT));
- else update(l,r,1,1,RIGHT), printf("OK\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement