```cpp
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define lson root<<1
#define rson (root<<1)|1
#define ll long long
using namespace std;
const int N = 1e5 + 5;
int n, m;
inline ll read() {
ll z = 0, x = 1; char c = getchar();
while (c > '9' || c < '0') {if (c == '-') x = -x; c = getchar();}
while (c >= '0' && c <= '9') z = z * 10 + c - '0', c = getchar();
return z * x;
}
struct tree {
int l,r;
ll ans1, ans2, ans3;
ll sum1, sum2;
ll lazytag;
}node[N<<2];
void build(ll l, ll r,int root) {
node[root].l=l,node[root].r=r;
node[root].ans1 = node[root].ans2 = node[root].ans3 = 0;
node[root].lazytag = 0;
if (l == r) {
node[root].sum1 = l, node[root].sum2 = l * l;
return;
}
int mid = (l + r) >> 1;
build(l, mid,lson), build(mid + 1, r,rson);
node[root].sum1 = node[lson].sum1 + node[rson].sum1;
node[root].sum2 = node[lson].sum2 + node[rson].sum2;
return;
}
void pushdown(int root) {
int mid = (node[root].l + node[root].r) >> 1;
ll val = node[root].lazytag;
node[lson].ans1 += (mid-node[root].l+1)*val;
node[lson].ans2 += node[lson].sum1 * val;
node[lson].ans3 += node[lson].sum2 * val;
node[rson].ans1 += (node[root].r - mid) * val;
node[rson].ans2 += node[rson].sum1 * val;
node[rson].ans3 += node[rson].sum2 * val;
node[rson].lazytag += val;
node[lson].lazytag += val;
node[root].lazytag = 0;
return;
}
void update(int root){
node[root].ans1=node[lson].ans1+node[rson].ans1;
node[root].ans2=node[lson].ans2+node[rson].ans2;
node[root].ans3=node[lson].ans3+node[rson].ans3;
return;
}
void add(int root,int ql,int qr,ll val) {
if (ql<=node[root].l&&node[root].r<=qr) {
node[root].lazytag += val;
node[root].ans1 += (node[root].r-node[root].l+1)*val;
node[root].ans2 += node[root].sum1 * val;
node[root].ans3 += node[root].sum2 * val;
return;
}
pushdown(root);
int mid = (node[root].l + node[root].r) >> 1;
if (ql <= mid) add(lson, ql, qr, val);
if (qr >= mid + 1) add(rson, ql, qr, val);
update(root);
return;
}
ll ans1 = 0, ans2 = 0, ans3 = 0;
void query(int root, int ql, int qr) {
if (ql <= node[root].l && node[root].r <= qr) {
ans1 += node[root].ans1;
ans2 += node[root].ans2;
ans3 += node[root].ans3;
return;
}
pushdown(root);
int mid = (node[root].l + node[root].r) >> 1;
if (ql <= mid) query(lson, ql, qr);
if (qr >= mid + 1) query(rson, ql, qr);
return;
}
ll gcd(ll a, ll b) {
return b > 0 ? gcd(b, a % b) : a;
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("b.out","w",stdout);
n = read(), m = read();
build(1, n, 1);
for (int i = 1; i <= m; i++) {
char op = 0;
scanf("%c",&op);
if (op == 'C') {
ll l = read(),r = read()-1, v = read();
add(1, l, r, v);
}
else if (op == 'Q') {
ll l = read(), r = read()-1;
ans1 = 0, ans2 = 0, ans3 = 0;
query(1, l, r);
ll ans_a = (r-l+1-r*l) * ans1 + (l + r) * ans2 - ans3,ans_b=((r-l+2)*(r-l+1))/2ll;
ll ans_c = gcd(ans_a, ans_b);
if(ans_c)
printf("%lld/%lld\n", ans_a / ans_c, ans_b / ans_c);
else
printf("0/1\n");
}
}
return 0;
}
```
by lzjsy @ 2022-09-19 11:38:27
```scanf("%c",&op);```
改成
```scanf(" %c",&op);```
就通过了
by Sakura_Lu @ 2023-02-26 08:08:19