• 欢迎光临~

# [洛谷P4231]三步必杀 题解

## 洛谷P4231 三步必杀

• 思路：

(forall i in [l,r],A_i gets A_i + s + (i-l) times d)

(B_l gets B_l + s)

(forall i in (l,r],B_i gets B_i + d)

(B_{r + 1} gets B_{r + 1} - t)

(B_l) 执行单点修改，则在 (C) 中：(C_l gets C_l+s) , (C_{l+1} gets C_{l+1} - s)

((l,r]) 执行区间修改，则：(C_{l+1} gets C_{l+1} + d) , (C_{r + 1} gets C_{r + 1} - d)

(B_{r+1}) 执行单点修改，则： (C_{r + 1} gets C_{r + 1} - t) , (C_{r + 2} gets C_{r+2} + t)

code:

``````#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
const int maxn = 1e7 + 5;
int s = 0;
char c = getchar();
for(;!isdigit(c);c = getchar());
for(;isdigit(c);c = getchar())s = (s << 1) + (s << 3) + (c ^ '0');
return s;
}
int n,m;
long long c[maxn];
int main() {
for(int i = 1;i <= m;++ i) {
int d = (e - s) / (r - l);
c[l] += (long long)s;
c[l + 1] -= (long long)s;
c[l + 1] += (long long)d;
c[r + 1] -= (long long)d;
c[r + 1] -= (long long)e;
c[r + 2] += (long long)e;
}
long long sum1 = 0,sum2 = 0,ans = 0,cnt = 0;
for(int i = 1;i <= n;++ i) {
sum1 += c[i];
sum2 += sum1;
cnt ^= sum2;
ans = max(ans , sum2);
}
printf("%lld %lld",cnt,ans);
return 0;
}
``````