题解:luogu U37449 Lycanthropy
差分套差分qwq
pushinl说这题思维比较好
其实算是比较简单了
一开始写了假的差分
还是没摆脱单个处理
其实是对每个区间边界进行差分处理,每个区间内部再进行标记差分
正解很好理解
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int pls=40001; 7 int a[20000050]; 8 long long bl, tot; 9 void change(int l, int r, int val){ 10 a[l+pls]+=val; 11 a[r+1+pls]-=val; 12 } 13 int main(){ 14 int n,m; 15 scanf("%d%d", &n, &m); 16 for (int i=1; i<=n; ++i){ 17 int v, x; 18 scanf("%d%d", &v, &x); 19 change(x-v+1, x, -1); 20 change(x+1, x+v, 1); 21 change(x-3*v+1, x-2*v, 1); 22 change(x-2*v+1, x-v, -1); 23 change(x+v+1, x+2*v, 1); 24 change(x+2*v+1, x+3*v, -1); 25 } 26 for (int i=1; i<=m+pls; ++i){ 27 bl+=a[i]; 28 tot+=bl; 29 if(i>pls) printf("%lld ", tot); 30 } 31 printf("\n"); 32 return 0; 33 }
"Hello World!"