版本比较
题解:LuckyIII Beginner Contest 2 - She has come
正文
增加 23 行删除 2 行
222 行未改动全部展开22322422522622722822923037 行未改动26826927027127227327427527656 行未改动33333433533633733833934034190 行未改动222 行未改动全部展开。区间和 $\sum_{i=a}^{b} i$ 的奇偶性等于区间内奇数个数的奇偶性,即$$\text{奇数个数} = \left\lfloor\frac{b+1}{2}\right\rfloor - \left\lfloor\frac{a}{2}\right\rfloor$$,答案即为该值 $\bmod 2$。### Code from 出题人```cpp//std#include<bits/stdc++.h>37 行未改动return 0;}```### Code from 题解作者```cpp#include <bits/stdc++.h>using namespace std;56 行未改动假设 $dist_{i,j}$ 是 $i$ 到 $j$ 的最短路。对于询问 $(x,y)$,变换为 $(y,x)$,我们需要:用二分找到第一个 $\geqslant y$ 的关键点 $ps$ 和最后一个 $\leqslant x$ 的关键点 $pe$,如果有哪个找不到或者 $ps>pe$ 则说明这两个点之间根本没有关键点,答案就是 $x-y$;否则答案就是 $(a_ps-y)+dist_{ps,pe}+(x-a_pe)$。```cpp#include<bits/stdc++.h>using namespace std;90 行未改动222 行未改动全部展开22322422522622722822923023123223323423523623723823924024124224324424524624724824925025125237 行未改动29029129229329429529629756 行未改动35435535635735835936036136290 行未改动222 行未改动全部展开。区间和 $\sum_{i=a}^{b} i$ 的奇偶性等于区间内奇数个数的奇偶性,即$$\text{奇数个数} = \left\lfloor\frac{b+1}{2}\right\rfloor - \left\lfloor\frac{a}{2}\right\rfloor$$,答案即为该值 $\bmod 2$。::::success[因为数据过水导致的非正解 AC 代码]```cpp#include<iostream>using namespace std;int main(){int t;cin>>t;while(t--){long long x,y,z,usto1,usto2;cin>>x>>y>>z;x=x%z;y=y%z;usto1=(y)*(y+1)/2;usto1=(usto1%z)*(usto1%z)%z;usto2=(x)*(x-1)/2;usto2=(usto2%z)*(usto2%z)%z;cout<<(usto1-usto2+z)%z<<endl;;}exit(0);}```::::### Code from 出题人```cpp//std#include<bits/stdc++.h>37 行未改动return 0;}```### Code from 题解作者```cpp#include <bits/stdc++.h>using namespace std;56 行未改动假设 $dist_{i,j}$ 是 $i$ 到 $j$ 的最短路。对于询问 $(x,y)$,变换为 $(y,x)$,我们需要:用二分找到第一个 $\geqslant y$ 的关键点 $ps$ 和最后一个 $\leqslant x$ 的关键点 $pe$,如果有哪个找不到或者 $ps>pe$ 则说明这两个点之间根本没有关键点,答案就是 $x-y$;否则答案就是 $(a_{ps}-y)+dist_{ps,pe}+(x-a_{pe})$。```cpp#include<bits/stdc++.h>using namespace std;90 行未改动