-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1183.cpp
More file actions
137 lines (121 loc) · 3.49 KB
/
Copy path1183.cpp
File metadata and controls
137 lines (121 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
#define ft first
#define sd second
#define mp make_pair
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 1e9
#define eps 1e-9
#define mod 1000000007
#define NN 100010
#define read(a) scanf("%lld", &a)
struct data {
ll sum;
ll xtra;
} tree[300010];
void init(ll node, ll low, ll high) {
if (low == high) {
tree[node].sum = 0;
tree[node].xtra = -1;
return;
}
ll left = node << 1;
ll right = left + 1;
ll mid = (low + high) >> 1;
init(left, low, mid);
init(right, mid + 1, high);
tree[node].sum = 0;
tree[node].xtra = -1;
return;
}
void update(ll node, ll low, ll high, ll rlow, ll rhigh, ll value) {
if (low >= rlow && high <= rhigh) {
tree[node].sum = (high - low + 1) * value;
tree[node].xtra = value;
return;
}
ll left = node << 1;
ll right = left + 1;
ll mid = (low + high) >> 1;
if (tree[node].xtra != -1) {
tree[left].xtra = tree[node].xtra;
tree[right].xtra = tree[node].xtra;
tree[left].sum = (mid - low + 1) * tree[left].xtra;
tree[right].sum = (high - mid) * tree[right].xtra;
tree[node].xtra = -1;
}
if (rhigh <= mid)
update(left, low, mid, rlow, rhigh, value);
else if (rlow > mid)
update(right, mid + 1, high, rlow, rhigh, value);
else {
update(left, low, mid, rlow, mid, value);
update(right, mid + 1, high, mid + 1, rhigh, value);
}
tree[node].sum = tree[left].sum + tree[right].sum;
}
ll query(ll node, ll low, ll high, ll rlow, ll rhigh, ll carry) {
if (carry != -1) {
return (rhigh - rlow + 1) * carry;
}
if (low >= rlow && high <= rhigh) {
return tree[node].sum;
}
ll left = node << 1;
ll right = left + 1;
ll mid = (low + high) >> 1;
ll p1 = 0, p2 = 0;
if ((high - low + 1) * tree[node].xtra == tree[node].sum) carry = tree[node].xtra;
if (rhigh <= mid)
p1 = query(left, low, mid, rlow, rhigh, carry);
else if (rlow > mid)
p2 = query(right, mid + 1, high, rlow, rhigh, carry);
else {
p1 = query(left, low, mid, rlow, mid, carry);
p2 = query(right, mid + 1, high, mid + 1, rhigh, carry);
}
return p1 + p2;
}
int main() {
ios_base::sync_with_stdio(false);
ll tc, t = 1;
cin >> tc;
while (tc--) {
ll n, q;
cin >> n >> q;
printf("Case %d:\n", t++);
init(1, 1, n);
while (q--) {
ll i, j, k, l;
cin >> i;
if (i == 1) {
cin >> j >> k >> l;
update(1, 1, n, j + 1, k + 1, l);
} else if (i == 2) {
cin >> j >> k;
ll ans = query(1, 1, n, j + 1, k + 1, -1);
ll res = (k - j + 1);
ll gcd = __gcd(res, ans);
if (res / gcd > 1)
printf("%lld/%lld\n", ans / gcd, res / gcd);
else
printf("%lld\n", ans / gcd);
}
}
}
return 0;
}