Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- const int N = 131075;
- ll Tree[2 * N];
- ll Lazy[2 * N];
- bool Lazyache[2 * N];
- void UpdateTree(int node, int L, int R, int TL, int TR, ll val){
- int Left = node * 2;
- int Right = Left + 1;
- int mid = (L+R)/2;
- if(Lazyache[node]){
- Tree[node] = Lazy[node] * (R-L+1);
- if(L < R){
- Lazy[Left] = Lazy[node];
- Lazy[Right] = Lazy[node];
- Lazyache[Left] = 1;
- Lazyache[Right] = 1;
- }
- Lazy[node] = 0;
- Lazyache[node] = 0;
- }
- if(TL > R || TR < L) return;
- if(TL <= L && TR >= R){
- Tree[node] = val * (R-L+1);
- if(L < R){
- Lazy[Left] = val;
- Lazy[Right] = val;
- Lazyache[Left] = 1;
- Lazyache[Right] = 1;
- }
- return;
- }
- UpdateTree(Left, L, mid, TL, TR, val);
- UpdateTree(Right, mid + 1, R, TL, TR, val);
- Tree[node] = Tree[Left] + Tree[Right];
- }
- ll Query(int node, int L, int R, int TL, int TR){
- int Left = node * 2;
- int Right = Left + 1;
- int mid = (L+R)/2;
- if(Lazyache[node]){
- Tree[node] = Lazy[node] * (R-L+1);
- if(L < R){
- Lazy[Left] = Lazy[node];
- Lazy[Right] = Lazy[node];
- Lazyache[Left] = 1;
- Lazyache[Right] = 1;
- }
- Lazy[node] = 0;
- Lazyache[node] = 0;
- }
- if(TL > R || TR < L) return 0;
- if(TL <= L && TR >= R) return Tree[node];
- return Query(Left, L, mid, TL, TR) + Query(Right, mid + 1, R, TL, TR);
- }
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- printf("Case %d:\n", ++cs);
- int n, q;
- scanf("%d %d", &n, &q);
- memset(Tree, 0, sizeof(Tree));
- memset(Lazy, 0, sizeof(Lazy));
- memset(Lazyache, 0, sizeof(Lazyache));
- while(q--){
- int type, L, R; scanf("%d %d %d", &type, &L, &R);
- L++, R++;
- if(type == 1){
- ll val; scanf("%lld", &val);
- UpdateTree(1, 1, n, L, R, val);
- }
- else{
- ll sum = Query(1, 1, n, L, R);
- ll div = R - L + 1;
- ll gc = __gcd(sum, div);
- sum/=gc;
- div/=gc;
- printf("%lld", sum);
- if(div > 1) printf("/%lld", div);
- printf("\n");
- }
- }
- }
- #ifdef ERFANUL007
- fprintf(stderr, "\n>>> Runtime : %.9f\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement