ABC462D 题解
Daily_Light · · 题解
也许更好的阅读体验。
赛时用树状数组水过去了,但是非常不喜欢数据结构。严肃学习结论化做法。
观察到对于时间
然后注意到作案时间是
如何求
::::info[另:赛时群里的批话] 如果出现人物不想出现的可以让我删除。
::::success[AC 代码]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int MOD = 998244353;
ll n, d, ans, c, f[N];
int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> d;
for (int i = 0, s, t; i < n; i++) {
cin >> s >> t;
ll r = t - d;
if (r >= s) {
f[s]++, f[r + 1]--;
}
}
for (int x = 1; x <= 1e6; x++) {
c += f[x];
ans += c * (c - 1) / 2;
}
cout << ans;
return 0;
}
::::
都看到这里了还不点赞,那还是人吗?