Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
107557 魍蔚酯·传统美德 迷宫问题 C++ 运行出错 0 790 MS 376 KB 1993 2023-10-25 13:41:24

Tests(0/15):


#include<bits/stdc++.h> #define int long long using namespace std; const int maxn = 1919810; int n,m,val[maxn * 4],a[maxn],tag[maxn]; inline int fr(){ register int x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ putchar('-'); x = -x; } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } void build(int u,int l,int r){ if (l == r){ val[u] = a[l]; return ; } int mid = (l + r) / 2; build(u * 2,l,mid); build(u * 2 + 1,mid + 1,r); val[u] = val[u * 2] + val[u * 2 + 1]; } void pushdown(int u,int l,int r){ if (tag[u]){ int mid = (l + r) / 2; val[u * 2] += tag[u] * (mid - l + 1); tag[u * 2] += tag[u]; val[u * 2 + 1] += tag[u] * (r - mid); tag[u * 2 + 1] += tag[u]; tag[u] = 0; } } void update(int u,int l,int r,int s,int t,int x){ if (s <= l && r <= t){ val[u] += x * (r - l + 1); tag[u] += x; return ; } pushdown(u,l,r); int mid = (l + r) / 2; if (s <= mid){ update(u * 2,l,mid,s,t,x); } if (t > mid){ update(u * 2 + 1,mid + 1,r,s,t,x); } val[u] = val[u * 2] + val[u * 2 + 1]; } int query(int u,int l,int r,int s,int t){ if (s <= l && r <= t){ return val[u]; } pushdown(u,l,r); int mid = (l + r) / 2; if (t <= mid){ return query(u * 2,l,mid,s,t); } if (s > mid){ return query(u * 2 + 1,mid + 1,r,s,t); } return query(u * 2,l,mid,s,t) + query(u * 2 + 1,mid + 1,r,s,t); } signed main(){ int n,m; n = fr(),m = fr(); for (int i = 1;i <= n;i++){ a[i] = fr(); //update(1,1,n,i,a[i]); } build(1,1,n); for (int i = 1;i <= m;i++){ int o,p,q,r; o = fr(),p = fr(),q = fr(); if (o == 1){ r = fr(); update(1,1,n,p,q,r); } else{ fw(query(1,1,n,p,q)); puts(""); } } return 0; }


测评信息: