#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 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 = 1e9;
int ans = 0, cnt = 0;
map<int,int> sum;
for(int i = 0, j; i < n; i = j) {
for(j = i; 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++) tmp[i] = (tmp[i] + calc(l, i, r)) % MOD;
for(int i = l; i <= r; i++) ans = (ans + tmp[i]) % MOD;
sum = tmp;
cnt += r-l+1;
lastL = l, lastR = r;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |