#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)
using namespace std;
const int MOD = 1000000000;
int calc(int L, int i, int R) {
// return \sum_{j=L}^R abs(j-i)
// 0 + 1 + 2 + ... + i-L +
// 1 + 2 + ... + R-i
return (1LL * (i-L) * (i-L+1) / 2 + 1LL * (R-i) * (R-i+1) / 2) % MOD;
}
int jizz(int len) {
return 1LL*len*(len+1)*(len+2)/6%MOD;
}
int DistanceSum(int n, int x[], int y[]) {
vector<pair<int,int>> v;
vector<pair<int,int>> s;
for(int i = 0; i < n; i++) v.pb(x[i], y[i]);
sort(all(v));
int lastL = 0, lastR = INT_MAX;
int ans = 0, cnt = 0;
map<int,int> sum;
for(int i = 0, j; i < n; i = j) {
for(j = i+1; j < n; j++) if(v[i].first != v[j].first) break;
int l = v[i].second, r = v[j-1].second;
int L = max(lastL, l), R = min(lastR, r);
map<int,int> tmp;
for(int i = L; i <= R; i++) {
int s = (sum[i] + cnt) % MOD;
tmp[i] = s;
}
for(int i = L-1; i >= l; i--) {
int s = (tmp[i+1] + cnt) % MOD;
tmp[i] = s;
}
for(int i = R+1; i <= r; i++) {
int s = (tmp[i-1] + cnt) % MOD;
tmp[i] = s;
}
for(int i = l; i <= r; i++) ans = (ans + tmp[i]) % MOD;
ans = (ans + jizz(r-l)) % MOD;
for(int i = l; i <= r; i++) tmp[i] = (tmp[i] + calc(l, i, r)) % MOD;
sum = tmp;
cnt += r-l+1;
lastL = l, lastR = r;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
896 KB |
Output is correct |
2 |
Correct |
11 ms |
896 KB |
Output is correct |
3 |
Correct |
26 ms |
1408 KB |
Output is correct |
4 |
Correct |
23 ms |
1408 KB |
Output is correct |
5 |
Correct |
55 ms |
2428 KB |
Output is correct |
6 |
Correct |
47 ms |
2300 KB |
Output is correct |
7 |
Correct |
53 ms |
2292 KB |
Output is correct |
8 |
Correct |
54 ms |
2300 KB |
Output is correct |
9 |
Correct |
44 ms |
2292 KB |
Output is correct |
10 |
Correct |
41 ms |
2292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |